2014-05-03 23 views
0

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

的Nginx 1.7.0可执行位置:

/opt/nginx/sbin/nginx. 

我在/etc/init.d/nginx除去由类型先前INITD NLEVELS运行配置

sudo update-rc.d nginx remove 

我取代这两条线:

# 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的启动工作正常,但停止命令不起作用。 须藤服务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的安装。

这真是枯燥,容易出错杀和每个配置更新之后重新启动该进程....

感谢您的帮助。

回答

0

修复

系统需要知道nginx的守护进程的进程ID,以便能够发出停止请求时将其杀死。包含此PID的文件必须在nginx配置文件中的/etc/init.d/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 <[email protected]> 
# 
# 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 

。希望帮助。