Nginx 似乎无法正确停止

Nginx 似乎无法正确停止

我正在使用以下脚本来启动/停止 nginx:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  reload)
          echo -n "Reloading $DESC configuration: "
          start-stop-daemon --stop --signal HUP --quiet --pidfile     /opt/nginx/logs/$NAME.pid \
              --exec $DAEMON
          echo "$NAME."
          ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
            exit 1
            ;;
    esac

    exit 0

运行以下任一操作后:

/etc/init.d/nginx stop

或者

service nginx stop

它确实将消息输出到控制台“正在启动/停止 nginx”。但如果我在停止后尝试启动,则会收到常见的无法绑定()错误,因为它仍在运行。

当我跑步时:

ps -elf | grep nginx

我仍然看到有两个进程正在运行:

1 S root      2113     1  0  80   0 -  9043 rt_sig 07:36 ?        00:00:00 nginx: master process /opt/nginx/sbin/nginx
5 S nobody    2114  2113  0  80   0 -  9172 ep_pol 07:36 ?        00:00:00 nginx: worker process
0 S root      5541  5280  0  80   0 -  1609 pipe_w 11:29 pts/1    00:00:00 grep --color=auto nginx

我如何诊断服务无法正确停止的原因?

更新

实际上当我这样做/etc/init.d/nginx stop

我懂了:

sudo: unable to resolve host myhostname

相关内容