溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

模擬Nginx服務(wù)啟動關(guān)閉

發(fā)布時間:2020-06-15 16:28:41 來源:網(wǎng)絡(luò) 閱讀:532 作者:匿名不回信 欄目:建站服務(wù)器

已知Nginx管理命令為:

啟動:/application/nginx/sbin/nginx

停止:/application/nginx/sbin/nginx -s stop

重新加載:/application/nginx/sbin/nginx -s reload

請用case腳本模擬Nginx服務(wù)啟動關(guān)閉:

/etc/init.d/nginx {start|stop|reload|restart},并可通過chkconfig管理。

[root@web01 ~]# cat /etc/init.d/nginx
#/bin/sh
# chkconfig: 2345 15 62  #設(shè)定運行級別以及啟動和停止Nginx服務(wù)順序
# 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



向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI