# vi /usr/local/nginx/sbin/nginx_restart.sh 貼入一下代碼:
#!/bin/bash
#www.xmsolink.com
#Monitor nginx service
#check root user
if [ $(id -u) != "0" ]
then
echo "Not the root user! Try using sudo command!"
exit 1
fi
netstat -anop | grep 0.0.0.0:80
if [ $? -ne 1 ]
then
exit
fi
echo $(date +%T%n%F)" Restart nginx Services " >> nginx.log
#/usr/local/nginx/sbin/nginx -s quit
/usr/local/nginx/sbin/nginx
其實主要內容就是
檢查是否是root用戶
檢查監聽服務程序的端口是否還正常
對運行不正常的進程進行重啟
:wq! 保存退出,chmod +w nginx_restart.sh 授權為可自行腳本
加入Linux crontab自動任務里即可:
1
*/5 * * * * sh /usr/local/nginx/sbin/nginx_restart.sh
# /etc/init.d/crond reload 刷新生效
————————————————
版權聲明:本文為CSDN博主「hongping626」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/hongping626/article/details/84428589