nginx 启动脚本

#!/bin/bash
#chkconfig: 2345 30 88

nginxd=/usr/local/nginx/sbin/nginx

. /etc/init.d/functions
res=`netstat -lntup | grep nginx|wc -l`

start(){
        if [ $res -eq 0 ];then
                $nginxd -c /usr/local/nginx/conf/nginx.conf
                echo "nginx is starting"
                if [ $? -eq 0 ];then
                        action "nginx is started." /bin/true
                else
                        action "nginx is started." /bin/false
                fi
        else
                echo "nginx is running."
        fi
}

stop(){
        if [ $res -ge 1 ];then
                $nginxd -s stop
                echo "nginx is stopping"
                if [ $? -eq 0 ];then
                        action "nginx is stopped." /bin/true
                else
                        action "nginx is stopped." /bin/false
                fi
        else
                echo "nginx is not running."
        fi
}

restart(){
        if [ $res -ge 1 ];then
                killall -9 nginx
                action "nginx is stopped" /bin/true
                $nginxd -c /usr/local/nginx/conf/nginx.conf
                echo "nginx is starting."
                if [ $? -eq 0 ];then
                        action "nginx is started." /bin/true
                else
                        action "nginx is started." /bin/false
                fi
        else
                echo "ningx is not running."
        fi

}

case $1 in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                restart
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart}"
                exit 1
esac
exit

将nginxd 加入启动项: chkconfig --add nginxd

 

posted @ 2017-03-21 17:06  Vincen_shen  阅读(215)  评论(0编辑  收藏  举报