more init fixes
[hdw-linux/hdw-linux.git] / misc / sysfiles / etc / init.d / down
1 #!/bin/sh
2 #
3 # hdw - linux /etc/init.d/down (copied from ROCK Linux)
4 #
5 # shutdown and reboot script.
6 #
7
8 exec 2>&1
9
10 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
11
12 case "$1" in
13         *halt)   command=halt   ;;
14         *reboot) command=reboot ;;
15         *)       echo "never call this script directly !" ; exit 1 ;;
16 esac
17
18 touch /var/log/init.msg /var/log/boot.msg
19 mv /var/log/init.msg /var/log/init.old
20 mv /var/log/boot.msg /var/log/boot.old
21
22 echo "** shutting down hdw-linux **"
23
24 . /etc/conf/bootdown
25 [ -f /fastdown ] && FASTDOWN=1
26 [ $FASTDOWN = 1 ] && echo "fast shutdown mode enabled."
27
28 echo "writing a wtmp record ..."
29 $command -w 
30
31 echo "saving kernel random seed ..."
32 dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null
33
34 if [ $FASTDOWN = 1 ]
35 then
36         echo "sending all processes a SIGTERM (15) ..."
37         killall5 -15 ; sleep 3
38         echo "sending all processes a SIGKILL (9) ..."
39         killall5 -9 ; sleep 2
40 else
41         echo "sending all processes a SIGTERM (15) ..."
42         killall5 -15 ; sleep 5
43         echo "sending all processes a 2nd SIGTERM (15) ..."
44         killall5 -15 ; sleep 3
45         echo "sending all processes a SIGKILL (9) ..."
46         killall5 -9 ; sleep 3
47         echo "sending all processes a 2nd SIGKILL (9) ..."
48         killall5 -9 ; sleep 3
49 fi
50
51 echo "turning off swap ..."
52 swapoff -a ; sync ; sleep 1
53
54 if [ $FASTDOWN = 1 ]
55 then
56         echo "unmounting file systems ..."
57         umount -vnra -t noproc,devfs,shm
58         mount -vn -o remount,ro /
59         sleep 1 ; sync ; sleep 1
60 else
61         echo "remounting sync/ro and umount filesystems ..."
62         grep -v '^none ' /etc/mtab /proc/mounts | grep -v ' / ' | \
63         cut -f1,2 -d' ' | sort -u -k2 -t' ' | sort -r -k2 -t' ' | \
64         while read dev fs ; do
65                 echo -n "$dev on $fs: sync" ; mount -o remount,sync $fs
66                 echo -n " ro"  ; mount -o remount,ro $fs
67                 echo " umount" ; umount $fs
68         done
69
70         echo "shutting down udev ..."
71         /etc/init.d/udev stop
72         umount /dev/pts ; rm -rf /dev/pts
73         umount /dev/shm ; rm -rf /dev/shm
74         umount /dev
75
76         echo "unmounting remaining file systems ..."
77         sync ; sleep 1 ; sync
78         grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab
79         umount -vnra -t noproc,devfs,shm
80         mount -vn -o remount,sync /
81         mount -vn -o remount,ro /
82         sleep 1 ; sync ; sleep 1
83 fi
84
85 echo "going to $command the system ..."
86 exec $command -d -f -i -p