On Fri, Nov 23, 2018 at 10:02:15AM +0100, Olaf van der Spek wrote:
Op vr 23 nov. 2018 om 09:52 schreef Christos Trochalakis
<ctrochala...@debian.org>:
Yes, restarting Nginx is something that can be avoided, Nginx provides
such utilities.

You can just run something like `nginx -t && nginx -s reload`, that
checks the config and the gracefully reloads nginx (no restart). If
nginx configuration is not valid the script will return a non-zero
exit status.

>
>I think the conf files should be checked in restart before the old
>service is stopped.

This is working in sysvinit systems but is not supported in systemd
systems: systemd doesn't give an entrypoint for a pre restart command.

What about ExecStartPre?

It's already at `ExecStartPre=` [0], the problem is that in `systemd
restart nginx` ExecStartPre is executed **after** the service is
stopped, not in the start of the sequence.

[0] $ systemctl cat nginx.service|grep ^ExecStartPre=

ExecStartPre=, ExecStartPost=

Additional commands that are executed before or after the command in 
ExecStart=, respectively. Syntax is the same as for ExecStart=, except that 
multiple command lines are allowed and the commands are executed one after the 
other, serially.

If any of those commands (not prefixed with "-") fail, the rest are not 
executed and the unit is considered failed.

>Perhaps even better, but I'm not sure if systemd and nginx supports
>this, would be for the new instance to be fully started before the old
>one is stopped.
>

This can be done (in both sysvinit & systemd) systems by running
`/etc/init.d/nginx upgrade` but in your case a binary upgrade is not
needed, just a config reload (nginx -s reload).

Could "service nginx restart" use this same logic?
Users and packages probably don't know about nginx upgrade and will be
using the standard interfaces...

No, service restart just calls systemctl restart on systemd systems.
I think that both nginx restart & upgrade are commands that are rarely
needed in my experience: `service nginx reload` is what you usually need
and luckily that works as expected on both systemd & sysvinit.

Reply via email to