I have a Linux process that runs on RHEL7 and is started by systemd. When the process is stopped, I need to know if it is being stopped because of a system shutdown or reboot, and I need to be able to distinguish between the two.
Previously, under init on RHEL6, I was able to do this by looking at the pathname used to invoke my init script, and sent the process a different signal accordingly, i.e.:
case "$0" in
*rc0\.d*|*rc1\.d*) #shutdown
sig=USR1
;;
*rc6\.d*) #reboot
sig=USR2
;;
*)
sig=TERM
;;
esac
This doesnt work with systemd...although my init script gets called at the right time, $0 is always the same (/etc/init.d/scriptname).
Is there some way under systemd to know if you are being called because of a system shutdown or reboot? I'm happy to get rid of the init script and configure it as a systemd target instead, but from the documentation I can't see a way to do what I want.