-
Notifications
You must be signed in to change notification settings - Fork 6
/
run.sh
executable file
·77 lines (63 loc) · 2.13 KB
/
run.sh
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
#!/bin/bash -e
source conf.sh
source services.sh
if [ "$1" == "--version" ]; then
VERSION="$2"
shift #move command line arguments to the left
shift #move command line arguments to the left
fi
NAME=${1:-all}
if [ "$NAME" == "--help" ]; then
echo "$0 [--version <version>]: run all services."
echo "$0 [--version <version>] <service> : run a specific service."
echo "$0 [--version <version>] coscale : run the CoScale services."
exit 0
fi
function get_service {
echo $1 | grep -o -e '^[^0-9]*'
}
function get_seq {
echo $1 | grep -o -e '[0-9]*$'
}
function run {
SERVICE=$1
IMAGE_VERSION=$2
SEQ=$3
ENV_VARS_CONF=`for VAR in $(cat conf.sh | grep '^export' | grep -v REGISTRY | awk '{ print $2; }' | awk -F= '{ print $1; }'); do echo '-e '${VAR}'='${!VAR}' '; done`
echo "Starting $SERVICE:$IMAGE_VERSION $SEQ"
# Don't bother when service is already running
if [ "$(docker ps -a | grep coscale_$SERVICE$SEQ$)" ]; then
echo "The service ${SERVICE}${SEQ} already exists."
else
docker run -d \
$ENV_VARS_CONF $(./get-docker-opts.sh $SERVICE $SEQ) \
-e "COSCALE_VERSION=$IMAGE_VERSION" \
--restart on-failure \
--hostname=coscale_$SERVICE$SEQ \
--name coscale_$SERVICE$SEQ coscale/$SERVICE:$IMAGE_VERSION
fi
}
# Run the data services
STARTED=0
for SERVICE in $DATA_SERVICES; do
if [ "$NAME" == "all" ] || [ "$NAME" == "data" ] || [ "$NAME" == $(get_service "$SERVICE") ] || [ "$NAME" == "$SERVICE" ]; then
run $(get_service $SERVICE) $VERSION $(get_seq $SERVICE)
STARTED=1
fi
done
if [ "$STARTED" == "1" ]; then
echo "Sleeping 30 seconds to bring the data services up."
sleep 30
fi
# Run the coscale services
for SERVICE in $COSCALE_SERVICES $LB_SERVICE; do
if [ "$NAME" == "all" ] || [ "$NAME" == "coscale" ] || [ "$NAME" == $(get_service "$SERVICE") ] || [ "$NAME" == "$SERVICE" ]; then
run $(get_service $SERVICE) $VERSION $(get_seq $SERVICE)
STARTED=1
fi
done
# Raise an error if no containers were started
if [ "$STARTED" == "0" ]; then
echo "Error: no containers started."
exit 1
fi