0

我刚刚在我的 debian 7.4 机器上编译了最后一个 Nginx 版本(1.7),基于不同的网络帖子和文档合并在这里。它工作正常。我还需要更改启动作业以针对新的 Nginx 可执行文件。结果是我可以使用service命令启动但无法停止 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 service 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 安装。

每次配置更新后杀死并重新启动进程真的很无聊且容易出错....

谢谢你的帮助。

4

1 回答 1

0

使固定

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

/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

希望有帮助。

于 2014-06-04T12:45:55.737 回答