| #!/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 |
| mkdir /b/s |
| cd /b/s |
| echo "Bootstrapping $swarming, expect a reboot" |
| # 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 |
| script=$(cat << EOF |
| import json |
| import urllib2 |
| |
| token_url = ('http://metadata/computeMetadata/v1/instance/' |
| 'service-accounts/default/token') |
| req = urllib2.Request(token_url, headers={'Metadata-Flavor': 'Google'}) |
| tok = json.load(urllib2.urlopen(req)) |
| req = urllib2.Request( |
| '$swarming/bootstrap', |
| headers={'Authorization': 'Bearer %s' % tok['access_token']}) |
| exec urllib2.urlopen(req).read() |
| EOF |
| ) |
| python -c "$script" |
| else |
| echo "Starting swarming" |
| /usr/bin/python /b/s/swarming_bot.zip start_bot & |
| fi |