Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8374

Raspberry Pi OS • Re: Can't get a script to run on shutdown (Systemd) pi5 bookworm

$
0
0
This works.

/etc/systemd/system/test.service:

Code:

[Unit]Description=Shutdown pi nicelyAfter=network-online.target[Service]Type=oneshotRemainAfterExit=trueExecStop=/usr/local/bin/tester[Install]WantedBy=multi-user.target
/usr/local/bin/tester:

Code:

#!/bin/bashlogger "Tester ran!"
Be sure to:

Code:

sudo systemctl enable test.servicesudo chmod 755 /usr/local/bin/tester
Log snippet:

Code:

Jan 01 07:59:06 p43 systemd-logind[436]: The system will reboot now!Jan 01 07:59:06 p43 systemd-logind[436]: System is rebooting.Jan 01 07:59:06 p43 systemd[1]: Stopping test.service - Shutdown pi nicely...Jan 01 07:59:06 p43 root[709]: Tester ran!Jan 01 07:59:06 p43 systemd[1]: test.service: Deactivated successfully.Jan 01 07:59:06 p43 systemd[1]: Stopped test.service - Shutdown pi nicely.Jan 01 07:59:07 p43 systemd[1]: systemd-reboot.service: Deactivated successfully.Jan 01 07:59:07 p43 systemd[1]: Finished systemd-reboot.service - System Reboot.Jan 01 07:59:07 p43 systemd[1]: Reached target reboot.target - System Reboot.

Statistics: Posted by bls — Wed Jan 01, 2025 4:06 pm



Viewing all articles
Browse latest Browse all 8374

Trending Articles