zoukankan      html  css  js  c++  java
  • linux 下Nginx启动、关闭、重新加载脚本

    转自:http://www.cnblogs.com/likehua/p/4015074.html

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    #! /bin/sh
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts the nginx web server
     
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DESC="nginx daemon"
    NAME=nginx
    <span style="color: #ff0000;"><strong>DAEMON=/usr/local/nginx/sbin/$NAME
    CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
    PIDFILE=/usr/local/nginx/logs/$NAME.pid</strong></span>
    SCRIPTNAME=/etc/init.d/$NAME
     
    set -e
    [ -x "$DAEMON" ] || exit 0
     
    do_start() {
     $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
    }
     
    do_stop() {
     kill -INT `cat $PIDFILE` || echo -n "nginx not running"
    }
     
    do_reload() {
     kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
    }
     
    case "$1" in
     start)
     echo -n "Starting $DESC: $NAME"
     do_start
     echo "."
     ;;
     stop)
     echo -n "Stopping $DESC: $NAME"
     do_stop
     echo "."
     ;;
     reload|graceful)
     echo -n "Reloading $DESC configuration..."
     do_reload
     echo "."
     ;;
     restart)
     echo -n "Restarting $DESC: $NAME"
     do_stop
     do_start
     echo "."
     ;;
     *)
     echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
     exit 3
     ;;
    esac
     
    exit 0

      备注:着红色的地方要根据实际路径进行修改,将上述脚本命名为nginx,保存到/etc/init.d目录下。尝试/etc/init.d/nginx start 命令,会报“权限不足”的错误,执行chmod +x /etc/init.d/nginx 给其赋执行权限。

        可以用一下方式来执行此脚本:

         /etc/init.d/nginx start

         /etc/init.d/nginx sttop

        /etc/init.d/nginx reload

        /etc/init.d/nginx restart

       如果想让此脚本开机自启动  还需在脚本头部家 chkconfig xx  xx等注释(具体需要参考chkconfig命令用法),让它支持chckconfig  然后执行/sbin/chkconfig nginx on 命令。同时,可以sudo /sbin/chkconfig --list nginx  来查看效果。

  • 相关阅读:
    数据库范式
    SQL--使用NewID函数,创建GUID列
    初学Python
    Artificial intelligence(AI)
    Concurrency in csharp (Asynchronous, Parallel, and Multithreaded Programming)
    MySQL 5.7 create VIEW or FUNCTION or PROCEDURE
    csharp: Oracle Stored Procedure DAL using ODP.NET
    csharp: ODP.NET,System.Data.OracleClient(.net 4.0) and System.Data.OleDb读取Oracle g 11.2.0的区别
    csharp:ASP.NET SignalR
    csharp: MySQL Stored Procedure using DAL
  • 原文地址:https://www.cnblogs.com/shininguang/p/4936700.html
Copyright © 2011-2022 走看看