-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsiwapp-haproxy-db.sh
42 lines (35 loc) · 1.25 KB
/
siwapp-haproxy-db.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
#!/bin/bash -x
curl -o /tmp/provisioningVars.sh ${FILE_SERVER}/pod_${POD}_variables.sh
. /tmp/provisioningVars.sh
echo "Installing haproxy."
yum -y update
yum install -y haproxy
echo "Configuring haproxy"
su -c 'echo "
#---------------------------------------------------------------------
# Siwapp App Server Backend
#---------------------------------------------------------------------
listen galera 0.0.0.0:3306
balance roundrobin
mode tcp
option tcpka
option mysql-check user haproxy
" >> /etc/haproxy/haproxy.cfg'
# Set internal seperator to ',' since they're comma-delimited lists.
temp_ifs=${IFS}
IFS=','
# nodeArr=(${CliqrTier_siwapp_mariadb_NODE_ID}) # Array of nodes in my tier.
ipArr=(${DB_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 $DB_TIER_HOSTNAMES ; do
su -c "echo 'server ${host} ${ipArr[${host_index}]}:3306 check 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 "DB HAProxy install complete"