fshalt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 fsys all sync
  13. if(! dial/expect -qt 120 ': ')
  14. echo -n 'not synced...' > /dev/cons
  15. } < $i >> $i
  16. }
  17. echo -n venti...
  18. venti/sync >[2]/dev/null
  19. for (i in $k){
  20. echo -n $i...
  21. switch($i){
  22. case /srv/kfs.cmd
  23. disk/kfscmd sync
  24. case *
  25. disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
  26. }
  27. sleep 2
  28. }
  29. # halting (binaries we run can't be on the fs we're halting)
  30. ramfs
  31. builtin cd /tmp
  32. cp /bin/dial/expect /tmp
  33. cp /bin/echo /tmp
  34. cp /bin/disk/kfscmd /tmp
  35. cp /bin/rc /tmp
  36. cp /bin/sed /tmp
  37. bind /tmp /bin
  38. echo
  39. echo -n halting...
  40. for(i in $f){
  41. echo -n $i...
  42. {
  43. echo fsys all halt
  44. if(! expect -qt 120 ': ')
  45. echo -n 'not halted...' > /dev/cons
  46. } < $i >> $i
  47. }
  48. for (i in $k){
  49. echo -n $i...
  50. switch($i){
  51. case /srv/kfs.cmd
  52. kfscmd halt
  53. case *
  54. kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
  55. }
  56. }
  57. echo
  58. echo done