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 

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

 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