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

Raspberry Pi OS • Execute custom reboot and shutdown service/script on RPI 5 Bookworm

$
0
0
Hello and good day! I would like to execute custom code and shut down commands prior to system reboot and shutdown. Research on this forum identifies using systemctl/systemd as a solution on other systems but I'm unsuccessful implementing the following code on my Raspberry Pi 5/Bookworm:
cat /etc/systemd/system/preshutdown.service
:

Code:

[Unit]Description=Run custom command before reboot, poweroff, halt, or shutdownBefore=reboot.target poweroff.target halt.target shutdown.target[Service]Type=oneshotRemainAfterExit=trueExecStart=/bin/trueExecStop=/bin/bash /home/deveals/preshutdown.sh[Install]WantedBy=multi-user.target
deveals@melkor:~/scripts $ lsla /home/deveals/scripts/preshutdown.sh
-rwxr-xr-x 1 root root 122 Nov 25 13:41 preshutdown.sh
cat /home/deveals/scripts/preshutdown.sh
#!/bin/bash
# Excute custom shutdown script
sudo wall "Reboot, powercycle, or shutdown underway, and see you on the other side ..."
The following code executes without error:

Code:

sudo systemctl daemon-reloadsudo systemctl start preshutdownjournalctl -f -u preshutdown.service
The goal is to execute custom code when the following command is completed:

Code:

sudo shutdown -r +10
Broadcast message from root@melkor on pts/2 (Mon 2024-11-25 14:03:10 CST):

The system will reboot at Mon 2024-11-25 14:13:10 CST!

Reboot scheduled for Mon 2024-11-25 14:13:10 CST, use 'shutdown -c' to cancel.
Did I miss something or any ideas to supplement the custom broadcast message ( and soon with custom commands) preshutdown.sh? In advance, your expertise and assistance is appreciated.

Thanks. Danny.

Statistics: Posted by deveals — Mon Nov 25, 2024 8:13 pm — Replies 0 — Views 4



Viewing all articles
Browse latest Browse all 4644

Trending Articles