Skip to content

Commit 296f91a

Browse files
committed
added galera fixup script
1 parent 9600a69 commit 296f91a

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

siwapp-db.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash -x
22

3-
curl -o /tmp/provisioningVars.sh ${FILE_SERVER}/pod_${POD}_variables.sh
4-
. /tmp/provisioningVars.sh
3+
mkdir /usr/local/siwapp
4+
curl -o /usr/local/siwapp/provisioningVars.sh ${FILE_SERVER}/pod_${POD}_variables.sh
5+
. /usr/local/siwapp/provisioningVars.sh
56

67
su -c "cat <<EOF > /etc/yum.repos.d/MariaDB.repo
78
[mariadb]
@@ -234,3 +235,11 @@ else
234235
systemctl start mariadb
235236
fi
236237
fi
238+
239+
mkdir /usr/share/systemd/siwapp
240+
wget ${FILE_SERVER}/siwapp-galera-fixup.sh -P /usr/share/systemd/siwapp
241+
mkdir /usr/lib/systemd/system/mariadb.service.d
242+
cat > /usr/lib/systemd/system/mariadb.service.d/10-siwapp-edits.conf <<EOF
243+
[Service]
244+
ExecStartPre=/usr/bin/bash /usr/share/systemd/siwapp/siwapp-galera-fixup.sh
245+
EOF

siwapp-galera-fixup.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash -x
2+
3+
. /usr/local/siwapp/provisioningVars.sh
4+
5+
temp_ifs=${IFS}
6+
IFS=','
7+
dbHosts=(${DB_TIER_HOSTNAMES}) # Array of nodes in my tier.
8+
dbIps=(${DB_TIER_IPS}) # Array of IPs in my tier.
9+
master=${dbHosts[0]} # Let the first node in the service tier be the master.
10+
master_addr=${dbIps[0]} # Let the first node in the service tier be the master.
11+
12+
IFS=${temp_ifs}
13+
14+
if [ "${master}" == "${HOSTNAME}" ]; then
15+
sed -i "s/safe_to_bootstrap.*/safe_to_bootstrap: 1/" /var/lib/mysql/grastate.dat
16+
systemctl set-environment _WSREP_NEW_CLUSTER='--wsrep-new-cluster'
17+
18+
else
19+
echo "Waiting for master node to be initialized..."
20+
COUNT=0
21+
MAX=50
22+
SLEEP_TIME=5
23+
ERR=0
24+
25+
# Keep checking for port 3306 on the master to be open
26+
until $(mysql -h $master_addr -u root -p"${GALERA_DB_ROOT_PWD}" -e ""); do
27+
sleep ${SLEEP_TIME}
28+
let "COUNT++"
29+
echo ${COUNT}
30+
if [ ${COUNT} -gt ${MAX} ]; then
31+
ERR=1
32+
break
33+
fi
34+
done
35+
if [ ${ERR} -ne 0 ]; then
36+
echo "Failed to find port 3306 open on master node, so guessing something is wrong."
37+
exit 1
38+
else
39+
echo "starting slave"
40+
fi
41+
fi

0 commit comments

Comments
 (0)