5

When I stop nginx like this on ubuntu 12.04, I get the following errors:

$ sudo service nginx stop
Stopping nginx: nginx.
$sudo service nginx start
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

I have to use this to fix it. Why does't stopping the service kill the nginx process? That is confusing!

2

2 Answers 2

6

By default start-stop-daemon send SIGTERM to nginx process. It doesn`t guarantee stop process. Fix: in file /etc/init.d/nginx change in section "stop" string

start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \

to

start-stop-daemon --stop --retry=TERM/30/KILL/5 --quiet --pidfile /var/run/$NAME.pid \

That fix send SIGKILL (kill -9) if SIGTERM don`t stop process.

And ensure please, that path to pid-file pid /var/run/nginx.pid; in /etc/nginx/nginx.conf and path --pidfile /var/run/$NAME.pid in /etc/init.d/nginx are the same.

3

If your system has systemd, use it to kill the service - Root may be needed:

systemctl kill nginx.service

More information.

3
  • systemctl kill is what you mean?!
    – Ned64
    Sep 8, 2015 at 13:00
  • @Ned64 Yes, but I just wrote "use systemd kill" and put the link to the commands (to mean use the systemd kill option, I did not intend to write exact command, which is of course what you wrote, and I did not want to repeat given the link has it). Some editor here has formatted the text to look like systemd is a command and changed the link to 'more information text', after I submitted it.
    – user133216
    Sep 8, 2015 at 13:57
  • 2
    It's preferable to repeat the command; links are nice, but answers should be written as though the link isn't there, or if/when it breaks the answer becomes useless Sep 8, 2015 at 14:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .