| #!/bin/bash |
| |
| # Found as /opt/start_swarming. Called by /etc/init.d/start-swarming so it can be run |
| # as user chrome-bot (swarming doesn't like being run as root). |
| # Logs will be found in /var/log/startup.(log|err) |
| |
| # Wait 20s to make sure ssl is fully booted. Otherwise, we may get an error |
| # when trying to download the bootstrap code. |
| sleep 20s |
| |
| # Copy authentication to home directory |
| cp /opt/.gitconfig /home/chrome-bot/.gitconfig |
| cp /opt/.netrc /home/chrome-bot/.netrc |
| |
| host="$(hostname)" |
| swarming="https://chromium-swarm.appspot.com" |
| if [[ "$host" = skia-i-* ]]; then |
| swarming="https://chrome-swarming.appspot.com" |
| elif [[ "$host" = skia-d-* ]]; then |
| swarming="https://chromium-swarm-dev.appspot.com" |
| fi |
| |
| if [ -d "/b/s" ]; then |
| echo "Starting swarming at legacy location /b/s" |
| /usr/bin/python /b/s/swarming_bot.zip start_bot & |
| # The following is based on this Ansible script, which was not used here |
| # because it would've complicated the setup flow a bit: |
| # https://skia.googlesource.com/buildbot/+/master/skolo/common/ansible/bootstrap-swarming.yml |
| elif [ ! -d "/opt/s" ]; then |
| mkdir -p /opt/s |
| cd /opt/s |
| tok=$(curl --silent --show-error --header "Metadata-Flavor: Google" \ |
| "http://metadata/computeMetadata/v1/instance/service-accounts/default/token" | \ |
| sed -E 's/.*"access_token":"([^"]+)".*/\1/') |
| curl --silent --show-error --location "${swarming}/bot_code?tok=${tok}" \ |
| --output /opt/s/swarming_bot.zip |
| echo "Bootstrapping $swarming at /opt/s, expect a reboot" |
| /usr/bin/python -u /opt/s/swarming_bot.zip |
| else |
| echo "Starting swarming at /opt/s" |
| /usr/bin/python /opt/s/swarming_bot.zip start_bot & |
| fi |