Checking job queue instead of dbus

This commit is contained in:
Friedrich Doku 2023-01-06 21:32:57 -05:00
parent 4b7053a635
commit 7cf51a1b43
3 changed files with 29 additions and 21 deletions

View file

@ -30,26 +30,23 @@ else
fi
dbus-monitor --system |
while read -r line; do
if [[ $line =~ .*"poweroff.target".* ]]; then
kexec -l $kernel --initrd=$initrd --reuse-cmdline --append="wiperamexit=yes wiperamaction=poweroff"
break
fi
if systemctl list-jobs | grep "poweroff.target" | grep -q "start"; then
wram="yes"
wact="poweroff"
elif systemctl list-jobs | grep "reboot.target" | grep -q "start"; then
wram="yes"
wact="reboot"
elif systemctl list-jobs | grep "halt.target" | grep -q "start"; then
wram="yes"
wact="halt"
elif systemctl list-jobs | grep "kexec.target" | grep -q "start"; then
wram="yes"
wact="kexec"
else
echo "Error no shutdown option found!"
wram="yes"
wact="error"
fi
if [[ $line =~ .*"reboot.target".* ]]; then
kexec -l $kernel --initrd=$initrd --reuse-cmdline --append="wiperamexit=yes wiperamaction=reboot"
break
fi
if [[ $line =~ .*"halt.target".* ]]; then
kexec -l $kernel --initrd=$initrd --reuse-cmdline --append="wiperamexit=yes wiperamaction=halt"
break
fi
if [[ $line =~ .*"kexec.target".* ]]; then
kexec -l $kernel --initrd=$initrd --reuse-cmdline --append="wiperamexit=yes wiperamaction=reboot"
break
fi
done
kexec -l /boot/vmlinuz-$(uname -r) --initrd=/boot/initrd.img-$(uname -r) --reuse-cmdline --append="wiperamexit=$wram wiperamaction=$wact"