在实际的工作场景中,很多进程莫名巧妙退出,或者被人为kill掉。特意写下这个能保证应用保持启动的shell脚本。
#!/bin/bash
count=`ps aux | grep sersync2| grep -v grep |wc -l`
##the server will execute the code inside do.....done all the time if there is no signal false or exit
while true
do
##if sersync has started,then exit this shell.
if [ $count -eq 1 ];then
echo "sersync2 process exists"
exit 0
else ## if sersync2 has not started, then start sersync2
cd /usr/local/sersync/ && nohup ./sersync2 &
exit 0
fi
done