nginx啓動腳本

#!/bin/bash
#chkconfig - 80 90
pid="/usr/local/nginx/logs/nginx.pid"
mynaginx="/usr/local/nginx/sbin/nginx"

cecho(){
    echo -e "\033[$1m$2\033[0m"
}
a=33;b=31
start(){
    if [ -f $pid ];then
        cecho $a "nginx正在運行..."
    else    
        /usr/local/nginx/sbin/nginx
        sleep 5
        if [ -f $pid ];then
            cecho $a "nginx啓動成功..."
        else
            cecho $b  "nginx啓動失敗..."
        fi        

    fi
}
stop(){
    if [ ! -f $pid ];then
        cecho $b  "nginx處於停運狀態..."
    else
        kill `cat /usr/local/nginx/logs/nginx.pid`
        sleep 5
                if [ -f $pid ];then
                        cecho $b "nginx關閉失敗..."
                else
                        cecho $a  "nginx關閉成功..."
        fi
    fi

}
status(){
        if [ -f $pid ];then
                        cecho $a "nginx正在運行中..."
                else
                        cecho $b  "nginx處於關閉狀態..."
        fi
}
case $1 in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    sleep 2
    start
    ;;
status)
    status
    ;;
*)
    echo "Usage: nginx {start|stop|restart|status}"
esac
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章