2

We use Nginx across multiple servers and are currently running 1.11.10.

I am creating an Ansible script to deploy some configuration changes. The script copies the new configuration file to the server and then issues a command to reload the Nginx configuration.

Is there any way I can confirm that the file has been reloaded successfully? Using "systemctl status nginx" at the command line just gives me the status of the server and details when it was last restarted, not when the configuration was last reloaded.

Many thanks in advance for any information or help.

Raghu Ariga
  • 1,059
  • 1
  • 19
  • 28
GarlicBread
  • 1,671
  • 8
  • 26
  • 49
  • I use `nginx -t` to test it before I apply reload (and I'm not aware if there is even a way to obtain the last configuration reload time) – zerkms May 21 '18 at 00:53
  • What you are asking is basically "[how to get the start time of a long-running Linux process](https://stackoverflow.com/questions/5731234/how-to-get-the-start-time-of-a-long-running-linux-process)" – hcheung May 21 '18 at 01:27
  • 2
    @hcheung it's not: processes are not restarted during the `reload` operation. – zerkms May 21 '18 at 01:42

1 Answers1

2

That nginx -s reload return success(echo $?) tell us nginx load configurations successfully, but now the latest configuration may not worker for every request, because there maybe some connections with old worker are still not finished, at this time, the system has double worker processes as configured.

  1. master-worker mode

    The master process load the new configurations and spawn new worker processes with it, then stop the the old worker process after they finish the already existed connections

    let's try with worker_processes 2;

    ✗ ./sbin/nginx
    ✗ ps aux|grep nginx
    larryhe         2572   Ss    2:43PM   0:00.00 nginx: master process ./sbin/nginx
    larryhe         2575   S     2:43PM   0:00.00 nginx: worker process
    larryhe         2573   S     2:43PM   0:00.00 nginx: worker process
    
    ✗ ./sbin/nginx -s reload
    ✗ ps aux|grep nginx
    larryhe         2572     Ss    2:43PM   0:00.01 nginx: master process ./sbin/nginx
    larryhe         2706     S     2:44PM   0:00.00 nginx: worker process
    larryhe         2705     S     2:44PM   0:00.00 nginx: worker process
    

    The second column is pid, we can see that pids of worker processes are different before and after reload.

  2. single-master mode

    The master process apply the latest configuration within the process without restarting, it's done if nginx -s reload returns success.

Larry.He
  • 604
  • 5
  • 16