run_buildbot.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env bash
  2. set -x
  3. readonly BOT_ROOT=/b
  4. readonly BOT_ROOT_NAME=$1
  5. readonly BOT_PASS=$2
  6. #pushd /tmp
  7. #curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
  8. #bash install-monitoring-agent.sh
  9. #curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
  10. #bash install-logging-agent.sh --structured
  11. #popd
  12. apt-get update -y
  13. apt-get upgrade -y
  14. apt-get install sudo -y
  15. systemctl set-property buildslave.service TasksMax=100000
  16. function setup_numbered_bot() {
  17. local BOT_NAME=$1
  18. local BOT_DIR=$2
  19. mkdir -p $BOT_DIR
  20. buildslave stop $BOT_DIR
  21. chown buildbot:buildbot $BOT_DIR
  22. rm -rf $BOT_DIR/*
  23. buildslave create-slave --allow-shutdown=signal "$BOT_DIR" "lab.llvm.org:9990" "$BOT_NAME" "$BOT_PASS"
  24. echo "Eric Fiselier <ericwf@google.com>" > $BOT_DIR/info/admin
  25. echo "Connecting as $1"
  26. {
  27. uname -a | head -n1
  28. cmake --version | head -n1
  29. g++ --version | head -n1
  30. ld --version | head -n1
  31. date
  32. lscpu
  33. } > $BOT_DIR/info/host
  34. #echo "SLAVE_RUNNER=/usr/bin/buildslave
  35. #SLAVE_ENABLED[1]=\"1\"
  36. #SLAVE_NAME[1]=\"$BOT_NAME\"
  37. #SLAVE_USER[1]=\"buildbot\"
  38. #SLAVE_BASEDIR[1]=\"$BOT_DIR\"
  39. #SLAVE_OPTIONS[1]=\"\"
  40. #SLAVE_PREFIXCMD[1]=\"\"" > $BOT_DIR/buildslave.cfg
  41. ls $BOT_DIR/
  42. cat $BOT_DIR/buildbot.tac
  43. }
  44. function try_start_builder {
  45. local N=$1
  46. local BOT_DIR="$BOT_ROOT/b$N"
  47. local BOT_NAME="$BOT_ROOT_NAME$N"
  48. systemctl daemon-reload
  49. service buildslave restart
  50. setup_numbered_bot "$BOT_NAME" "$BOT_DIR"
  51. systemctl daemon-reload
  52. service buildslave restart
  53. chown -R buildbot:buildbot $BOT_DIR/
  54. sudo -u buildbot /usr/bin/buildslave start $BOT_DIR/
  55. sleep 30
  56. cat $BOT_DIR/twistd.log
  57. if grep --quiet "slave is ready" $BOT_DIR/twistd.log; then
  58. return 0
  59. fi
  60. if grep --quiet "configuration update complete" $BOT_DIR/twistd.log; then
  61. return 0
  62. fi
  63. if grep "rejecting duplicate slave" $BOT_DIR/twistd.log; then
  64. return 1
  65. fi
  66. echo "Unknown error"
  67. cat $BOT_DIR/twistd.log
  68. exit 1
  69. }
  70. for N in `shuf -i 1-5`
  71. do
  72. if try_start_builder $N; then
  73. break
  74. fi
  75. echo "failed to start any buildbot"
  76. shutdown now
  77. done
  78. # GCE can restart instance after 24h in the middle of the build.
  79. # Gracefully restart before that happen.
  80. sleep 72000
  81. while pkill -SIGHUP buildslave; do sleep 5; done;
  82. shutdown now