首页 > 其他 > 详细

nginx启动脚本编写

时间:2017-07-16 17:17:23      阅读:264      评论:0      收藏:0      [点我收藏+]

思路:

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!