I want to run a script at shutdown and reboot after rsyslog has stopped.
What do I have to write in my systemd service file /lib/systemd/system/test.service. So far I have
[Unit]
Description=test
RequiresMountsFor=/
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/which/path/should/itbe
[Install]
WantedBy=reboot.target halt.target shutdown.target poweroff.target
How can I run this after rsyslog has stopped?
This seems to be the only way How to run a script at shutdown on Debian 9 or Raspbian 8 (Jessie).
After=rsyslog.service
? And what's the logic behindWantedBy=multi-user.target
? It is not so easy to find useful documentation on this. – Frank Breitling Feb 24 '17 at 20:23WantedBy=multi-user.target
it means that it will be added to the dependency chain that leads to themulti-user.target
(which is the default target started on a machine)And I was wrong, if you want your service to be stopped After rsyslog you need to set
– Bigon Feb 24 '17 at 20:34Before=rsyslog.service
as the order is reversed between the boot and the shutdown.ExecStart=
but the configuration would even be more complex. Regarding the dependencies at shutdown (https://www.freedesktop.org/software/systemd/man/systemd.unit.html): "Note that when two units with an ordering dependency between them are shut down, the inverse of the start-up order is applied" – Bigon Feb 24 '17 at 20:56