Skip to content

Commit

Permalink
add Checking PS
Browse files Browse the repository at this point in the history
  • Loading branch information
GeunSam2 committed Mar 30, 2020
1 parent 97499ed commit 97e6c07
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
5 changes: 5 additions & 0 deletions mysql-mha/Dockerfile-manager
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ RUN apt-get update && \
RUN apt-get install -y jq

ARG SERVICE_N
ARG MHA_HAPROXY_IMG_1
ARG MHA_HAPROXY_IMG_2

ENV MHA_HAPROXY_IMG_1 ${MHA_HAPROXY_IMG_1}
ENV MHA_HAPROXY_IMG_2 ${MHA_HAPROXY_IMG_2}

COPY conf/common/NodeUtil.pm /usr/share/perl5/MHA/NodeUtil.pm
COPY conf/common/MasterFailover.pm /usr/share/perl5/MHA/MasterFailover.pm
Expand Down
7 changes: 3 additions & 4 deletions mysql-mha/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SERVICE_N := sampledb-1
SERVICE_N := sampledb-1
TAG := v1
IMAGE_NAME_BASE := geunsam2/mha-$(SERVICE_N)
MYSQL_PASS := admin123!@#
Expand All @@ -13,7 +13,7 @@ build: ## Builds docker image latest
docker build --pull -t $(IMAGE_NAME_BASE):db2$(TAG) -f Dockerfile-db --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=2 .
docker build --pull -t $(IMAGE_NAME_BASE):db3$(TAG) -f Dockerfile-db --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=3 .
docker build --pull -t $(IMAGE_NAME_BASE):db4$(TAG) -f Dockerfile-db --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=4 .
docker build --pull -t $(IMAGE_NAME_BASE):manager$(TAG) -f Dockerfile-manager --build-arg SERVICE_N=$(SERVICE_N) --build-arg HAPROXY_IMG_1=$(IMAGE_NAME_BASE):haproxy1$(TAG) --build-arg HAPROXY_IMG_2=$(IMAGE_NAME_BASE):haproxy2$(TAG) .
docker build --pull -t $(IMAGE_NAME_BASE):manager$(TAG) -f Dockerfile-manager --build-arg SERVICE_N=$(SERVICE_N) --build-arg MHA_HAPROXY_IMG_1=$(IMAGE_NAME_BASE):haproxy1$(TAG) --build-arg MHA_HAPROXY_IMG_2=$(IMAGE_NAME_BASE):haproxy2$(TAG) .
docker build --pull -t $(IMAGE_NAME_BASE):haproxy1$(TAG) -f Dockerfile-haproxy --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=1 .
docker build --pull -t $(IMAGE_NAME_BASE):haproxy2$(TAG) -f Dockerfile-haproxy --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=2 .

Expand All @@ -23,7 +23,7 @@ push: ## Pushes the docker image to hub.docker.com
docker build --pull -t $(IMAGE_NAME_BASE):db2$(TAG) -f Dockerfile-db --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=2 .
docker build --pull -t $(IMAGE_NAME_BASE):db3$(TAG) -f Dockerfile-db --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=3 .
docker build --pull -t $(IMAGE_NAME_BASE):db4$(TAG) -f Dockerfile-db --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=4 .
docker build --pull -t $(IMAGE_NAME_BASE):manager$(TAG) -f Dockerfile-manager --build-arg SERVICE_N=$(SERVICE_N) .
docker build --pull -t $(IMAGE_NAME_BASE):manager$(TAG) -f Dockerfile-manager --build-arg SERVICE_N=$(SERVICE_N) --build-arg MHA_HAPROXY_IMG_1=$(IMAGE_NAME_BASE):haproxy1$(TAG) --build-arg MHA_HAPROXY_IMG_2=$(IMAGE_NAME_BASE):haproxy2$(TAG) .
docker build --pull -t $(IMAGE_NAME_BASE):haproxy1$(TAG) -f Dockerfile-haproxy --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=1 .
docker build --pull -t $(IMAGE_NAME_BASE):haproxy2$(TAG) -f Dockerfile-haproxy --build-arg SERVICE_N=$(SERVICE_N) --build-arg F_NUM=2 .
docker push $(IMAGE_NAME_BASE):db1$(TAG)
Expand All @@ -33,4 +33,3 @@ push: ## Pushes the docker image to hub.docker.com
docker push $(IMAGE_NAME_BASE):manager$(TAG)
docker push $(IMAGE_NAME_BASE):haproxy1$(TAG)
docker push $(IMAGE_NAME_BASE):haproxy2$(TAG)

