forked from eBayClassifiedsGroup/PanteraS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_yml.sh
executable file
·145 lines (128 loc) · 4.64 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
#!/bin/bash
[ -f ./restricted/common ] && . ./restricted/common
[ -f ./restricted/host ] && . ./restricted/host
[ -f ./restricted/overwrite ] && . ./restricted/overwrite
echo "Keep in mind to not to occupy those ports on DOCKERHOST"
echo "53, 80, 81, 2181, 2888, 3888, 5050, 5151, 8080, 8300-8302, 8400, 8500, 8600, 9000, 31000 - 32000"
# 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"}
#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_HAPROXY=${START_HAPROXY:-${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}
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`"}
# 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 template.conf:/etc/haproxy/haproxy.cfg:/opt/consul-template/haproxy_reload.sh"
#
DNSMASQ_PARAMS="-d \
-u dnsmasq \
-r /etc/resolv.conf \
-7 /etc/dnsmasq.d \
--server=/consul/${CONSUL_IP}#8600 \
--address=/consul/${CONSUL_IP} \
--host-record=${HOSTNAME},${CONSUL_IP} \
${DNSMASQ_PARAMS}"
#
HAPROXY_RELOAD_COMMAND="/usr/sbin/haproxy -p /tmp/haproxy.pid -f /etc/haproxy/haproxy.cfg -sf \$(pidof /usr/sbin/haproxy) || true"
#
MARATHON_PARAMS="--master zk://${ZOOKEEPER_HOSTS}/mesos \
--zk zk://${ZOOKEEPER_HOSTS}/marathon \
--hostname ${HOSTNAME} \
${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} \
--docker_stop_timeout=5secs \
${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}
HAPROXY_RELOAD_COMMAND=${HAPROXY_RELOAD_COMMAND:-$HAPROXY_RELOAD_COMMAND}
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}
# DNS manipulation
# You can change your resolv.conf inside panetras image
# just cerate /etc/resolv.conf.paas on docker host wih your content
#
RESOLV_CONF='/etc/resolv.conf'
$B2D [ -f /etc/resolv.conf.paas ] 2>/dev/null && RESOLV_CONF='/etc/resolv.conf.paas'
eval "$(cat docker-compose.yml.tpl| sed 's/"/+++/g'|sed 's/^\(.*\)$/echo "\1"/')" |sed 's/+++/"/g'|sed 's;\\";";g' > docker-compose.yml