nginx启动脚本撰写

#!/bin/sh
#chkconfig: 2345 85 15
# description: nginx is a World Wide Web server. It is used to serve
function start(){
        netstat -tunlp | grep nginx > /dev/null
        if [ $? -eq 0 ]; then
                echo "nginx is already starting"
        else
                /usr/local/nginx/sbin/nginx
        fi
}

function stop(){
        netstat -tunlp | grep nginx > /dev/null
        if [ $? -eq 0 ]; then
                /usr/local/nginx/sbin/nginx -s stop
        else
                echo "nginx is already stopping"
        fi
}

function reload(){
        netstat -tunlp | grep nginx > /dev/null
        if [ $? -eq 0 ]; then
                /usr/local/nginx/sbin/nginx -s reload
        else
                echo "nginx is not running"
        fi
}

case $1 in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        reload)
                reload
                ;;
        *)
                echo "Usg:$0 start|stop|restart"
esac

chkconfig --list 列出所以服务启动情况
chkconfig --add nginx 将nginx加入开机启动项
service nginx start

说明:# chkconfig: - 85 15
开启模式:- 代表所有运行模式不开启,可以修改开启模式为2345
开启顺序:值越小,优先权越高,如果A服务需要依赖B服务启动,那A的开启顺序值比B服务小,代表A服务先启动
关闭顺序:值越小,优先权越高,与开启顺序相反,先将B服务关闭再将A服务关闭

posted @ 2022-06-01 15:11  Me-lihu  阅读(119)  评论(0编辑  收藏  举报