How to reload a group of systemd services

systemd

I want to reload (not restart!) a group of services upon an event.

For example, if I update my SSL certificates, I want every service that uses them reloaded (nginx and postfix come to mind). Neither I want to remember which services on a given server use SSL certificates. It should be enough to have them grouped when they were configured.

On the other hand, I'd like to avoid changing .service files provided with the packages, because this will require manual intervention during updates.

How do I accomplish that?

There is an option to stop a group of services on request, but this would make them inaccessible for a second or two, or worse – they may stay down until fixed. I can't afford that.

Best Answer

Create /etc/systemd/system/ssl-reload.target with the following contents.

[Unit]
Description=Services which need reloaded with SSL certs are updated.
PropagatesReloadTo=nginx postfix

Then create another file: /etc/systemd/system/ssl-reload.path

[Unit]
Description=Restart services which use SSL when the cert directory changes

[Path]
PathChanged=/path/to/your/ssl/certs/dir

[Install]
WantedBy=multi-user.target

Then:

systemctl enable ssl-reload.path
systemctl start ssl-reload.path

With that said, after changing something in your SSL directory, the desired services should be reloaded automatically.

if you don't want the automatic behavior, then don't use the .path file, and just issue systemctl reload ssl-reload.target manually after you change SSL files.

Related Question