Systemd - How to trigger another unit while reloading a service?

758 views Asked by At

I'm currently facing the issue that I want to trigger a Systemd unit when another unit get reloaded - not restartet. This is what I achived so far:

[Unit]
After=teleport.service
Requires=teleport.service
PartOf=teleport.service

[Service]
ExecStart=/usr/bin/bash -c "Reloaded gracefully | /usr/bin/logger"

But that is only working using systemctl restart teleport. Reload doesn't work. How can this be achived without touching the original teleport.service unit?

1

There are 1 answers

0
Pegasus1985 On BEST ANSWER

Found out that this can be easily achived by drop-in files. Instead of writing a new unit drop-in files can be used like this:

You can create drop-in files in /etc/systemd/... for units defined in /lib or /usr/lib: /etc/systemd/system/teleport.service.d/override.conf

[Service] 
ExecReload=
ExecReload=/usr/bin/bash -c "/bin/kill -HUP $MAINPID; usr/bin/bash -c "Reloaded gracefully | /usr/bin/logger"

First the defined attribute needs to be unset. What happens directly after [Service].