On Mon, 03 Nov 2014 02:50:23 +0200 Mert Dirik <mertdi...@gmail.com> wrote:
I'm attaching a two different versions of the patch. First version (v1), reads /proc/1/comm to check if it's systemd or init. A potential problem with this approach is that the /proc/<pid>/comm interface works on only linux 2.6.33+. I don't know if it's really a problem. Second approach reads the output of "systemctl is-system-running" command. This command will print "stopping" if systemd is the init and the system is shutting down or rebooting. Otherwise (if systemd is not init or systemd is not installed at all, so the command doesn't exist) it will fail so the if check will fail.
systemd maintainers recommend this method to check if systemd is pid 1 (in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=741930#25):
- systemd The canonical check for systemd being PID 1 is [ -d /run/systemd/system ] See also man 3 sd_booted and [0]
The patch is attached (untested).
--- kexec-load.init.d 2014-11-03 02:35:02.197656058 +0200 +++ kexec-load.init.d_v3 2014-11-03 15:36:13.382149435 +0200 @@ -103,8 +103,7 @@ stop) # If running systemd, we want kexec reboot only if current # command is reboot - pidof systemd > /dev/null 2>&1 - if [ $? -eq 0 ]; then + if [ -d /run/systemd/system ]; then systemctl list-jobs systemd-reboot.service | grep -q systemd-reboot.service if [ $? -ne 0 ]; then exit 0