For some reason this piqued my interest, so I spent a bit of time trying to differentiate between shutdown, reboot, and halt.
According to the systemctl man page, each of these is equivalent to "systemctl start xxx.target", for xxx being one of shutdown, reboot, or halt.
I set up a service with an ExecStop like yours. The script:Unfortunately, the systemctl documentation appears to be incorrect. /usr/local/bin/sdxout shows that none of the targets are active.So, you apparently can't use this technique to figure out whether it's a shutdown, reboot, etc.
But, you could set up a script that you use to do the shutdown, reboot, etc that sets an envar in a file that your "shutdown" script reads to figure out what is going to happen after the shutdown. That should work, but I left that as an exercise for the reader Image may be NSFW.
Clik here to view.
According to the systemctl man page, each of these is equivalent to "systemctl start xxx.target", for xxx being one of shutdown, reboot, or halt.
I set up a service with an ExecStop like yours. The script:
Code:
#!/bin/bashrm -f /usr/local/bin/sdxoutecho "halt=$(systemctl show -p ActiveState halt.target --value)" >> /usr/local/bin/sdxoutecho "kexec=$(systemctl show -p ActiveState kexec.target --value)" >> /usr/local/bin/sdxoutecho "poweroff=$(systemctl show -p ActiveState poweroff.target --value)" >> /usr/local/bin/sdxoutecho "reboot=$(systemctl show -p ActiveState reboot.target --value)" >> /usr/local/bin/sdxoutecho "halt-active=$(systemctl is-active halt.target)" >> /usr/local/bin/sdxoutecho "kexec-active=$(systemctl is-active kexec.target)" >> /usr/local/bin/sdxoutecho "poweroff-active=$(systemctl is-active poweroff.target)" >> /usr/local/bin/sdxoutecho "reboot-active=$(systemctl is-active reboot.target)" >> /usr/local/bin/sdxout
Code:
halt=inactivekexec=inactivepoweroff=inactivereboot=inactivehalt-active=inactivekexec-active=inactivepoweroff-active=inactivereboot-active=inactive
But, you could set up a script that you use to do the shutdown, reboot, etc that sets an envar in a file that your "shutdown" script reads to figure out what is going to happen after the shutdown. That should work, but I left that as an exercise for the reader Image may be NSFW.
Clik here to view.

Statistics: Posted by bls — Tue Feb 06, 2024 7:50 pm