Following script:
#Tomcat status
tc_status () {
ps aux | grep myapp123 | wc -l
}
#shutdown, if tomcat
if [ $(tc_status) -gt 0 ]; then
echo "Stopping Tomcat "; /home/user/shutdown.sh myapp123 > /dev/null 2>&1;
if [ $(tc_status) -eq 0 ]; then
echo "OK!"
fi
fi
#some other code
#startup
echo "Starting Tomcat...";
/home/user/startup.sh myapp123 > /dev/null 2>&1;
if [ $(tc_status) -gt 0 ]; then
echo "OK!";
fi
The above code first checks whether Tomcat is still running. If so, then it will be stopped, if not, further lines of code will be executed.
Finally the Tomcat is started. If it is running, there is an "OK" message.
The problem at this point is that the status is not 100% meaningful, especially when starting. Because the Tomcat process is running, but Tomcat usually takes several seconds or minutes until it is actually up.
How can I make sure that the Tomcat is actually DOWN and UP?