Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
onlineCheck (#52)
Browse files Browse the repository at this point in the history
Added some usefull info and updated the deployment.yaml
  • Loading branch information
Rub& committed Jul 18, 2019
1 parent 757ddb1 commit d941cf3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
43 changes: 43 additions & 0 deletions docker/files/cli/commands/cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ command_init() {

sleep 5

command_sync:checkOnline

touch /proxysql-ready
}

Expand Down Expand Up @@ -248,3 +250,44 @@ command_sync:cluster() {

sleep 1
}

commands_add "sync:checkOnline" "Check if all available servers are online"
command_sync:checkOnline() {

echo -e "\e[33m Check added MySQL servers \e[0m"

confTotal=$(
proxysql_execute_query "
SELECT COUNT (*) FROM mysql_servers;
";
)
echo -e "\e[33m The number of servers found is" $confTotal "in total \e[0m"

sleep 5

echo -e "\e[33m Check current state of all available servers \e[0m"

proxysql_execute_query "
SELECT hostgroup_id,hostname,status FROM mysql_servers;
" | while read hostgroup_id hostname status; do
# use $hostgroup_id and $status variables
echo "Checking - hostID: $hostgroup_id, hostname: $hostname, status: $status"
# when working with a service "status" as indicator isn't always right
if mysqladmin ping -u${MYSQL_ADMIN_USERNAME} -p${MYSQL_ADMIN_PASSWORD} -h$hostname; then
echo -e "\e[33m $hostname is operating normaly \e[0m"
else
echo -e "\e[33m $hostname is not active \e[0m"
foundTotal=$((foundTotal + 1))
echo -e "\e[33m Found:" $foundTotal " offline server(s), out of " $confTotal " server(s) total \e[0m"
if [ $foundTotal = $confTotal ]; then
# All servers are Offline
echo -e "\e[33m All servers are offline, this container is unhealthy. \e[0m"
# lets exit this container using liveness probe
rm -rf /proxysql-liveness
echo -e "\e[33m Liveness state updated to destroy this container. \e[0m"
fi
fi
done

sleep 1
}
2 changes: 2 additions & 0 deletions docker/files/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -e

touch /proxysql-liveness

if [[ ! -z $CONFIG_TEMPLATE && -s "$CONFIG_TEMPLATE" ]]; then
envsubst < $CONFIG_TEMPLATE > /etc/proxysql.cnf
echo "Replaced content and variables from $CONFIG_TEMPLATE into /etc/proxysql.cnf"
Expand Down
12 changes: 12 additions & 0 deletions k8s/proxysql.statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ spec:
- cat
- /proxysql-ready

livenessProbe:
failureThreshold: 1
initialDelaySeconds: 20
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 2

exec:
command:
- cat
- /proxysql-liveness

args: [ "--cluster" ]

volumeMounts:
Expand Down

0 comments on commit d941cf3

Please sign in to comment.