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

Commit 9a5aa37

Browse files
Revert "Merge branch Pull Reuqest 209 into develop"
This reverts commit 20373f3, reversing changes made to 570f38f. These changes caused delete-deployment to fail since the drain scripts are run in parallel on all nodes.
1 parent 20373f3 commit 9a5aa37

File tree

1 file changed

+2
-40
lines changed

1 file changed

+2
-40
lines changed

jobs/mysql/templates/drain.sh

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,15 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash -e
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
414
PIDFILE=/var/vcap/sys/run/mariadb_ctl/mariadb_ctl.pid
425
source /var/vcap/packages/cf-mysql-common/pid_utils.sh
436

447
set +e
45-
kill_and_wait "${PIDFILE}" 300 0 > /dev/null
8+
kill_and_wait ${PIDFILE} 300 0 > /dev/null
469
return_code=$?
4710

4811
echo 0
4912
exit ${return_code}
50-
5113
<% else %>
5214
echo 0
5315
exit 0

0 commit comments

Comments
 (0)