forked from eBayClassifiedsGroup/PanteraS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_yml.sh
executable file
·165 lines (145 loc) · 5.62 KB
/
generate_yml.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# docker-compose.yml generator
#
[ -f ./restricted/common ] && . ./restricted/common
[ -f ./restricted/host ] && . ./restricted/host
[ -f ./restricted/overwrite ] && . ./restricted/overwrite
echo "Keep in mind, to set free these ports on DOCKER HOST:"
echo "53, 80, 81, 2181, 2888, 3888, 5050, 5151, 8080, 8300 - 8302, 8400, 8500, 8600, 9000, 31000 - 32000"
echo "and be sure that your hostname is resolvable, if not, add entry to /etc/resolv.conf"
# detect DOCKERHOST IP if was not provided
# boot2docker
B2D=""
which boot2docker >/dev/null && {
echo "Boot2docker detected, shall we use it (y/n)?"
read ANSWER
[ "$ANSWER" == "y" ] && {
boot2docker init
boot2docker start
$(boot2docker shellinit)
HOSTNAME=boot2docker
B2D="boot2docker ssh"
FQDN=$HOSTNAME
[ -n "${DOCKER_HOST}" ] && IP=${IP:-$(echo $DOCKER_HOST | sed 's;.*//\(.*\):.*;\1;')}
}
}
# Try to detect IP
# outside vagrant
which vagrant >/dev/null && IP=${IP:-$(vagrant ssh -c ifconfig 2>/dev/null| grep -oh "\w*192.168.10.10\w*")}
# inside vagrant
[ "$HOSTNAME" == "standalone" ] && IP=${IP:-192.168.10.10}
# try to guess
IP=${IP:-$(dig +short ${HOSTNAME})}
[ -z ${IP} ] && echo "env IP variable missing" && exit 1
# Defaults for stand alone mode
MASTER=${MASTER:-"true"}
SLAVE=${SLAVE:-"true"}
# allow to specify a specific docker image or a specific tag of the pass-in-a-box image
PANTERAS_IMAGE_TAG=${PANTERAS_IMAGE_TAG:-"latest"}
PANTERAS_DOCKER_IMAGE=${PANTERAS_DOCKER_IMAGE:-${REGISTRY}panteras/paas-in-a-box:${PANTERAS_IMAGE_TAG}}
#COMMON
START_CONSUL=${START_CONSUL:-"true"}
#MASTER
START_MESOS_MASTER=${START_MESOS_MASTER:-${MASTER}}
START_MARATHON=${START_MARATHON:-${MASTER}}
START_ZOOKEEPER=${START_ZOOKEEPER:-${MASTER}}
#SLAVE
START_CONSUL_TEMPLATE=${START_CONSUL_TEMPLATE:-${SLAVE}}
START_MESOS_SLAVE=${START_MESOS_SLAVE:-${SLAVE}}
START_REGISTRATOR=${START_REGISTRATOR:-${SLAVE}}
#OPTIONAL
START_DNSMASQ=${START_DNSMASQ:-"true"}
# Lets consul behave as a client but on slaves only
[ "${SLAVE}" == "true" ] && [ "${MASTER}" == "false" ] && CONSUL_MODE=${CONSUL_MODE:-' '}
CONSUL_MODE=${CONSUL_MODE:-'-server'}
HOST_IP=${IP}
DNS_IP=${DNS_IP}
CONSUL_IP=${IP}
CONSUL_DC=${CONSUL_DC:-"UNKNOWN"}
CONSUL_BOOTSTRAP=${CONSUL_BOOTSTRAP:-'-bootstrap-expect 1'}
CONSUL_HOSTS=${CONSUL_HOSTS:-${CONSUL_BOOTSTRAP}}
MESOS_CLUSTER_NAME=${CLUSTER_NAME:-"mesoscluster"}
MESOS_MASTER_QUORUM=${MESOS_MASTER_QUORUM:-"1"}
ZOOKEEPER_HOSTS=${ZOOKEEPER_HOSTS:-"${HOSTNAME}:2181"}
ZOOKEEPER_ID=${ZOOKEEPER_ID:-"0"}
GOMAXPROCS=${GOMAXPROCS:-"4"}
FQDN=${FQDN:-"`hostname -f`"}
FQDN=${FQDN:-${HOSTNAME}}
# Disable dnsmasq address re-mapping on non slaves - no HAProxy there
[ "${SLAVE}" == "false" ] && DNSMASQ_ADDRESS=${DNSMASQ_ADDRESS:-' '}
DNSMASQ_ADDRESS=${DNSMASQ_ADDRESS:-"--address=/consul/${CONSUL_IP}"}
# enable keepalived if the consul_template(with HAproxy) gets started and a
# virtual IP address is specified
[ "${START_CONSUL_TEMPLATE}" == "true" ] && [ ${KEEPALIVED_VIP} ] && \
KEEPALIVED_CONSUL_TEMPLATE="-template=./keepalived.conf.ctmpl:/etc/keepalived/keepalived.conf:./keepalived_reload.sh"
# Expose ports depends on which service has been mark to start
[ "${START_CONSUL_TEMPLATE}" == "true" ] && {
[ "${START_CONSUL}" == "true" ] && PORTS="ports:" && CONSUL_UI_PORTS='- "8500:8500"'
[ "${START_MARATHON}" == "true" ] && PORTS="ports:" && MARATHON_PORTS='- "8080:8080"'
[ "${START_MESOS_MASTER}" == "true" ] && PORTS="ports:" && MESOS_PORTS='- "5050:5050"'
}
# Parameters for every supervisord command
#
# -config-dir=/etc/consul.d/ \
CONSUL_PARAMS="agent \
-client=0.0.0.0 \
-data-dir=/opt/consul/ \
-ui-dir=/opt/consul/dist/ \
-advertise=${HOST_IP} \
-node=${HOSTNAME} \
-dc=${CONSUL_DC} \
${CONSUL_MODE} \
${CONSUL_HOSTS} \
${CONSUL_PARAMS}"
#
CONSUL_TEMPLATE_PARAMS="-consul=${CONSUL_IP}:8500 \
-template haproxy.cfg.ctmpl:/etc/haproxy/haproxy.cfg:/opt/consul-template/haproxy_reload.sh \
${KEEPALIVED_CONSUL_TEMPLATE}"
#
DNSMASQ_PARAMS="-d \
-u dnsmasq \
-r /etc/resolv.conf.orig \
-7 /etc/dnsmasq.d \
--server=/consul/${CONSUL_IP}#8600 \
--host-record=${HOSTNAME},${CONSUL_IP} \
${DNSMASQ_ADDRESS} \
${DNSMASQ_PARAMS}"
#
MARATHON_PARAMS="--master zk://${ZOOKEEPER_HOSTS}/mesos \
--zk zk://${ZOOKEEPER_HOSTS}/marathon \
--hostname ${HOSTNAME} \
--no-logger \
${MARATHON_PARAMS}"
#
MESOS_MASTER_PARAMS="--zk=zk://${ZOOKEEPER_HOSTS}/mesos \
--work_dir=/var/lib/mesos \
--quorum=${MESOS_MASTER_QUORUM} \
--ip=0.0.0.0 \
--hostname=${FQDN} \
--cluster=${MESOS_CLUSTER_NAME} \
${MESOS_MASTER_PARAMS}"
#
MESOS_SLAVE_PARAMS="--master=zk://${ZOOKEEPER_HOSTS}/mesos \
--containerizers=docker,mesos \
--executor_registration_timeout=5mins \
--hostname=${FQDN} \
--ip=0.0.0.0 \
--docker_stop_timeout=5secs \
--gc_delay=1days \
--docker_socket=/tmp/docker.sock \
${MESOS_SLAVE_PARAMS}"
#
REGISTRATOR_PARAMS="-ip=${HOST_IP} consul://${CONSUL_IP}:8500 \
${REGISTRATOR_PARAMS}"
#
ZOOKEEPER_PARAMS="start-foreground"
CONSUL_APP_PARAMS=${CONSUL_APP_PARAMS:-$CONSUL_PARAMS}
CONSUL_TEMPLATE_APP_PARAMS=${CONSUL_TEMPLATE_APP_PARAMS:-$CONSUL_TEMPLATE_PARAMS}
DNSMASQ_APP_PARAMS=${DNSMASQ_APP_PARAMS:-$DNSMASQ_PARAMS}
MARATHON_APP_PARAMS=${MARATHON_APP_PARAMS:-$MARATHON_PARAMS}
MESOS_MASTER_APP_PARAMS=${MESOS_MASTER_APP_PARAMS:-$MESOS_MASTER_PARAMS}
MESOS_SLAVE_APP_PARAMS=${MESOS_SLAVE_APP_PARAMS:-$MESOS_SLAVE_PARAMS}
REGISTRATOR_APP_PARAMS=${REGISTRATOR_APP_PARAMS:-$REGISTRATOR_PARAMS}
ZOOKEEPER_APP_PARAMS=${ZOOKEEPER_APP_PARAMS:-$ZOOKEEPER_PARAMS}
PANTERAS_HOSTNAME=${PANTERAS_HOSTNAME:-${HOSTNAME}}
PANTERAS_RESTART=${PANTERAS_RESTART:-"no"}
eval "$(cat docker-compose.yml.tpl| sed 's/"/+++/g'|sed 's/^\(.*\)$/echo "\1"/')" |sed 's/+++/"/g'|sed 's;\\";";g' > docker-compose.yml