5

It took me a while to find out, but as of some recent-ish update, I can't stop Nginx on any of my Ubuntu 12.04 or Ubuntu 14.04 servers.

I run sudo service nginx stop, and I get nginx start/running, process 16178.

I try sudo service nginx stop again, and I get nginx start/running, process 16206.

Note how the process number changes.

In /var/log/syslog I can see why:

Jun 11 11:57:51 kernel: [2318556.994508] init: nginx main process ended, respawning.

Nginx is respawned every time I run sudo service nginx stop. It never comes to a full stop.

I tried updating Ubuntu, rebooted and I re-installed my servers on local test-images (I use Puppet). Nothing makes any difference. I also tried searching for bugs relating to this without avail.

Does anyone know how I can fix this problem? I'd like to be able to run sudo service nginx stop and have all nginx processes stopped as a result.

href_
  • 149
  • Are you using a PPA for nginx? The packages for nginx in Ubuntu at least upto 14.04 use sysv init scripts, not Upstart init files. The respawn option is an Upstart thing, and neither Ubuntu's package for nginx nor the nginx team's PPA (https://launchpad.net/~nginx/+archive/ubuntu/stable) use Upstart. – muru Jul 31 '15 at 23:16
  • I'm using ppa:nginx/stable on 12.04 and 14.04 – href_ Aug 01 '15 at 08:54

3 Answers3

4

You can stop nginx process using sudo nginx -s quit

You can see in /etc/init/nginx

Melebius
  • 11,431
  • 9
  • 52
  • 78
4

It seems you nginx server is handle by an upstart process.

Look in the /etc/init folder, and check if there is not a file which handles nginx.

grep -r nginx /etc/init

Then edit this file, and remove the respawn option in the config file.

aklmie
  • 1,046
  • Thanks. I just wanted to try your solution when I noticed that it now works. I'm guessing some update solved the problem? Or maybe it was a reboot.

    In any case, this answer is helpful to me as it will help me find the problem should it resurface.

    – href_ Jul 30 '15 at 07:01
  • It's work, for e too. Additionally, I follow the instructions in http://askubuntu.com/questions/19320/how-to-enable-or-disable-services to avoid it automatically starts. – molavec Feb 14 '16 at 21:27
0

I had the same problem, when I wanted to update my letsencrypt certificates with a temporary webserver by certbot: every time, i stopped nginx with

service stop nginx

after some seconds it restarted automatically so when it came to serving the proof of my domain certbot, port 443 was already in use by the respawned nginx.

I was really in a hurry to fix this, so I started a really dirty workaround, but it worked:

while true; do service nginx stop; sleep 2; done

Now I was able to refresh my certificates and find out later, how to stop nginx for good in a more correct way ;)

rubo77
  • 32,486