1#!/bin/sh 2# We are trying to be nice. 3# TERM everybody. Give them some time to die. 4# KILL might make some filesystems non-unmountable, 5# so we'll do it in stop_storage instead. 6 7killcnt=30 8 9PATH=/sbin:/usr/sbin:/bin:/usr/bin 10 11echo "<*> `date '+%Y-%m-%d %H:%M:%S'` Executing '$0 $*'" 12 13showps() { 14 # sleep 1 ensures that xargs will have time to start up. 15 # This makes pslist less prone to random jitter. 16 pslist=`{ sleep 1; ps -A -o comm=; } | sort | xargs` 17 pscnt=$(( `echo "$pslist" | wc -w` + 0 )) 18 if test x"$VERBOSE" = x; then 19 echo "* `date '+%H:%M:%S'` $pscnt processes" 20 else 21 echo "* `date '+%H:%M:%S'` Processes ($pscnt): $pslist" 22 fi 23} 24 25# Sync. 26# Rationale: sometimes buggy root processes can 27# hang the system when killed (X for example may have problems 28# with restoring text mode on a poorly supported hardware). 29# These are bugs and must be fixed, but until then users will lose 30# dirty data on shutdown! Let's make that less likely. 31sync & 32 33# Send SIGTERMs. If list of processes changes, proceed slower. 34# If it has stabilised (all who wanted to, exited), proceed faster. 35showps 36i="$killcnt" 37while test "$i" -gt 0; do 38 echo "* `date '+%H:%M:%S'` Sending CONT, TERM" #, HUP" 39 # I've seen "killall5 2.86" which doesn't grok signal names! 40 killall5 -18 41 killall5 -15 42 #killall5 -1 # HUP: because interactive bash does not die on TERM... 43 # but init will reread /etc/inittab on HUP and my /etc is on non root fs! 44 # -> umounts will complain. 45 oldpslist="$pslist" 46 showps 47 if test x"$pslist" = x"$oldpslist"; then 48 i=$((i-8)) 49 fi 50 i=$((i-2)) 51done 52 53echo "* `date '+%H:%M:%S'` Turning off swap" 54swapoff -a 55cat /proc/swaps | grep -v ^Filename | cut -d ' ' -f1 \ 56| while read -r line; do 57 test "$line" && { 58 echo swapoff "$line" 59 swapoff "$line" 60 } 61done 62 63echo "* /proc/swaps:" 64cat /proc/swaps 65echo "* /proc/mounts:" 66cat /proc/mounts 67echo "* ps -A e:" 68ps -A e 69echo "* top -bn1:" 70top -bn1 71