how to reload nginx - systemctl or nginx -s?
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
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.
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
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.