3 changes: 2 additions & 1 deletion mysql-mha/change_proxy1.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
jq .container.docker.image=\"${HAPROXY_IMG_1}\" /etc/mha_script/haproxy.json | \
. /env.sh
jq .container.docker.image=\"${MHA_HAPROXY_IMG_1}\" /etc/mha_script/haproxy.json | \
/usr/local/bin/dcos marathon app update ${MHA_HAPROXY_DCOS_NAME}
echo "HAPROXY update to type 1 success" >> /var/log/masterha/MHA.log
echo "DB Master is now ${MHA_DB_1_IP}${MHA_DB_1_PORT}" >> /var/log/masterha/MHA.log
3 changes: 2 additions & 1 deletion mysql-mha/change_proxy2.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
jq .container.docker.image=\"${HAPROXY_IMG_2}\" /etc/mha_script/haproxy.json | \
. /env.sh
jq .container.docker.image=\"${MHA_HAPROXY_IMG_2}\" /etc/mha_script/haproxy.json | \
/usr/local/bin/dcos marathon app update ${MHA_HAPROXY_DCOS_NAME}
echo "HAPROXY update to type 2 success" >> /var/log/masterha/MHA.log
echo "DB Master is now ${MHA_DB_2_IP}${MHA_DB_2_PORT}" >> /var/log/masterha/MHA.log
27 changes: 25 additions & 2 deletions mysql-mha/repl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,23 @@ MHA_CMASTER_PORT=""
MHA_CMASTER=""
echo "### Checking ENV [OK]"

echo "###Wait MHA Nodes for 10 Second "
sleep 10
echo "### Checking PS"
PS_COUNTER=0
for i in $(seq 1 3)
do
CHECK_PS=$(ps -ef | egrep '(defunct|master_ip_failover_script)' | wc -l)
if [ ${CHECK_PS} -eq 1 ]; then
PS_COUNTER=$((PS_COUNTER+1))
fi
sleep 0.5
done

if [ ${PS_COUNTER} -ne 3 ]; then
echo "###Master is now failovering. Stop CRON script."
exit 1
fi
echo "### Checking PS [OK]"


#Check Current Master and Slave status
echo "### Checking Current Master and Slave Status"
Expand Down Expand Up @@ -61,6 +76,14 @@ echo "### Current Master is : ${MHA_CMASTER}"
echo "### Need Work List : ${MHA_REPL_LIST[@]}"
echo "### Checking Current Master and Slave Status [OK]"

#Deploy HAPROXY
if [ ${MHA_CMASTER_IP}${MHA_CMASTER_PORT} = ${MHA_DB_1_IP}${MHA_DB_1_PORT} ]; then
/bin/bash /etc/mha_script/change_proxy1.sh
else
/bin/bash /etc/mha_script/change_proxy2.sh
fi


#Dump from master
echo "### Dumping current Master's Databases. (${MHA_REPL_DB_1} ${MHA_REPL_DB_2} ${MHA_REPL_DB_3})"
mysqldump --single-transaction --routines --triggers --databases ${MHA_REPL_DB_1} ${MHA_REPL_DB_2} ${MHA_REPL_DB_3} -h ${MHA_CMASTER_IP} -P ${MHA_CMASTER_PORT} -u${MHA_DB_ADMIN_ID} -p${MHA_DB_ADMIN_PW} > /tmp/master_dump.db
Expand Down

0 comments on commit 97e6c07

Please sign in to comment.