Debian Codegraph @

examples/shutdown-1.0/script/stop_tasks

raw symbols SCIP
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
7 killcnt=30
8
9 PATH=/sbin:/usr/sbin:/bin:/usr/bin
10
11 echo "<*> `date '+%Y-%m-%d %H:%M:%S'` Executing '$0 $*'"
12
13 showps() {
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.
31 sync &
32
33 # Send SIGTERMs. If list of processes changes, proceed slower.
34 # If it has stabilised (all who wanted to, exited), proceed faster.
35 showps
36 i="$killcnt"
37 while 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))
51 done
52
53 echo "* `date '+%H:%M:%S'` Turning off swap"
54 swapoff -a
55 cat /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 }
61 done
62
63 echo "* /proc/swaps:"
64 cat /proc/swaps
65 echo "* /proc/mounts:"
66 cat /proc/mounts
67 echo "* ps -A e:"
68 ps -A e
69 echo "* top -bn1:"
70 top -bn1