0

I have a script that I want to run at logout/reboot and shutdown with a .service file in /etc/systemd/system.

[Unit]
Description=My description
DefaultDependencies=no
Before=poweroff.target halt.target reboot.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/path/to/myscript.sh

[Install]
WantedBy=poweroff.target halt.target reboot.target

I have enabled the script with systemctl and it works on reboot and shutdown but not on logout. Is it doable?

1 Answer 1

0

Assuming this is a user service, running on user logout (and, in turn, shutdown while the user is logged in) can be done by (ab)using ExecStop:

[Service]
Type=exec
ExecStart=/bin/echo
ExecStop=/path/to/myscript.sh
1
  • Thanks for your answer but sorry, that did not work for me. Let me explain what I am trying to achieve. I am on Arch with two windowmanagers and using SDDM as loginmanager. If I change wallpaper in one of the windowmanagers the SDDM login manager wallpaper should be updated to the same wallpaper at logout, shutdown and reboot. This is what my script does. Its working on shutdown and reboot but not when I logout from one the windowmanagers, and I don't know if it's doable with systemd.
    – Laphroigh
    Commented Jan 9 at 11:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .