Debian Codegraph @

examples/shutdown-1.0/script/do_shutdown

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # We are called with stdin/out/err = /dev/null
3
4 resetgracetime=60
5
6 logfile="/var/log/reboot/`datescip-shell system . . date. '+%Y%m%d%H%M%S'`.log"
7 mkdirscip-shell system . . mkdir. -p /var/log/rebootscip-shell filesystem . . `/var/log/reboot`.
8
9 PATH=/sbin:/binscip-shell filesystem . . `/sbin:/bin`.
10
11 sayscip-shell shell shell-project 0.0.0 say().() {
12 printfscip-shell system . . printf. "\r%s\n\r" "$*"
13 }
14
15 # Since there is a potential for various fuckups during umount,
16 # we start delayed hard reboot here which will forcibly
17 # reboot hung box in a remote datacenter a thousand miles away ;)
18 if testscip-shell system . . test. "$1" = "-r"; then
19 ./hardshutdown -r "$resetgracetime" &
20 fi
21
22 # Now, (try to) switch away from X and open a console. I've seen reboots
23 # hung on open("/dev/console"), therefore we do it _after_ hardshutdown
24 exec >/dev/consolescip-shell filesystem . . `/dev/console`. 2>&1
25
26 if testscip-shell system . . test. "$1" = "-r"; then
27 sayscip-shell shell shell-project 0.0.0 say(). "* `datescip-shell system . . date. '+%H:%M:%S'` Scheduled hard reboot in $resetgracetime seconds"
28 fi
29
30 sayscip-shell shell shell-project 0.0.0 say(). "* `datescip-shell system . . date. '+%H:%M:%S'` Stopping tasks (see /var/log/reboot/* files)"
31 # log reboot event to file. %Y%m%d%H%M%S: YYYYMMDDHHMMSS
32 ./stop_tasks >"$logfile" 2>&1
33
34 # Dying X tends to leave us at semi-random vt. Try to fix that,
35 # but if it doesn't work, proceed anyway.
36 exec >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
37 chvt 1 & sleepscip-shell system . . sleep. 1
38 exec >/dev/consolescip-shell filesystem . . `/dev/console`. 2>&1
39
40 command -v ctrlaltdel >/dev/nullscip-shell filesystem . . `/dev/null`. && {
41 sayscip-shell shell shell-project 0.0.0 say(). "* `datescip-shell system . . date. '+%H:%M:%S'` Setting Ctrl-Alt-Del to 'hard'"
42 ctrlaltdel hard
43 }
44
45 sayscip-shell shell shell-project 0.0.0 say(). "* `datescip-shell system . . date. '+%H:%M:%S'` Stopping storage devices"
46 # we can't log this: we are about to unmount everything!
47 ./stop_storage "$@"
48
49 # If we have cmdline params, start hardshutdown with them
50 testscip-shell system . . test. "$*" && ./hardshutdown "$@"
51
52 # Just sleep endlessly...
53 sayscip-shell shell shell-project 0.0.0 say(). "* `datescip-shell system . . date. '+%H:%M:%S'` You may now power off or press Ctrl-Alt-Del to reboot"
54 while truescip-shell system . . true.; do sleepscip-shell system . . sleep. 32000; done