fshalt 1.8 KB

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