Debian-NGINX启动作业(initd)不';停不下来

Debian-NGINX启动作业(initd)不';停不下来,nginx,debian,startupscript,Nginx,Debian,Startupscript,我刚刚在我的debian 7.4机器上编译了上一个Nginx版本(1.7),它基于不同的web文章和合并的文档。它很好用。 我还需要更改启动作业,以新的Nginx可执行文件为目标。结果是,我可以启动http服务器,但不能使用服务命令停止http服务器 Nginx 1.7.0可执行文件位置: /opt/nginx/sbin/nginx. 我按输入删除了以前的initd run nlevels配置 sudo update-rc.d nginx remove 在/etc/init.d/nginx

我刚刚在我的debian 7.4机器上编译了上一个Nginx版本(1.7),它基于不同的web文章和合并的文档。它很好用。 我还需要更改启动作业,以新的Nginx可执行文件为目标。结果是,我可以启动http服务器,但不能使用服务命令停止http服务器

Nginx 1.7.0可执行文件位置:

/opt/nginx/sbin/nginx.
我按输入删除了以前的initd run nlevels配置

sudo update-rc.d nginx remove
在/etc/init.d/nginx I中替换了这两行:

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

然后设置运行级别

sudo update-rc.d nginx defaults
sudo服务nginx start工作正常,但stop命令不起作用sudo service nginx stop什么都不做,nginx作业仍然存在

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
/路径/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
#/垃圾箱/垃圾箱
###开始初始化信息
#提供:nginx
#必需的开始:$local_fs$remote_fs$network$syslog
#所需停止:$local\u fs$remote\u fs$network$syslog
#默认开始:2 3 4 5
#默认停止:0 1 6
#X-Interactive:真的吗
#简短说明:nginx-1.7.0
#描述:HTTP服务器和反向代理
###结束初始化信息
#作者:Emmanuel Brunet
#
#请删除上面的“作者”行并替换它们
#如果复制和修改此脚本,请使用您自己的名称。
#如果路径在mountnfs.sh脚本之后运行,则仅应包括/usr/*路径
路径=/sbin:/usr/sbin:/bin:/usr/bin
DESC=“nginx服务器”
NAME=nginx
守护进程=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
[-x“$DAEMON”]| |退出0
[-r/etc/default/$NAME]&&&/etc/default/$NAME
. /lib/init/vars.sh
. /lib/lsb/init函数
你要开始吗
{
#返回
#如果守护进程已启动,则返回0
#1如果守护进程已在运行
#2如果守护进程无法启动
start-stop守护进程--start--pidfile$pidfile--exec$daemon--test>/dev/null\
||返回1
start-stop守护进程--start--pidfile$pidfile--exec$daemon\
||返回2
}
停止
{
start-stop守护进程--stop--quiet--retry=TERM/30/KILL/5--pidfile$pidfile--name$name
RETVAL=“$?”
[“$RETVAL”=2]&返回2
启动停止守护进程--停止--安静--oknodo--重试=0/30/KILL/5--执行$daemon
[“$?”=2]&返回2
rm-f$PIDFILE
返回“$RETVAL”
}
你要重新加载吗{
#
#如果守护进程可以重新加载其配置而无需
#重新启动(例如,当发送SIGHUP时),
#然后在这里实现它。
#
回显“重新加载”$DESC
启动-停止守护进程--停止--信号1--安静--pidfile$pidfile--名称$name
返回0
}
案件“$1”
开始)
[“$VERBOSE”!=no]&&log\u daemon\u msg“Starting$DESC”“$NAME”
你要开始吗
中的大小写“$?”
0 | 1)[“$VERBOSE”!=no]&记录消息0;;
2) [“$VERBOSE”!=no]&记录消息1;;
以撒
;;
(停止)
[“$VERBOSE”!=no]&&log\u daemon\u msg“Stopping$DESC”“$NAME”
你停下来吗
中的大小写“$?”
0 | 1)[“$VERBOSE”!=no]&记录消息0;;
2) [“$VERBOSE”!=no]&记录消息1;;
以撒
;;
(状态)
_proc“$DAEMON”“$NAME”和&exit 0的状态| | exit$?
;;
#重新加载(强制重新加载)
#
#如果需要,请在此处插入代码
#;;
重新启动(强制重新加载)
#
#如果需要,请在此处插入代码
#
echo“重新启动$DESC”
你停下来吗
中的大小写“$?”
0|1)
你要开始吗
中的大小写“$?”
0)日志结束消息0;;
1) 日志结束消息1;#旧进程仍在运行
*)日志结束消息1;#启动失败
以撒
;;
*)
#未能停止
日志\u结束\u消息1
;;
以撒
;;
*)
#echo“用法:$SCRIPTNAME{start | stop | restart | reload | force reload}>&2
echo“用法:$SCRIPTNAME{start | stop | status | restart | force reload}>&2
出口3
;;
以撒
希望有帮助

#! /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