NGINX启动作业(initd)不停止

我在我的debian 7.4机器上编译了最后一个Nginx版本(1.7),它基于不同的Web帖子和文档在这里合并。 它工作正常。 我还需要更改启动作业以定位新的Nginx可执行文件。 结果是我可以启动,但无法使用服务命令停止http服务器。

Nginx 1.7.0可执行文件位置:

/opt/nginx/sbin/nginx.

我通过键入来删除以前的initd run nlevels配置

sudo update-rc.d nginx remove

在/etc/init.d/nginx我替换了这两行:

# PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# DAEMON=/usr/sbin/nginx

PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx

然后设置运行级别

sudo update-rc.d nginx defaults

sudo服务nginx开始工作正常,但停止命令不起作用。 sudo服务nginx停止不做任何事情,nginx作业是stil那里

root      3252     1  0 09:17 ?        00:00:00 nginx: master process /opt/nginx/sbin/nginx
www-data  3253  3252  0 09:17 ?        00:00:00 nginx: worker process

注意:我没有卸载旧的1.2 Nginx安装。

这是真的无聊和错误倾向于杀死并重新启动每个配置更新后的过程....

谢谢你的帮助。


固定

系统需要知道nginx守护进程的进程ID,以便能够在发出停止请求时将其终止。 包含此PID文件必须在/etc/init.d/nginx启动脚本中PIDFILE变量 nginx的配置文件中声明。 我忘了后者。

/etc/init.d/nginx

PIDFILE=/var/run/nginx.pid

/path/to/nginx.conf

pid     /var/run/nginx.pid;

这是整个启动脚本源代码

#! /bin/sh
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: nginx-1.7.0
# Description:       HTTP server and Reverse proxy
### END INIT INFO

# Author: Emmanuel Brunet <emmanuel.brunet@live.fr>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="nginx server"
NAME=nginx
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

[ -x "$DAEMON" ] || exit 0
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started

    start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --test > /dev/null 
        || return 1
    start-stop-daemon --start  --pidfile $PIDFILE --exec $DAEMON  
        || return 2
}

do_stop()
{

    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    [ "$?" = 2 ] && return 2
    rm -f $PIDFILE
    return "$RETVAL"
}

do_reload() {
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    echo "reloading" $DESC
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
    return 0
}

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
  #reload|force-reload)
    #
    # Insert code here if needed
    #;;
  restart|force-reload)
    #
    # Insert code here if needed
    #
    echo "Restarting $DESC"
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
            0) log_end_msg 0 ;;
            1) log_end_msg 1 ;; # Old process is still running
            *) log_end_msg 1 ;; # Failed to start
        esac
        ;;
        *)
        # Failed to stop
        log_end_msg 1
        ;;
    esac
    ;;
        *)
    #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
    esac

希望有所帮助。

链接地址: http://www.djcxy.com/p/95185.html

上一篇: NGINX startup job (initd) doesn't stop

下一篇: Nginx Module http