shell编程:利用脚本实现nginx的守护自动重启
nginx_daemon.sh
#!/bin/bash # this_pid=$$ while true do ps -ef | grep nginx | grep -v grep | grep -v $this_pid &> /dev/null if [ $? -eq 0 ];then echo "nginx is ok" sleep 3 else systemctl start nginx echo "nginx is down,starting it..." fi done
执行脚本
后台执行脚本并输出日志到/tmp/nginx_daemon.out sh nginx_daemon.sh > /tmp/nginx_daemon.out 2>&1 & (sh nginx_daemon.sh & 不指定文件的话为当前目录的nohup.out 文件中) 查看日志 tail -f /tmp/nginx_daemon.out
查看任务
查看任务。
jobs
关闭任务
fg %n
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步