how to reload nginx - systemctl or nginx -s?

24

5

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

moonring

Posted 2014-02-03T23:39:32.610

Reputation: 241

1Actually if your system supports it, I would prefer using service or init.d, like sudo service nginx reload – Mohammad AbuShady – 2014-02-11T14:50:34.827

Answers

24

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.

Siosm

Posted 2014-02-03T23:39:32.610

Reputation: 396

5

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

Stijn Diependaele

Posted 2014-02-03T23:39:32.610

Reputation: 151