linux检测服务宕机自动重启
一:创建启动脚本 course-reload.sh
二:脚本内容,10检测一次
while : do run=$(ps -ef | grep course-service.jar | grep -v grep) if [ "$run" ] ; then echo "运行中!" else echo "已停止,正在重启!" sudo systemctl start course & echo "重启成功!" fi sleep 10 done
三:授权
# 1.授权 chmod 777 course-reload.sh # 2.处理脚本无法运行异常:报错syntax error near unexpected token `$'\r''解决方法 sed -i 's/\r//g' course-reload.sh
四:启动并打印日志
nohup ./course-reload.sh > courseLog.txt &