this is building on answers for Can systemd execute a command *before* a restart?
the current way to "start or restart" a service is:
systemctl is-active nginx && systemctl reload nginx || systemctl start nginx
I'm wondering if there's a better way using targets and such. I am having the feeling I am still trying to use systemd tooling as other init tools.
The case where i'd use this is after manual tweaks to the conf, which may work but crash during stress testing, and so i need to start or restart after new tweaks to the configuration file. Obviously the 'solution' here may be something that is not acceptable in production, as this is done on a vm/dev box.
systemctl restart nginx
will stop then start the unit. In all situations: if it was ever started or not, if it terminated unexpectedly, if the unit has a reload command or not. No need for an alternative verb to clean up after test runs.
ExecStartPre=/usr/sbin/nginx -t
Note that some systemd units for nginx, including distros like Fedora, have a syntax check before start. Also easy to do such a check in an editor or as automation is installing config files. Definitely will not catch everything, but finding the obvious typos earlier reduces downtime to fix them.
systemctl reload nginx
can be sufficient in situations where the only change is a config file. Your automation knows the package containing the executable was not updated but something in /etc/nginx/conf.d/ was. You consider it operational and as the unit was enabled on install can be assumed to be running, so gracefully reload.
Independent of the service manager, if this is important consider monitoring it. Regular requests from a different host, such as with a load balancer health check. Centrally collect error logs.