-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsiwapp-haproxy-app.sh
44 lines (38 loc) · 1.39 KB
/
siwapp-haproxy-app.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
#!/bin/bash -x
curl -o /tmp/provisioningVars.sh ${FILE_SERVER}/pod_${POD}_variables.sh
. /tmp/provisioningVars.sh
yum -y update
yum install -y haproxy
echo "Configuring haproxy"
su -c 'echo "
#---------------------------------------------------------------------
# http frontend
#---------------------------------------------------------------------
frontend http_in
mode http
bind *:80
default_backend siwapp_apps
#---------------------------------------------------------------------
# Siwapp App Server Backend
#---------------------------------------------------------------------
backend siwapp_apps
balance roundrobin
cookie SERVERID insert indirect nocache
" >> /etc/haproxy/haproxy.cfg'
# Set internal separator to ',' since they're comma-delimited lists.
temp_ifs=${IFS}
IFS=','
ipArr=(${APP_TIER_IPS}) # Array of IPs in my tier.
echo "Creating haproxy config files"
# Iterate through list of hosts to add hosts and corresponding IPs to haproxy config file.
host_index=0
for host in $APP_TIER_HOSTNAMES ; do
su -c "echo 'server ${host} ${ipArr[${host_index}]}:8081 check cookie ${host} inter 5s' >> /etc/haproxy/haproxy.cfg"
su -c "echo '${ipArr[${host_index}]} ${host}' >> /etc/hosts"
let host_index=${host_index}+1
done
# Set internal separator back to original.
IFS=${temp_ifs}
systemctl start haproxy
systemctl enable haproxy
echo "App HAProxy install complete"