I have this script that I'm trying to get the system to execute on shutdown and only on shutdown (or restart for that matter). This script doesn't start or stop a server; it merely unmounts some file systems. Unfortunately a lot of the documentation I find seems to think I'm going to write a script to manage a server, but that's not what I'm doing at all.
Reading http://tuxgraphics.org/npa/systemd-scripts/ and man systemd.service
and man systemd.unit
(I'm not even sure what I'm supposed to be following) I have:
[Unit]
Description=My umount script
After=network.target syslog.target
[Service]
Type=oneshot
ExecStop=/home/PL/bin/umountb2.sh
StandardOutput=journal
But I have no idea if that's right and I'm even less confident that it will be executed at the right time. I need it to execute sometime after all the regular users are logged out but not before any file systems are unmounted.
I'm running Ubuntu 22.04.2
Edit: now the config file looks like this:
Description=My special shutdown script
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/home/PL/bin/umountb2.sh
[Install]
WantedBy=multi-user.target
And things have improved, but there's a problem, because my script calls cryptsetup
which returns an error. I think it's being executed too late, because when I restart, I run journalctl -b -1 --dmesg
there are only 3 messages that follow my script, the first being:
kernel: nfsd: last server has exited, flushing export cache