diff options
author | Denys Vlasenko | 2018-04-20 15:12:52 +0200 |
---|---|---|
committer | Denys Vlasenko | 2018-04-20 15:12:52 +0200 |
commit | c21dfaf836cf0eb5317035bc20395c751a205934 (patch) | |
tree | 1b9b812eb0153da450a7f9f14fd444dc0bc4b567 /examples/shutdown-1.0/script/stop_tasks | |
parent | e09c426456cfd030cc868d93bbcb2e0a6933cabb (diff) | |
download | busybox-c21dfaf836cf0eb5317035bc20395c751a205934.zip busybox-c21dfaf836cf0eb5317035bc20395c751a205934.tar.gz |
examples/shutdown-1.0: an example of reboot which does not signal init
For one, my inits know nothing about the concept of "shutting down the system".
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'examples/shutdown-1.0/script/stop_tasks')
-rwxr-xr-x | examples/shutdown-1.0/script/stop_tasks | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/examples/shutdown-1.0/script/stop_tasks b/examples/shutdown-1.0/script/stop_tasks new file mode 100755 index 0000000..2d752a3 --- /dev/null +++ b/examples/shutdown-1.0/script/stop_tasks @@ -0,0 +1,70 @@ +#!/bin/sh +# We are trying to be nice. +# TERM everybody. Give them some time to die. +# KILL might make some filesystems non-unmountable, +# so we'll do it in stop_storage instead. + +killcnt=30 + +PATH=/sbin:/usr/sbin:/bin:/usr/bin + +echo "<*> `date '+%Y-%m-%d %H:%M:%S'` Executing '$0 $*'" + +showps() { + # sleep 1 ensures that xargs will have time to start up. + # This makes pslist less prone to random jitter. + pslist=`{ sleep 1; ps -A -o comm=; } | sort | xargs` + pscnt=$(( `echo "$pslist" | wc -w` + 0 )) + if test x"$VERBOSE" = x; then + echo "* `date '+%H:%M:%S'` $pscnt processes" + else + echo "* `date '+%H:%M:%S'` Processes ($pscnt): $pslist" + fi +} + +# Sync. +# Rationale: sometimes buggy root processes can +# hang the system when killed (X for example may have problems +# with restoring text mode on a poorly supported hardware). +# These are bugs and must be fixed, but until then users will lose +# dirty data on shutdown! Let's make that less likely. +sync & + +# Send SIGTERMs. If list of processes changes, proceed slower. +# If it has stabilised (all who wanted to, exited), proceed faster. +showps +i="$killcnt" +while test "$i" -gt 0; do + echo "* `date '+%H:%M:%S'` Sending CONT, TERM" #, HUP" + # I've seen "killall5 2.86" which doesn't grok signal names! + killall5 -18 + killall5 -15 + #killall5 -1 # HUP: because interactive bash does not die on TERM... + # but init will reread /etc/inittab on HUP and my /etc is on non root fs! + # -> umounts will complain. + oldpslist="$pslist" + showps + if test x"$pslist" = x"$oldpslist"; then + i=$((i-8)) + fi + i=$((i-2)) +done + +echo "* `date '+%H:%M:%S'` Turning off swap" +swapoff -a +cat /proc/swaps | grep -v ^Filename | cut -d ' ' -f1 \ +| while read -r line; do + test "$line" && { + echo swapoff "$line" + swapoff "$line" + } +done + +echo "* /proc/swaps:" +cat /proc/swaps +echo "* /proc/mounts:" +cat /proc/mounts +echo "* ps -A e:" +ps -A e +echo "* top -bn1:" +top -bn1 |