blob: 448e6d57e382a3f4638b611224dd97496f1f7c1c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/bin/sh
# shutdown - shutdown(8) lookalike for runit
single() {
runsvchdir single
}
abort() {
echo "$@" >&2
exit 1
}
usage() {
abort "Usage: shutdown [-fF] [-kchPr] time [warning message]"
}
action=single
while getopts akrhPHfFnct: opt; do
case "$opt" in
a|n|H) abort "-$opt is not implemented";;
t) ;;
f) touch /fastboot;;
F) touch /forcefsck;;
k) action=true;;
c) action=cancel;;
h|P) action=halt;;
r) action=reboot;;
[?]) usage;;
esac
done
shift $(expr $OPTIND - 1)
[ $# -eq 0 ] && usage
time=$1; shift
message="${*:-system is going down}"
if [ "$action" = "cancel" ]; then
kill $(cat /run/runit/shutdown.pid)
echo "${*:-shutdown cancelled}" | wall
exit
fi
if ! touch /run/runit/shutdown.pid 2>/dev/null; then
abort "Not enough permissions to execute ${0#*/}"
fi
echo $$ >/run/runit/shutdown.pid
case "$time" in
now) time=0;;
+*) time=${time#+};;
*:*) abort "absolute time is not implemented";;
*) abort "invalid time";;
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
|