aboutsummaryrefslogtreecommitdiff
path: root/examples/shutdown-1.0/script/stop_storage
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-20 15:12:52 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-20 15:12:52 +0200
commitc21dfaf836cf0eb5317035bc20395c751a205934 (patch)
tree1b9b812eb0153da450a7f9f14fd444dc0bc4b567 /examples/shutdown-1.0/script/stop_storage
parente09c426456cfd030cc868d93bbcb2e0a6933cabb (diff)
downloadbusybox-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_storage')
-rwxr-xr-xexamples/shutdown-1.0/script/stop_storage81
1 files changed, 81 insertions, 0 deletions
diff --git a/examples/shutdown-1.0/script/stop_storage b/examples/shutdown-1.0/script/stop_storage
new file mode 100755
index 000000000..1be5f735b
--- /dev/null
+++ b/examples/shutdown-1.0/script/stop_storage
@@ -0,0 +1,81 @@
+#!/bin/sh
+# Do unmount/remount-ro. Wait.
+# KILL everybody. Wait.
+# Repeat.
+
+umountcnt=2
+writeout=0 # increase if your kernel doesn ot guarantee writes to complete
+
+# No /usr - we are expecting all binaries to be accessible
+# from root fs alone
+PATH=/sbin:/bin
+
+say() {
+ printf "\r%s\n\r" "$*"
+}
+
+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=$(( `say "$pslist" | wc -w` + 0 ))
+ if test x"$VERBOSE" = x; then
+ say "* `date '+%H:%M:%S'` $pscnt processes"
+ else
+ say "* `date '+%H:%M:%S'` Processes ($pscnt): $pslist"
+ fi
+}
+
+say "<*> `date '+%Y-%m-%d %H:%M:%S'` Executing '$0 $*'"
+
+showps
+
+i="$umountcnt"
+while test "$i" -gt 0; do
+ say "* `date '+%H:%M:%S'` Unmounting filesystems"
+ umount -a -n -r -f
+ # In case we unmounted proc...
+ test -e /proc/version || mount -t proc none /proc
+ # Remounting / RO isn't necessary when /etc/mtab is linked to /proc/mounts:
+ # already done. But let's be more paranoid here...
+ say "* `date '+%H:%M:%S'` Remounting root filesystem read-only"
+ mount -n -o remount,ro /
+ say "* `date '+%H:%M:%S'` Freeing loop devices"
+ for a in /dev/loop*; do
+ test -b "$a" && losetup -d "$a"
+ done
+ say "* `date '+%H:%M:%S'` Syncing"
+ sync
+ say "* `date '+%H:%M:%S'` Executing: killall5 -KILL"
+ killall5 -9
+ showps
+ i=$((i-1))
+done
+
+say "* `date '+%H:%M:%S'` Filesystem status (/proc/mounts)"
+cat /proc/mounts \
+| {
+ bad=false
+ while read dev mntpoint fstype opt n1 n2; do
+ case "$fstype" in
+ ( proc | sysfs | usbfs | devpts | rpc_pipefs | binfmt_misc | autofs | rootfs | tmpfs | ramfs )
+ say "$dev $mntpoint $fstype $opt $n1 $n2"
+ continue
+ ;;
+ esac
+ if test "${opt:0:2}" = "rw"; then
+ say "$dev $mntpoint $fstype $opt $n1 $n2 - RW!"
+ bad=true
+ else
+ say "$dev $mntpoint $fstype $opt $n1 $n2"
+ fi
+ done
+ if $bad; then
+ say "ERROR: we have filesystems mounted RW! Press <Enter> (^J)..."
+ read junk </dev/console
+ #sh </dev/console >&0 2>&0 # debug
+ fi
+}
+
+# Disk cache writeout
+sleep "$writeout"