]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/fshalt
inst: default dist location to /, use old cache format by default... will change...
[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 c=`{ls /srv/cwfs*cmd >[2]/dev/null}
31
32 echo -n syncing...
33 for(i in $f) @ {
34         echo -n $i...
35         {
36                 echo
37                 dial/drain &
38                 sleep 2
39                 echo fsys all sync
40                 if(! dial/expect -t 120 ': ')
41                         echo -n 'not synced...' > /dev/cons
42         } < $i >> $i
43 }
44
45 # flush the last bit of possible fossil traffic
46 echo -n venti...
47 venti/sync -h localhost >[2]/dev/null &
48 venti/sync  >[2]/dev/null &
49 sleep 5
50
51 for (i in $k){
52         echo -n $i... 
53         switch($i){
54         case /srv/kfs.cmd
55                 disk/kfscmd sync
56         case *
57                 disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
58         }
59         sleep 2
60 }
61
62 for (i in $c){
63         echo -n $i...
64         echo halt >>$i
65         sleep 2
66 }
67
68 # halting (binaries we run can't be on the fs we're halting)
69 ramfs
70 builtin cd /tmp
71 cp /bin/dial/expect /tmp
72 cp /bin/echo /tmp
73 cp /bin/disk/kfscmd /tmp
74 cp /bin/rc /tmp
75 cp /bin/sed /tmp
76 cp /bin/ns /tmp
77 cp /bin/iostats /tmp
78 mkdir /tmp/lib
79 cp /rc/lib/rcmain /tmp/lib
80 bind /tmp /rc
81 bind /tmp /bin
82
83 # put this in a shell function so this rc script doesn't get read
84 # when it's no longer accessible
85 fn x {
86         echo
87         echo -n halting...
88         for(i in $f) @ {
89                 echo -n $i...
90                 {
91                         echo fsys all halt
92                         if(! expect -t 60 ': ')
93                                 echo -n 'not halted...' > /dev/cons
94                 } < $i >> $i
95         }
96         
97         for (i in $k){
98                 echo -n $i... 
99                 switch($i){
100                 case /srv/kfs.cmd
101                         kfscmd halt
102                 case *
103                         kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
104                 }
105         }
106         echo
107         echo done halting
108
109         if (~ $reboot yes) {
110                 echo rebooting...
111                 echo reboot >'#c/reboot'
112         }
113 }
114
115 x