The execution of a script on shutdown is required (such as formerly scripts in rc0.d and rc6.d would) but the script is only being executed when the service is stopped manually using
Code: Select all
systemctl stop service
Code: Select all
shutdown -r now
System: Debian 11
To reproduce:
install debian11 netinstall
Code: Select all
#!/bin/bash
cat << THISISTHEEND > /etc/systemd/system/sd.service
[Unit]
Description=do fancy stuff on shutdown
DefaultDependencies=no
Before=shutdown.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/runatshutdown.sh
TimeoutStartSec=0
[Install]
WantedBy=shutdown.target
THISISTHEEND
cat << THISISTHEEND > /usr/local/bin/runatshutdown.sh
#!/bin/bash
logger "hey, we're about to shut down this host"
touch /home/flag
THISISTHEEND
chmod u+x /usr/local/bin/startup_script.sh
systemctl enable sd
systemctl start sd
Code: Select all
[Unit]
Description=more details here
DefaultDependencies=no
After=final.target
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/usr/local/bin/runatshutdown.sh
[Install]
WantedBy=multi-user.target
The first example is taken from this tutorial: https://www.golinuxcloud.com/run-script ... e_shutdown
The second example is what I've come up with using man pages and other documentation.
Help will be appreciated!