由于服务器出现down机之后,机器重新启动,nginx 35级别不能正常的启动起来,进程没有nginx进程,但是有进程文件存在,每次需要人工去关闭再启动服务,很是麻烦,于是就写了这个脚本方便系统的管理,给自己也减少工作量。
脚本如下:
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
master_pid=`ps -ef | grep "nginx: master process"` //查看nginx主进程
fcgi_pid_file=/usr/local/nginx/logs/fcgi.pid //进程文件的路径
nginx_pid_file=/usr/local/nginx/logs/nginx.pid //进程文件的路径
if [ -f $fcgi_pid_file -a $nginx_pid_file ]
then
rm -rf $fcgi_pid_file
rm -rf $nginx_pid_file
echo ok
else
echo fail
fi
/etc/init.d/nginx stop
/etc/init.d/nginx start
if [ -n "$master_pid" ]
then
exit
else
echo "nginx_reboot_fail" | /bin/mail -s "nginx_reboot_fail" 13798598403@139.com -- -f root@abc.cn
fi
脚本如下:
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
master_pid=`ps -ef | grep "nginx: master process"` //查看nginx主进程
fcgi_pid_file=/usr/local/nginx/logs/fcgi.pid //进程文件的路径
nginx_pid_file=/usr/local/nginx/logs/nginx.pid //进程文件的路径
if [ -f $fcgi_pid_file -a $nginx_pid_file ]
then
rm -rf $fcgi_pid_file
rm -rf $nginx_pid_file
echo ok
else
echo fail
fi
/etc/init.d/nginx stop
/etc/init.d/nginx start
if [ -n "$master_pid" ]
then
exit
else
echo "nginx_reboot_fail" | /bin/mail -s "nginx_reboot_fail" 13798598403@139.com -- -f root@abc.cn
fi
转载于:https://blog.51cto.com/wiliiwin/199228