Skip to content

Instantly share code, notes, and snippets.

@jmillerdesign
Last active February 28, 2017 23:46
Show Gist options
  • Save jmillerdesign/ce2bcb41ef0630be9fd3 to your computer and use it in GitHub Desktop.
Save jmillerdesign/ce2bcb41ef0630be9fd3 to your computer and use it in GitHub Desktop.
#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
if [[ $(service mysql status | grep running | wc -l) != 1 ]];
then
echo "$(date "+%Y-%m-%d %T")" >> /root/keep-mysql-running.log
echo "$(service mysql status)" >> /root/keep-mysql-running.log
service mysql start >> /root/keep-mysql-running.log
fi
----------------------------------------------------------------------
#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
if [[ $(ps -ef | grep "/usr/sbin/mysqld" | grep -v "grep" | wc -l) != 1 ]];
then
echo "$(date "+%Y-%m-%d %T")" >> /root/keep-mysql-running.log
echo "$(service mysql status)" >> /root/keep-mysql-running.log
service mysql restart >> /root/keep-mysql-running.log
fi
@jmillerdesign
Copy link
Author

Run this on a cron job to start mysql if it ever detects it as not running:

# Keep MySQL running
* * * * * /root/keep-mysql-running.sh

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