标签:nginx自动脚本
思路:
1、判断nginx进程是否存在ps -ef|grep nginx |egrep -v "grep|nginxd.sh"
2、case 启动|关闭|重启|重新加载
缺陷:nginx分两个不同的进程,分别是master管理进程和运行进程,如果某个进程出现问题的话这个脚本就无效,需要对pid进行流程控制。此脚本没有涉及kill nginx的ID
[root@TEST-1 ~]# cat nginxd.sh
#!/bin/bash
##
#nginx服务启动脚本
. /etc/init.d/functions
nginx_dir=/mnt/tengine/tengine-2.1.2/sbin/
[ $# -ne 1 ] && {
echo "USAGE:$0 start|stop|restart|reload"
exit 9
}
testnginx(){
ps -ef|grep nginx |egrep -v "grep|nginxd.sh" &>/dev/null
result=$?
if [ $result -eq 0 ];then
return 1
else
return 0
fi
}
casefun(){
sum1=$1
case "$sum1" in
"start")
testnginx
[ $? -eq 1 ] && {
action "startnginx" /bin/false
exit 4
}
testnginx
[ $? -eq 0 ] && {
$nginx_dir/nginx
testnginx
[ $? -eq 1 ] && {
action "startnginx" /bin/true
}
}
;;
"stop")
testnginx
[ $? -eq 0 ] && {
acton "stopnginx" /bin/false
exit 6
}
testnginx
[ $? -eq 1 ] && {
$nginx_dir/nginx -s stop
testnginx
[ $? -eq 0 ] && {
action "stopnginx" /bin/true
}
}
;;
"restart")
testnginx
[ $? -eq 0 ] && {
action "stopnginx" /bin/false
}
testnginx
[ $? -eq 1 ] && {
$nginx_dir/nginx -s stop
testnginx
[ $? -eq 0 ] && {
action "restartnginx" /bin/true
}
}
$nginx_dir/nginx
testnginx
[ $? -eq 1 ] && {
action "startnginx" /bin/true
} || {
action "startnginx" /bin/false
}
;;
"reload")
testnginx
[ $? -eq 0 ] && {
action "reloadnginx" /bin/false
exit 7
}
[ $? -eq 1 ] && {
$nginx_dir/nginx -s reload
}
;;
*)
echo "USAGE:$0 start|stop|restart|reload"
exit 6
esac
}
casefun $*
本文出自 “常想一二” 博客,请务必保留此出处http://250919938.blog.51cto.com/962010/1947993
标签:nginx自动脚本
原文地址:http://250919938.blog.51cto.com/962010/1947993