| 1 | #!/bin/sh |
| 2 | # We are called with stdin/out/err = /dev/null |
| 3 | |
| 4 | resetgracetime=60 |
| 5 | |
| 6 | logfile="/var/log/reboot/`date '+%Y%m%d%H%M%S'`.log" |
| 7 | mkdir -p /var/log/reboot |
| 8 | |
| 9 | PATH=/sbin:/bin |
| 10 | |
| 11 | say() { |
| 12 | 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 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/console 2>&1 |
| 25 | |
| 26 | if test "$1" = "-r"; then |
| 27 | say "* `date '+%H:%M:%S'` Scheduled hard reboot in $resetgracetime seconds" |
| 28 | fi |
| 29 | |
| 30 | say "* `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/null 2>&1 |
| 37 | chvt 1 & sleep 1 |
| 38 | exec >/dev/console 2>&1 |
| 39 | |
| 40 | command -v ctrlaltdel >/dev/null && { |
| 41 | say "* `date '+%H:%M:%S'` Setting Ctrl-Alt-Del to 'hard'" |
| 42 | ctrlaltdel hard |
| 43 | } |
| 44 | |
| 45 | say "* `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 | test "$*" && ./hardshutdown "$@" |
| 51 | |
| 52 | # Just sleep endlessly... |
| 53 | say "* `date '+%H:%M:%S'` You may now power off or press Ctrl-Alt-Del to reboot" |
| 54 | while true; do sleep 32000; done |