Last active
April 11, 2016 13:51
-
-
Save LauLaman/1738a8ad4d633254aef6 to your computer and use it in GitHub Desktop.
Start mysql if its not running
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
#!/bin/bash | |
# Author: Laurens Laman | |
# Date: 2015-12-27 | |
# URL: https://gist.github.com/LauLaman/1738a8ad4d633254aef6 | |
# | |
# DESCRIPTION | |
# Sometimes MySQL randomly stops for no apparent reason. This can be an extreme pain in the * | |
# Use this scripts to start mysql when its not running. To make your life easy again. | |
# | |
# INSTRUCTIONS | |
# Stop mysql manualy (service mysql stop) and check the status message (service mysql status) | |
# Check if part of the status message is in the if statement below, if not add it and comment so i can update the script | |
# Run the script by hand and check if mysql is started | |
# Add script to cron: (run every minute) | |
# */1 * * * * /var/scripts/mysqlfix.sh > /var/logs/mysqlfix.log | |
mysqlStatus="$(service mysql status)"; | |
if ([[ $mysqlStatus =~ "not running" ]] || [[ $mysqlStatus =~ "is stopped" ]] || [[ $mysqlStatus =~ "stop/waiting" ]]) | |
then | |
echo "$(date +"%Y-%m-%d %T") -> MySQL is DOWN :( RESTARTING MySQL " | |
service mysql start > /dev/null | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment