Similar, but not identical to Run script at shutdown/reboot with systemd:
I want to run a custom process using systemd
when the system is going down (shutdown or reboot, maybe panic also), and when the system is booting.
Both actions should be run as early as possible.
Obviously the Type
of service will be a oneshot
, but I'm unsure about the rest (Wants
, Before
, After
, WantedBy
, etc.).
As my process needs the journal, I had added (among others):
[Unit]
DefaultDependencies=no
Wants=syslog.target
After=local-fs.target exit.target
Before=multi-user-target
[Service]
Type=oneshot
RemainAfterExit=no
[Install]
WantedBy=multi-user.target
When having enabled the service, my program is started (via ExecStart=
) after local filesystems are mounted, but it is immediately started again (via ExecStop=
) before temporary files are being created.
On reboot it was not started at all.