Shell守护进程监控nginx服务是否运行
#!/bin/bash
#$$表示当前shell的pid号,需要过滤掉(防止当前shell脚本名字包含nginx的字符)
ps -ef|grep nginx|grep -vE "grep|$$" >/dev/null
#直接通过$?获取上一句shell执行的状态
if [ $? -eq 0 ];then
echo "Nginx is running"
else
systemctl start nginx
echo "Nginx is down,Starting..."
fi