]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/fshalt
f288786fb82f9d92eb874ac83d2cd1394fb9112b
[plan9front.git] / rc / bin / fshalt
1 #!/bin/rc
2 # fshalt [-r] - sync (flush) and, if possible, halt all file servers
3 #       and optionally reboot
4 rfork e
5 reboot=no
6 switch ($#*) {
7 case 0
8 case 1
9         reboot=yes
10 case *
11         echo usage: $0 '[-r]' >[1=2]
12         exit usage
13 }
14
15 path=(/bin)
16 builtin cd /
17
18 setrtc
19
20 # start venti flushing
21 venti/sync -h localhost >[2]/dev/null &
22 venti/sync  >[2]/dev/null &
23
24 unmount /mnt/consoles >[2]/dev/null
25 kill consolefs | rc                     # don't compete with /mnt/consoles
26 sleep 1
27
28 f=`{ls /srv/fscons*>[2]/dev/null}
29 k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
30
31 echo -n syncing...
32 for(i in $f) @ {
33         echo -n $i...
34         {
35                 echo
36                 dial/drain &
37                 sleep 2
38                 echo fsys all sync
39                 if(! dial/expect -t 120 ': ')
40                         echo -n 'not synced...' > /dev/cons
41         } < $i >> $i
42 }
43
44 # flush the last bit of possible fossil traffic
45 echo -n venti...
46 venti/sync -h localhost >[2]/dev/null &
47 venti/sync  >[2]/dev/null &
48 sleep 5
49
50 for (i in $k){
51         echo -n $i... 
52         switch($i){
53         case /srv/kfs.cmd
54                 disk/kfscmd sync
55         case *
56                 disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
57         }
58         sleep 2
59 }
60
61 # halting (binaries we run can't be on the fs we're halting)
62 ramfs
63 builtin cd /tmp
64 cp /bin/dial/expect /tmp
65 cp /bin/echo /tmp
66 cp /bin/disk/kfscmd /tmp
67 cp /bin/rc /tmp
68 cp /bin/sed /tmp
69 cp /bin/ns /tmp
70 cp /bin/iostats /tmp
71 mkdir /tmp/lib
72 cp /rc/lib/rcmain /tmp/lib
73 bind /tmp /rc
74 bind /tmp /bin
75
76 # put this in a shell function so this rc script doesn't get read
77 # when it's no longer accessible
78 fn x {
79         echo
80         echo -n halting...
81         for(i in $f) @ {
82                 echo -n $i...
83                 {
84                         echo fsys all halt
85                         if(! expect -t 60 ': ')
86                                 echo -n 'not halted...' > /dev/cons
87                 } < $i >> $i
88         }
89         
90         for (i in $k){
91                 echo -n $i... 
92                 switch($i){
93                 case /srv/kfs.cmd
94                         kfscmd halt
95                 case *
96                         kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
97                 }
98         }
99         echo
100         echo done halting
101
102         if (~ $reboot yes) {
103                 echo rebooting...
104                 echo reboot >'#c/reboot'
105         }
106 }
107
108 x