diff options
author | Erich Eckner <git@eckner.net> | 2020-05-21 09:37:59 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2020-05-21 09:37:59 +0200 |
commit | 2591fa5313bbeaf88d0a7c57706d764d5bf2e188 (patch) | |
tree | d9f49a7a12bced13f31e6aa1d203354f02c59ce9 /shutdownasap.in | |
parent | d95437df15eb77b4819fef3ec04cda2618f65e28 (diff) | |
download | shutdownasap-2591fa5313bbeaf88d0a7c57706d764d5bf2e188.tar.xz |
use tmpDir for inter-instance communication - now we can change the target (reboot/shutdown) or even abort cleanly
Diffstat (limited to 'shutdownasap.in')
-rwxr-xr-x | shutdownasap.in | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/shutdownasap.in b/shutdownasap.in index a32f92d..d2d471f 100755 --- a/shutdownasap.in +++ b/shutdownasap.in @@ -6,28 +6,39 @@ set -e . #ETCDIR#/shutdownasap.conf -[ -r "${pidFile}" ] && ps aux | grep -q "^\S\+\s\+$(cat "${pidFile}") " && exit - -echo $$ > "${pidFile}" +mkdir -p "${tmpDir}" quiet=false -reboot=false +intentionSet=false while [ $# -gt 0 ]; do case "$1" in + '-a') + echo 'none' >"${tmpDir}/intention" + exit + ;; '-q') quiet=true ;; '-r') - reboot=true + echo 'reboot' >"${tmpDir}/intention" + intentionSet=true ;; *) - >&2 echo 'usage: shutdownasap [-q] [-r]' + >&2 echo 'usage: shutdownasap [-q] [-a|-r]' exit 1 ;; esac shift done +if ! ${intentionSet}; then + echo 'shutdown' >"${tmpDir}/intention" +fi + +[ -r "${tmpDir}/pid" ] && kill -0 "$(cat "${tmpDir}/pid")" && exit + +echo $$ > "${tmpDir}/pid" + beforeWatchHook i=1 @@ -130,8 +141,20 @@ else pre='' fi -if ${reboot}; then - ${pre} /sbin/reboot -else - ${pre} /sbin/poweroff -fi +case "$(head -n1 "${tmpDir}/intention")" in + 'reboot') + ${pre} /sbin/reboot + ;; + 'shutdown') + ${pre} /sbin/poweroff + ;; + 'none') + echo 'shutdown was aborted' + ;; + *) + printf 'intention "%s" not implemented\n' "$(head -n1 "${tmpDir}/intention")" + exit 1 + ;; +esac + +rm -rf --one-file-system "${tmpDir}" |