-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathboot
More file actions
executable file
·115 lines (88 loc) · 3.33 KB
/
boot
File metadata and controls
executable file
·115 lines (88 loc) · 3.33 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
#
# This script is designed to be run inside the container
#
# fail hard and fast even on pipelines
set -eo pipefail
# set debug based on envvar
[[ $DEBUG ]] && set -x
# configure etcd
export ETCD_PORT=${ETCD_PORT:-4001}
export ETCD="$HOST:$ETCD_PORT"
export ETCD_PATH=${ETCD_PATH:-/deis/builder}
export ETCD_TTL=${ETCD_TTL:-10}
export STORAGE_DRIVER=${STORAGE_DRIVER:-btrfs}
# wait for etcd to be available
until etcdctl --no-sync -C $ETCD ls >/dev/null 2>&1; do
echo "waiting for etcd at $ETCD..."
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done
# wait until etcd has discarded potentially stale values
sleep $(($ETCD_TTL+1))
function etcd_safe_mkdir {
etcdctl --no-sync -C $ETCD mkdir $1 >/dev/null 2>&1 || true
}
etcd_safe_mkdir $ETCD_PATH/users
# wait for confd to run once and install initial templates
until confd -onetime -node $ETCD -config-file /app/confd.toml; do
echo "builder: waiting for confd to write initial templates..."
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done
# spawn confd in the background to update services based on etcd changes
confd -node $ETCD -config-file /app/confd.toml &
CONFD_PID=$!
# remove any pre-existing docker.sock
test -e /var/run/docker.sock && rm -f /var/run/docker.sock
# spawn a docker daemon to run builds
docker -d --storage-driver=$STORAGE_DRIVER --bip=172.19.42.1/16 &
DOCKER_PID=$!
# wait for docker to start
while [[ ! -e /var/run/docker.sock ]]; do
sleep 1
done
# HACK: load progrium/cedarish tarball for faster boot times
# see https://github.com/deis/deis/issues/1027
if ! docker history progrium/cedarish >/dev/null 2>/dev/null ; then
echo "Loading cedarish..."
docker load -i /progrium_cedarish.tar
else
echo "Cedarish already loaded"
fi
# pull required images
# Custom slugbuilder?
SLUGBUILDER=`etcdctl --no-sync -C $ETCD get /deis/slugbuilder/image 2>/dev/null || etcdctl --no-sync -C $ETCD mk /deis/slugbuilder/image deis/slugbuilder:latest 2>/dev/null`
docker pull ${SLUGBUILDER}
docker tag ${SLUGBUILDER} deis/slugbuilder:latest
# Custom slugrunner?
SLUGRUNNER=`etcdctl --no-sync -C $ETCD get /deis/slugrunner/image 2>/dev/null || etcdctl --no-sync -C $ETCD mk /deis/slugrunner/image deis/slugrunner:latest 2>/dev/null`
docker pull ${SLUGRUNNER}
docker tag ${SLUGRUNNER} deis/slugrunner:latest
# start an SSH daemon to process `git push` requests
/usr/sbin/sshd -D -e &
SSHD_PID=$!
# smart shutdown on SIGINT and SIGTERM
function on_exit() {
kill -TERM $DOCKER_PID $SSHD_PID
wait $DOCKER_PID $SSHD_PID 2>/dev/null
exit 0
}
trap on_exit INT TERM EXIT
echo deis-builder running...
# publish the service to etcd using the injected PORT
if [[ ! -z $PUBLISH ]]; then
# configure service discovery
PORT=${PORT:-2223}
PROTO=${PROTO:-tcp}
set +e
# wait for the service to become available on PUBLISH port
sleep 1 && while [[ -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do sleep 1; done
# while the port is listening, publish to etcd
while [[ ! -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do
etcdctl --no-sync -C $ETCD set $ETCD_PATH/host $HOST --ttl $ETCD_TTL >/dev/null
etcdctl --no-sync -C $ETCD set $ETCD_PATH/port $PORT --ttl $ETCD_TTL >/dev/null
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done
# if the loop quits, something went wrong
exit 1
fi
wait