Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit 04cdb48

Browse files
Revert "Revert "Merge branch Pull Reuqest 209 into develop""
This commit is to re-merge the changes from Pull Request 209, as we have a workaround for the "delete deployment" case. The workaround will be checked in after this. This reverts commit 9a5aa37. [#157656403]
1 parent 34b6c2e commit 04cdb48

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

jobs/mysql/templates/drain.sh

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,53 @@
1-
#!/bin/bash -e
1+
#!/usr/bin/env bash
22

33
<% if p('cf_mysql_enabled') == true %>
4+
set -e -o pipefail
5+
6+
<%
7+
cluster_ips = link('mysql').instances.map(&:address)
8+
if_link('arbitrator') do
9+
cluster_ips += link('arbitrator').instances.map(&:address)
10+
end
11+
%>
12+
13+
CLUSTER_NODES=(<%= cluster_ips.map{|e| e }.join(' ') %>)
14+
MYSQL_PORT=<%= p("cf_mysql.mysql.port") %>
15+
GALERA_HEALTHCHECK_PORT=<%= p("cf_mysql.mysql.galera_healthcheck.port") %>
16+
LOG_DIR="/var/vcap/sys/log/mysql"
17+
18+
# If the node is not running, exit drain successfully
19+
if ! ps -p "$(</var/vcap/sys/run/mysql/mysql.pid)" >/dev/null; then
20+
echo "$(date): mysql is not running: OK to drain" >> "${LOG_DIR}/drain.log"
21+
echo 0; exit 0 # drain success
22+
fi
23+
24+
# Check the galera healthcheck endpoint on all of the nodes. If the http status returned is 000, there
25+
# is no node at that IP, so we assume we are scaling down. If the http status returned is 200 from all nodes
26+
# it will continue to drain. If it detects any other nodes to be unhealthy, it will fail to drain
27+
# and exit.
28+
for NODE in "${CLUSTER_NODES[@]}"; do
29+
set +e
30+
status_code=$(curl -s -o "/dev/null" -w "%{http_code}" "$NODE:$GALERA_HEALTHCHECK_PORT")
31+
set -e
32+
if [[ $status_code -eq 000 || $status_code -eq 200 ]]; then
33+
continue
34+
else
35+
echo "$(date): galera heathcheck returned $status_code; drain failed on node ${NODE}" >> "${LOG_DIR}/drain.err.log"
36+
exit -1
37+
fi
38+
done
39+
40+
# Actually drain with a kill_and_wait on the mysql pid
441
PIDFILE=/var/vcap/sys/run/mariadb_ctl/mariadb_ctl.pid
542
source /var/vcap/packages/cf-mysql-common/pid_utils.sh
643

744
set +e
8-
kill_and_wait ${PIDFILE} 300 0 > /dev/null
45+
kill_and_wait "${PIDFILE}" 300 0 > /dev/null
946
return_code=$?
1047

1148
echo 0
1249
exit ${return_code}
50+
1351
<% else %>
1452
echo 0
1553
exit 0

0 commit comments

Comments
 (0)