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

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

$
0
0
Hi All
I have been trying to get a script to run on shutdown/reboot with no success. Ultimately I want to close a running program gracefully before shutting down or rebooting but for now I am simply calling a script which just touches a file as a test. It works when I test it with:

Code:

systemctl stop shutdown.service 
The file appears when I do this. But when issuing a reboot or shutdown it doesn't work, no file is there after reboot. I have yet to find an example that works and I am wondering if it is because the file system is remounted read only before my script is run. I have been reading for ages and nothing helps.
Here is what I have in /etc/systemd/system/ with various commented out attempts:

Code:

[Unit]Description=Shutdown pi nicelyDefaultDependencies=no#RequiresMountsFor=/#Before=shutdown.target reboot.target halt.targetAfter=final.target[Service]Type=oneshotExecStart=/bin/trueRemainAfterExit=trueExecStop=/home/pi/Documents/shutdowntest.sh[Install]#WantedBy=halt.target reboot.target shutdown.targetWantedBy=final.target

Statistics: Posted by jimseng — Wed Jan 01, 2025 11:50 am — Replies 4 — Views 72



Viewing all articles
Browse latest Browse all 3466

Trending Articles