Created
January 30, 2018 09:25
-
-
Save vladbabii/cdc0f705e589b0b19bb9321ccdb6709e to your computer and use it in GitHub Desktop.
MariaDB Galera 10.1+ Cluster Check and Restart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STFAILED="failed" | |
STRUNNING="active" | |
STSTOPPED="stopped" | |
STSTARTING="starting" | |
CMDBOOTSTRAP="/usr/bin/galera_new_cluster" | |
CMDSTART="systemctl start mysql" | |
STARTWAIT=15 | |
GRFILE="/var/lib/mysql/grastate.dat" | |
GRSAFE="safe_to_bootstrap: 1" | |
STATUS="$(systemctl is-active mysql)" | |
if [ "$STATUS" == "STRUNNING" ] | |
then | |
echo "running. all ok." | |
exit | |
fi | |
if [ "$STATUS" == "$STFAILED" ] | |
then | |
echo "Trying to start normally...." | |
eval $CMDSTART | |
sleep $STARTWAIT | |
STATUS="$(systemctl is-active mysql)" | |
fi | |
if [ "$STATUS" == "STRUNNING" ] | |
then | |
echo "running. all ok." | |
exit | |
fi | |
if [ "$STATUS" == "$STFAILED" ] | |
then | |
echo "Status is failed, checking grastate for safe_to_bootstrap.." | |
if [ -f $GRFILE ]; then | |
echo "Grfile exists..." | |
if grep -q "$GRSAFE" "$GRFILE"; then | |
echo "Node is ok for bootstrapping..." | |
eval $CMDBOOTSTRAP | |
else | |
echo "This node cannot be bootstrapped" | |
fi | |
else | |
echo "Grfile $GRFILE is missing :(" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment