29

Is there a difference between calling

systemctl reload nginx

and calling

nginx -s reload

?

I know that, besides systemd, there are other init systems like SysV and Upstart. So maybe this question applies to them too.

Is it preferable to issue this command through the init system or can I just call nginx itself?

Thanks in advance

1
  • 1
    Actually if your system supports it, I would prefer using service or init.d, like sudo service nginx reload Feb 11, 2014 at 14:50

4 Answers 4

32

You can find out what systemd reload nginx will do by looking at the ExecReload= option in the [Service] section in the nginx.service unit file (located at /usr/lib/systemd/system/nginx.service on my system):

$ systemctl cat nginx | grep ExecReload=

Or by running:

$ systemctl show nginx.service --property=ExecReload

On my system, I get:

ExecReload=/usr/bin/kill -HUP $MAINPID

From nginx(8):

-s signal      Send a signal to the master process. The argument signal
               can be one of: stop, quit, reopen, reload. The following
               table shows the corresponding system signals:

               stop    SIGTERM
               quit    SIGQUIT
               reopen  SIGUSR1
               reload  SIGHUP

Thus systemctl reload nginx and nginx -s reload will, almost, do the same thing.

The differences are:

  • systemctl reload nginx will execute the command in a clean environment (and not the current user environment);
  • systemctl reload works for any service that allows it (which has it configured in the unit file). No need to remember service specific commands. This is even more interesting if you have several instances of a service.

Using service or init.d scripts are legacy/deprecated ways of doing the same thing. Although they might work, they are not supported nor recommended anymore on a systemd based system.

1
  • The OP seems to have not been here for a long time, but I think answer deserves to be accepted.
    – wlnirvana
    Feb 25, 2021 at 0:37
7

Currently there is a difference on Centos 7 and RHEL 7. Using systemctl reload nginx will NOT validate your configuration.

See the following bug: https://bugzilla.redhat.com/show_bug.cgi?id=1565377

So I would advise using nginx -s reload or updating your nginx unit file to use the following reload command:

ExecReload=/usr/sbin/nginx -s reload

https://bugzilla.redhat.com/attachment.cgi?id=1419614&action=diff

1
  • Thanks for this excellent tip. service nginx reload used to not only prevent reloading if errors exist, it would display the errors... systemctl reload nginx must be followed by systemctl status nginx for the same effect. Any idea if error reporting can also be achieved via ExecReload? Oct 21, 2022 at 14:31
1

I prefer nginx -s reload. On Centos8 systemctl reload nginx does /bin/kill -s HUP $mainpid, so if there are any errors in configuration it doesn't provide you any information (you will need to go look at the nginx error.log file to see where the error is). nginx -s reload will print errors to the console, which I find more convenient.

0

We had no success with systemctl. However, in order to reload an nginx config you can send HUP to the master process[1]. We just use killall (no it doesn't kill, it sends a signal) to send HUP to all nginx processes. I assume the workers just ignore the HUP:

sudo killall -s HUP nginx

Voila! The new config is loaded and applied.

[1] http://nginx.org/en/docs/control.html

You must log in to answer this question.

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