fshalt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/rc
  2. # halt - sync (flush) and, if possible, halt all file servers
  3. rfork e
  4. path=(/bin)
  5. builtin cd /
  6. kill consolefs | rc # don't compete with /mnt/consoles
  7. sleep 1
  8. f=`{ls /srv/fscons*>[2]/dev/null}
  9. k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
  10. echo -n syncing...
  11. for(i in $f){
  12. echo -n $i...
  13. {
  14. echo
  15. dial/drain
  16. echo fsys all sync
  17. if(! dial/expect -t 120 ': ')
  18. echo -n 'not synced...' > /dev/cons
  19. } < $i >> $i
  20. }
  21. echo -n venti...
  22. venti/sync >[2]/dev/null
  23. for (i in $k){
  24. echo -n $i...
  25. switch($i){
  26. case /srv/kfs.cmd
  27. disk/kfscmd sync
  28. case *
  29. disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
  30. }
  31. sleep 2
  32. }
  33. # halting (binaries we run can't be on the fs we're halting)
  34. ramfs
  35. builtin cd /tmp
  36. cp /bin/dial/expect /tmp
  37. cp /bin/echo /tmp
  38. cp /bin/disk/kfscmd /tmp
  39. cp /bin/rc /tmp
  40. cp /bin/sed /tmp
  41. cp /bin/ns /tmp
  42. cp /bin/iostats /tmp
  43. mkdir /tmp/lib
  44. cp /rc/lib/rcmain /tmp/lib
  45. bind /tmp /rc
  46. bind /tmp /bin
  47. # put this in a shell function so this rc script doesn't get read
  48. # when it's no longer accessible
  49. fn x {
  50. echo
  51. echo -n halting...
  52. for(i in $f){
  53. echo -n $i...
  54. {
  55. echo fsys all halt
  56. if(! expect -t 60 ': ')
  57. echo -n 'not halted...' > /dev/cons
  58. } < $i >> $i
  59. }
  60. for (i in $k){
  61. echo -n $i...
  62. switch($i){
  63. case /srv/kfs.cmd
  64. kfscmd halt
  65. case *
  66. kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
  67. }
  68. }
  69. echo
  70. echo done
  71. }
  72. x