summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2020-05-21 09:37:59 +0200
committerErich Eckner <git@eckner.net>2020-05-21 09:37:59 +0200
commit2591fa5313bbeaf88d0a7c57706d764d5bf2e188 (patch)
treed9f49a7a12bced13f31e6aa1d203354f02c59ce9
parentd95437df15eb77b4819fef3ec04cda2618f65e28 (diff)
downloadshutdownasap-2591fa5313bbeaf88d0a7c57706d764d5bf2e188.tar.xz
use tmpDir for inter-instance communication - now we can change the target (reboot/shutdown) or even abort cleanly
-rw-r--r--shutdownasap.1.in4
-rwxr-xr-xshutdownasap.conf.in4
-rwxr-xr-xshutdownasap.in45
3 files changed, 38 insertions, 15 deletions
diff --git a/shutdownasap.1.in b/shutdownasap.1.in
index 51c804c..65ee4af 100644
--- a/shutdownasap.1.in
+++ b/shutdownasap.1.in
@@ -15,8 +15,8 @@ For actually shutting down it calls \fBsudo shutdown\fP or \fBsudo reboot\fP for
.SH CONFIGURATION
The configfile \fB#ETCDIR#/shutdownasap.conf\fP is a bash script, which defines the following variables and routines:
.TP
-.B "pidFile"
-file to store pid in
+.B "tmpDir"
+shared run-time directory for all instances
.TP
.B "waitForDir"
directory which must be empty before shutting down
diff --git a/shutdownasap.conf.in b/shutdownasap.conf.in
index 780dafa..d04d3ea 100755
--- a/shutdownasap.conf.in
+++ b/shutdownasap.conf.in
@@ -3,8 +3,8 @@
# configuration file for shutdownasap
# it should be named #ETCDIR#/shutdownasap.conf
-# shutdownasap's pid
-pidFile="/tmp/shutdownasap.pid"
+# directory for inter-instance communication, etc.
+tmpDir="/tmp/tmp.shutdownasap"
# directory must be empty before shutdown
waitForDir="/home/shutdown/.warteauf"
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}"