File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change 11#! /bin/bash
2- set -eu
2+ set -u
33
44# This secret is mounted by k8s and always up to date
55read -s -u 3 3< /var/lib/secrets/dbpassword MYSQL_PWD || true
66export MYSQL_PWD
77
88PROBE_USER=root
9+ function mysql_status_check {
10+ local status=$1
11+ local expect=$2
12+ set -x
13+ mysql -u${PROBE_USER} -sNEe " show status like '${status} ';" | tail -1 | grep -w -e " ${expect} "
14+ }
915
1016# Consider the pod has "started" once mysql is reachable
17+ # and is part of the primary partition
1118if [ " $1 " = " startup" ]; then
12- mysql -u ${PROBE_USER} -sNe " select(1); "
19+ mysql_status_check wsrep_cluster_status Primary
1320 exit $?
1421fi
1522
16- set -x
23+ # readiness and liveness probes are run by k8s only after start probe succeeded
1724
1825case " $1 " in
1926 readiness)
2027 # If the node is e.g. a donor, it cannot serve traffic
21- mysql -u${PROBE_USER} -sNe " show status like 'wsrep_local_state_comment';" | grep -w -e Synced;;
28+ mysql_status_check wsrep_local_state_comment Synced
29+ ;;
2230 liveness)
23- # If the node is not in the primary partition, restart it
24- mysql -u${PROBE_USER} -sNe " show status like 'wsrep_cluster_status';" | grep -w -e Primary;;
31+ # If the node is not in the primary partition, the failed liveness probe
32+ # will make k8s restart this pod
33+ mysql_status_check wsrep_cluster_status Primary
34+ ;;
2535 * )
2636 echo " Invalid probe option '$1 '"
2737 exit 1;;
You can’t perform that action at this time.
0 commit comments