CentOS startup script

My guess here would be that Tomcat hasn’t fully stopped yet by the time you’re trying to start it again. You should check that the PID of Apache, Tomcat, MySQL, etc. have actually been removed before moving on to the next step.

Something like;

while ps -p $pid > /dev/null; do sleep 1; done;

where $pid is the PID of the process being stopped. You can get the PID for each process using code similar to the following:

ps -ef | awk '$8=="name_of_process" {print $2}'

where name_of_process is the process you’re wanting to get the PID for.

More details:

EDIT: Also, if your intent is to just restart the services then systemctl restart <service name> would do the stop/start for you.

HTH

– Denny

1 Like