21

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
    Actually if your system supports it, I would prefer using service or init.d, like sudo service nginx reload – Mohammad AbuShady Feb 11 '14 at 14:50
21

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.

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.