diff options
author | Juan RP <xtraeme@gmail.com> | 2014-04-26 10:42:57 +0200 |
---|---|---|
committer | Juan RP <xtraeme@gmail.com> | 2014-04-26 10:42:57 +0200 |
commit | f69bd705f46b3082f06abcec2d8e6b6c4d291b9e (patch) | |
tree | 427079005904590751227e3508a984415e8f711c | |
parent | 42c0aa02d58c30e64295035a4602fec30e0f3916 (diff) | |
download | runit-void-f69bd705f46b3082f06abcec2d8e6b6c4d291b9e.tar.gz runit-void-f69bd705f46b3082f06abcec2d8e6b6c4d291b9e.tar.xz runit-void-f69bd705f46b3082f06abcec2d8e6b6c4d291b9e.zip |
Added shutdown script from ignite.
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | shutdown.sh | 65 |
2 files changed, 66 insertions, 0 deletions
diff --git a/Makefile b/Makefile index 647b468..faddc96 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ install: install -d ${DESTDIR}/${PREFIX}/bin install -m755 halt ${DESTDIR}/${PREFIX}/bin install -m755 pause ${DESTDIR}/${PREFIX}/bin + install -m755 shutdown.sh ${DESTDIR}/${PREFIX}/bin/shutdown ln -s halt ${DESTDIR}/${PREFIX}/bin/poweroff ln -s halt ${DESTDIR}/${PREFIX}/bin/reboot install -d ${DESTDIR}/${PREFIX}/share/man/man1 diff --git a/shutdown.sh b/shutdown.sh new file mode 100644 index 0000000..d5cc4b7 --- /dev/null +++ b/shutdown.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# shutdown - shutdown(8) lookalike for runit + +single() { + runsvchdir single +} + +action=single + +while getopts akrhPHfFnct: opt; do + case "$opt" in + a|n|H) echo "-$opt is not implemented" >/dev/stderr; exit 1;; + t) ;; + + f) touch /fastboot;; + F) touch /forcefsck;; + + k) action=true;; + c) action=cancel;; + h|P) action=halt;; + r) action=reboot;; + + [?]) echo "Usage: shutdown [-fF] [-kchPr] time [warning message]" >/dev/stderr; exit 1;; + esac +done +shift $(expr $OPTIND - 1) + +time=$1; shift +message="${*:-system is going down}" + +if [ "$action" = "cancel" ]; then + kill $(cat /run/runit/shutdown.pid) + echo "${*:-shutdown cancelled}" | wall + exit +fi + +echo $$ >/run/runit/shutdown.pid + +case "$time" in + now) time=0;; + +*) time=${time#+};; + *:*) echo "absolute time is not implemented" >/dev/stderr; exit 1;; + *) echo "invalid time"; exit 1;; +esac + +if [ "$time" -gt 5 ]; then + echo "$message in $time minutes" | wall + echo -n "shutdown: sleeping for $time minutes... " + sleep $(expr '(' "$time" - 5 ')' '*' 60) + echo + time=5 +fi + +if [ "$time" -gt 0 ]; then + echo "$message in $time minutes" | wall + touch /etc/nologin + echo -n "shutdown: sleeping for $time minutes... " + sleep $(expr "$time" '*' 60) + echo + rm /etc/nologin +fi + +echo "$message NOW" | wall + +$action |