forked from travis-ci/worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemd-wrapper
executable file
·66 lines (53 loc) · 1.48 KB
/
systemd-wrapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
set -o errexit
main() {
local name="${1:-travis-worker}"
docker stop "${name}" &>/dev/null || true
docker rm -f "${name}" &>/dev/null || true
local env_file
env_file="$(tfw writeenv travis-worker)"
set -o allexport
# shellcheck source=/dev/null
source "${env_file}"
if [[ "${TRAVIS_WORKER_PROVIDER_NAME}" == gce ]]; then
local gce_zone
gce_zone="$(__fetch_gce_zone)"
if [ -z "${gce_zone}" ]; then
gce_zone=us-central1-b
fi
echo "TRAVIS_WORKER_GCE_ZONE=${gce_zone}" >>"${env_file}"
fi
if [[ ! "${TRAVIS_WORKER_LIBRATO_SOURCE}" ]]; then
local librato_source
librato_source="$(__build_librato_source "$(hostname)" "${name}")"
echo "TRAVIS_WORKER_LIBRATO_SOURCE=${librato_source}" >>"${env_file}"
fi
if [ -f "${TRAVIS_WORKER_PRESTART_HOOK}" ]; then
"${TRAVIS_WORKER_PRESTART_HOOK}"
fi
exec docker run \
--rm \
--name "${name}" \
--hostname "$(hostname)" \
--userns host \
-v /var/tmp:/var/tmp \
-v /var/run:/var/run \
--env-file "${env_file}" \
"${TRAVIS_WORKER_SELF_IMAGE}" travis-worker
}
__fetch_gce_zone() {
curl -sSL \
"http://metadata.google.internal/computeMetadata/v1/instance/zone" \
-H "Metadata-Flavor: Google" |
awk -F/ '{ print $NF }'
}
__build_librato_source() {
local host_name="${1}"
local name="${2}"
if [[ "${name}" == "travis-worker" ]]; then
echo "${host_name}"
return
fi
echo "${host_name}-${name/travis-worker-/}"
}
main "$@"