守护脚本 - daemon.sh
#/bin/bash
until false
do
ps aux | grep java | grep -v grep 2>&1 > /dev/null
if [ $? -eq 0 ]; then
echo upload is running.
else
echo upload is dead.
/root/apache-tomcat-6.0.24/bin/shutdown.sh
sleep 5
/root/apache-tomcat-6.0.24/bin/startup.sh
sleep 5
fi
sleep 2 //间隔2秒检查一次
done
守护进程配置
1、将 daemon.sh 脚本放到一个位置,例如:/root/daemon.sh
2、将脚本加入到开机自起中,在/etc/rc.local里添加一行,写脚本的路径-/root/daemon.sh
备注:
1、断电重启
2、断网重启
3、java 进程挂了重启