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