setup.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/sh -e
  2. LINE="---------------"
  3. start() {
  4. if [ -d _harness ]; then
  5. echo "Daemon setup already in place, stop it first."
  6. exit 1
  7. fi
  8. mkdir -p _harness
  9. cd _harness
  10. cp -a ../harness/daemons .
  11. cp -a ../harness/certs .
  12. echo keyfile > certs/keyfile
  13. chmod 600 certs/keyfile
  14. if ! mongod --help | grep -q -- --ssl; then
  15. rm -rf daemons/db3
  16. fi
  17. COUNT=$(ls daemons | wc -l)
  18. echo "Running daemons..."
  19. svscan daemons &
  20. SVSCANPID=$!
  21. echo $SVSCANPID > svscan.pid
  22. if ! kill -0 $SVSCANPID; then
  23. echo "Cannot execute svscan."
  24. exit 1
  25. fi
  26. echo "Starting $COUNT processes..."
  27. for i in $(seq 30); do
  28. UP=$(svstat daemons/* | grep ' up ' | grep -v ' [0-3] seconds' | wc -l)
  29. echo "$UP processes up..."
  30. if [ x$COUNT = x$UP ]; then
  31. echo "Running setup.js with mongo..."
  32. mongo --nodb ../harness/mongojs/init.js
  33. exit 0
  34. fi
  35. sleep 1
  36. done
  37. echo "Failed to start processes. svstat _harness/daemons/* output:"
  38. echo $LINE
  39. svstat daemons/*
  40. echo $LINE
  41. for DAEMON in daemons/*; do
  42. if $(svstat $DAEMON | grep ' up ' | grep ' [0-3] seconds' > /dev/null); then
  43. echo "Logs for _harness/$DAEMON:"
  44. echo $LINE
  45. cat $DAEMON/log/log.txt
  46. echo $LINE
  47. fi
  48. done
  49. exit 1
  50. }
  51. stop() {
  52. if [ -d _harness ]; then
  53. cd _harness
  54. if [ -f svscan.pid ]; then
  55. kill -9 $(cat svscan.pid) 2> /dev/null || true
  56. svc -dx daemons/* daemons/*/log > /dev/null 2>&1 || true
  57. COUNT=$(ls daemons | wc -l)
  58. echo "Shutting down $COUNT processes..."
  59. while true; do
  60. DOWN=$(svstat daemons/* | grep 'supervise not running' | wc -l)
  61. echo "$DOWN processes down..."
  62. if [ x$DOWN = x$COUNT ]; then
  63. break
  64. fi
  65. sleep 1
  66. done
  67. rm svscan.pid
  68. echo "Done."
  69. fi
  70. cd ..
  71. rm -rf _harness
  72. fi
  73. }
  74. if [ ! -f suite_test.go ]; then
  75. echo "This script must be run from within the source directory."
  76. exit 1
  77. fi
  78. case "$1" in
  79. start)
  80. start $2
  81. ;;
  82. stop)
  83. stop $2
  84. ;;
  85. esac
  86. # vim:ts=4:sw=4:et