您好,登錄后才能下訂單哦!
已知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|reload|restart},并可通過chkconfig管理。
[root@web01 ~]# cat /etc/init.d/nginx #/bin/sh # chkconfig: 2345 15 62 #設定運行級別以及啟動和停止Nginx服務順序 # description: Nginx Server #腳本說明 [ -f /etc/init.d/functions]&&. /etc/init.d/functions||exit 1 #Define Arivables Path=/application/nginx/sbin/nginx RETVAL=0 #Define Start Function start() { if [ `ss -lntup|grep nginx|wc -l` -gt 0];then echo "Nginx is Running..." else $Path RETVAL=$? if [ $RETVAL -eq 0 ];then action "Starting Nginx..."/bin/true else action "Starting Nginx..."/bin/false fi fi return $RETVAL } #Define Stop Function stop() { if [ `ss -lntup|grep nginx|wc -l` -gt 0];then $Path -s stop RETVAL=$? if [ $RETVAL -eq 0 ];then action "Stopping Nginx..."/bin/true else action "Stopping Nginx..."/bin/false fi else echo "Nginx is Stopped" fi return $RETVAL } #Define Restart Function reload() { if [ `ss -lntup|grep nginx|wc -l` -gt 0];then $Path -s reload RETVAL=$? if [ $RETVAL -eq 0 ];then action "Reloading Nginx..."/bin/true else action "Reloading Nginx..."/bin/false fi else echo "Nginx is Stopped" fi return $RETVAL } #Define Restart Function restart() { stop sleep 1 start return $RETVAL } case "$1" in start) start RETVAL=$? ;; stop) stop RETVAL=$? ;; reload) reload RETVAL=$? ;; restart) restart RETVAL=$? ;; *) echo "USAGE:$0 {start|stop|reload|restart}" RETVAL=2 ;; esac exit $RETVAL [root@web01 ~]# ls -l /etc/init.d/nginx -rwxr-xr-x. 1 root root 1680 Jun 9 12:13 /etc/init.d/nginx [root@web01 ~]# chkconfig --list|grep nginx nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。