summaryrefslogtreecommitdiff
path: root/rc/bin/fshalt
blob: ad3dc52c8c05cd71d0c6ab809075d972dd4da39d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/rc
# fshalt [-r] - sync (flush) and, if possible, halt all file servers
#	and optionally reboot
rfork e
reboot=no
switch ($#*) {
case 0
case 1
	reboot=yes
case *
	echo usage: $0 '[-r]' >[1=2]
	exit usage
}

path=(/bin)
builtin cd /

unmount /mnt/consoles >[2]/dev/null
kill consolefs | rc			# don't compete with /mnt/consoles
sleep 1

k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
c=`{ls /srv/cwfs*cmd >[2]/dev/null}

for (i in $k){
	echo -n $i... 
	switch($i){
	case /srv/kfs.cmd
		disk/kfscmd sync
	case *
		disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
	}
	sleep 2
}

# halting (binaries we run can't be on the fs we're halting)
ramfs
builtin cd /tmp
cp /bin/dial/expect /tmp
cp /bin/disk/kfscmd /tmp
cp /bin/echo /tmp
cp /bin/iostats /tmp
mkdir /tmp/lib
cp /rc/lib/rcmain /tmp/lib
cp /bin/ns /tmp
cp /bin/rc /tmp
cp /bin/sed /tmp
cp /bin/sleep /tmp
cp /bin/scram /tmp
bind /tmp /rc
bind /tmp /bin

# put this in a shell function so this rc script doesn't get read
# when it's no longer accessible
fn x {
	echo
	echo -n halting...
	for (i in $k){
		echo -n $i... 
		switch($i){
		case /srv/kfs.cmd
			kfscmd halt
		case *
			kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
		}
	}
	for (i in $c){
		echo -n $i...
		echo halt >>$i
		sleep 2
	}
	echo
	echo done halting

	if (~ $reboot yes) {
		echo rebooting...
		echo reboot >'#c/reboot'
	}
	if not scram
}

x