linux 检测Java jar程序挂掉自动重启,轮询centos7.6 实测有效!!

#/bin/bash
while :
do
                    #jar包名
run=$(ps -ef |grep "hstech-hikladderctl.jar" |grep -v "grep")
if [ "$run" ] ; then
echo "The service is alive!"
else
echo "The service was shutdown!"
echo "Starting service ..."
#启动脚本 以及启动命令 如果没有脚本可以 nohup java -jar jar名
/./opt/hstech/soft/hikladderctl/hikladderctl.sh start
echo "The service was started!"
fi
#每十秒轮询一次
sleep 10
done                                                                                                                                                                                                                                                                                  
chmod a+x autostart.sh  让脚本可以在当前目录下 使用./autostart.sh 执行

使用 nohup ./autostart.sh& 挂起当前脚本

或者nohup sh autostart.sh&

可以使用ps -ef|grep autostart 找到当前脚本进程号

猜你喜欢

转载自blog.csdn.net/jieyongquan/article/details/129673593