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:The goal is to execute custom code when the following command is completed:
Thanks. Danny.
: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
The following code executes without error: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 ..."
Code:
sudo systemctl daemon-reloadsudo systemctl start preshutdownjournalctl -f -u preshutdown.service
Code:
sudo shutdown -r +10
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.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.
Thanks. Danny.
Statistics: Posted by deveals — Mon Nov 25, 2024 8:13 pm — Replies 0 — Views 4