Skip to content

Instantly share code, notes, and snippets.

@reanim8ed
Last active November 18, 2024 17:36
Show Gist options
  • Save reanim8ed/90ef909ef3fc66b812a62d54e4bf2178 to your computer and use it in GitHub Desktop.
Save reanim8ed/90ef909ef3fc66b812a62d54e4bf2178 to your computer and use it in GitHub Desktop.
[Autorestart mysql] #mysql

crontab -e

*/5 * * * * service mysql status > /dev/null || service mysql start

OR

/home/scripts/mysqlmon.sh

#!/bin/bash

# Check if MySQL is running
sudo service mysql status > /dev/null 2>&1

# Restart the MySQL service if it's not running.
if [ $? != 0 ]; then
    echo -e "MySQL Service was down. Restarting now...\n"
    sudo service mysql restart
else
    echo -e "MySQL Service is running already. Nothing to do here.\n"
fi

sudo chmod +x mysqlmon.sh crontab -e

* * * * * /home/scripts/mysqlmon.sh > /dev/null 2>&1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment