以tomcat服务为例:
1.编写脚本文件tom.sh
#!/bin/sh
while true
do
ps -ef | grep "tomcat" | grep -v "grep"
if [ $? -eq 0 ]
then
echo "$?"
echo "tomcat process already started!"
else
echo "$?"
/usr/local/tomcat/apache-tomcat-7.0.82/bin/startup.sh #启动应用,修改成自己的启动应用脚本或命令
echo "tomcat process has been restarted!"
fi
sleep 30
done
2.授权文件可执行
chomd 777 tom.sh
3.nohub命令启动,让后台一直运行
nohup ./tom.sh >>/dev/null 2>&1 &