判断Nginx服务是否启动,如未启动,则自动重启

使用宝塔面板,最近发现Nginx 、MySQL服务重启后无法自动启动,添加开机启动命令无效,查看网贴找到《自动重启 shell脚本》,写在这里记录一下吧

nginx_procnum=`ps -ef|grep "nginx"|grep -v grep|wc -l`
if [ $nginx_procnum -eq 0 ]
then
	echo "start nginx..."
	/etc/init.d/nginx start
else 
	echo "no cmd"	
fi
// 然后添加定时任务;每分钟执行一次
然后添加定时任务;每分钟执行一次

图片[1]-判断Nginx服务是否启动,如未启动,则自动重启-追梦人
将全部的 redis,nginx,php,mysqld 判断并重启;

phpfpm_procnum=`ps -ef|grep "php-fpm"|grep -v grep|wc -l`
nginx_procnum=`ps -ef|grep "nginx"|grep -v grep|wc -l`
mysql_procnum=`ps -ef|grep "mysqld"|grep -v grep|wc -l`
redis_procnum=`ps -ef|grep "redis"|grep -v grep|wc -l`

if [ $phpfpm_procnum -eq 0 ]
then
echo "start php-fpm..."
    /etc/init.d/php-fpm-71 start
elif [ $nginx_procnum -eq 0 ]
then 
echo "start nginx..."
/etc/init.d/nginx start
elif [ $mysql_procnum -eq 0 ]
then 
    echo "start mysql..."
    /etc/init.d/mysql start
elif [ $redis_procnum -eq 0 ]
then 
    echo "start redis..."
    /etc/init.d/redis start
else 
echo "no cmd"

fi

原始文章链接

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享