caktus / margarita

A collection of delicious Salt states for Django project deployments.
BSD 3-Clause "New" or "Revised" License
34 stars 8 forks source link

Nginx doesn't restart or reload #125

Open vkurup opened 8 years ago

vkurup commented 8 years ago

The upstart script included with Nginx via the PPA doesn't work.

reload fails with an incorrect error message.

vkurup@ip-10-151-109-228:~$ sudo service nginx reload
reload: Not running

restart claims to work but doesn't actually restart the processes:

vkurup@ip-10-151-109-228:~$ ps auxw | grep nginx
www-data  5631  0.0  0.1  76168  1900 ?        S    16:10   0:00 nginx: worker process
www-data  5632  0.0  0.2  76320  3852 ?        S    16:10   0:00 nginx: worker process
www-data  5633  0.0  0.1  76168  1900 ?        S    16:10   0:00 nginx: worker process
www-data  5634  0.0  0.1  76168  3124 ?        S    16:10   0:00 nginx: worker process
vkurup    6210  0.0  0.0   8100   936 pts/2    S+   16:17   0:00 grep --color=auto nginx
root      6920  0.0  0.2  75856  4408 ?        S    Feb01   0:00 nginx: master process /usr/sbin/nginx
vkurup@ip-10-151-109-228:~$ sudo service nginx restart
nginx stop/waiting
nginx start/running
vkurup@ip-10-151-109-228:~$ ps auxw | grep nginx
www-data  5631  0.0  0.1  76168  1900 ?        S    16:10   0:00 nginx: worker process
www-data  5632  0.0  0.2  76320  3852 ?        S    16:10   0:00 nginx: worker process
www-data  5633  0.0  0.1  76168  1900 ?        S    16:10   0:00 nginx: worker process
www-data  5634  0.0  0.1  76168  3124 ?        S    16:10   0:00 nginx: worker process
vkurup    6251  0.0  0.0   8100   936 pts/2    S+   16:18   0:00 grep --color=auto nginx
root      6920  0.0  0.2  75856  4408 ?        S    Feb01   0:00 nginx: master process /usr/sbin/nginx

Possible workarounds:

vkurup commented 8 years ago

Just to complicate this a little...

The above commands were from Duckling's staging server. I ran the same commands on Duckling's production server (identical OS, versions etc, just a larger machine) and they worked fine. So it seems that this issue may be intermittent from server to server...

mlavin commented 8 years ago

What version of Nginx is running on those servers?

vkurup commented 8 years ago

nginx version: nginx/1.8.1

on both staging and production.

mlavin commented 8 years ago

Could this be only an issue for projects which were installed at 1.8.X vs those which were installed on an earlier version and later upgraded to 1.8.X. Grasping at straws here.

vkurup commented 8 years ago

Hmmm... that is plausible. I could see how changing init scripts might mess things up. Staging was provisioned way before production, in this case.

vkurup commented 8 years ago

That was it! Staging's nginx had been started before the PPA was installed. Once I manually killed the master process, then all the upstart commands started working normally.

Here's one way to tell if you're running an "old" master process:

vkurup$ ps auxw | grep 'nginx: master'
root      6920  0.0  0.2  75856  4408 ?        S    Feb01   0:00 nginx: master process /usr/sbin/nginx

The PPA version should have some command line parameters. It should look like this:

vkurup$ ps auxw | grep 'nginx: master'
root     18338  0.0  0.1  75864  3100 ?        Ss   16:30   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

To fix it, kill the "old" process and then use the normal upstart commands:

vkurup$ sudo kill `cat /var/run/nginx.pid`
vkurup$ sudo reload nginx

It seems it would need a 1-time fix on any server that was running the Ubuntu-provided nginx and then upgraded to the PPA. Not sure if we should do that manually across our servers, or write something in salt to do it.

dpoirier commented 8 years ago

The annoying thing about this problem is that there's nothing wrong with these systems' configurations; they've just in a state they can't get themselves out of in the normal course of deploying to them. A simple reboot would sort it out.