您好,登錄后才能下訂單哦!
Nginx服務啟動停止重新加載腳本
已知Nginx管理命令為:
啟動:/application/nginx/sbin/nginx
停止:/application/nginx/sbin/nginx -s stop
重新加載:/application/nginx/sbin/nginx -s reload
請用case腳本模擬Nginx啟動關閉
/etc/init.d/nginx{start|stop|restart|reload}
并實現可通過chkonfig管理
腳本:
#
#nginx 啟動腳本
#2018-11-29
#
#!/bin/bash
#調用系統函數及自定義變量
[ -f /etc/init.d/functions ]&& . /etc/init.d/functions
Pidfile=/application/nginx/logs/nginx.pid
#共用函數
publics(){
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "Nginx is $1" /bin/true
else
actio "Nginx is $1" /bin/false
fi
}
#啟動函數start
start(){
if [ -f $Pidfile ];then
echo "Nginx is running"
else
/application/nginx/sbin/nginx
publics Started
fi
return $RETVAL
}
#關閉函數stop
stop(){
if [ ! -f $Pidfile ];then
echo "Nginx is not runing"
else
/application/nginx/sbin/nginx -s stop
publics Stopped
fi
return $RETVAL
}
#重新加載函數reload
reload(){
if [ ! -f $Pidfile ];then
echo "Can't open $Pidfile ,no such file directory"
else
/application/nginx/sbin/nginx -s reload
publics Reload
fi
return $RETVAL
}
#case 語句使用選擇
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
reload)
reload
RETVAL=$?
;;
restart)
stop
sleep 2
start
RETVAL=$?
;;
*)
echo "USAGE:$0 {satrt|stop|restart|reload}"
exit 1
;;
esac
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。