1、进入nginx目录cd /usr/local/nginx
2、创建shell文件夹 mkdir shell
3、cd shell后创建restartNginx.sh脚本 vim restartNginx.sh后wq!保存
内容如下
!/bin/sh
while true
do
#no-headers 不打印开头 计算有多少行
A=`ps -C nginx --no-header | wc -l`
if [ $A -eq 0 ];then
echo $(date +%F%n%T) "nginx未启动,启动nginx..."
systemctl start nginx
sleep 20
else
echo $(date +%F%n%T) "nginx正在运行..."
fi
sleep 10
done
4、chmod 777 restartNginx.sh
5、启动脚本 nohup ./restartNginx.sh &
测试结果