fshalt 1.3 KB

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