Created
February 21, 2014 17:21
-
-
Save turtlemonvh/9138770 to your computer and use it in GitHub Desktop.
Register this as a crontab to run every hour to check if mysql had a hard time restarting. If so, it may be because this was brought down quickly. Use `sudo crontab -e` when creating the crontab because it needs to run as root to be able to move the pid files and restart the service.
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
#!/usr/bin/env python | |
import os | |
import subprocess | |
child = subprocess.Popen('service mysqld status', shell=True, stdout=subprocess.PIPE) | |
# Capture output string | |
outstr = '' | |
while True: | |
out = child.stdout.read(1) | |
if out == '' and child.poll() != None: | |
break | |
if out != '': | |
outstr +=out | |
# Is it running? | |
if 'is running' not in outstr: | |
# There's a problem | |
# http://stackoverflow.com/questions/20407292/centos-another-mysql-daemon-already-running-with-the-same-unix-socket | |
# sudo mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak | |
os.rename('/var/lib/mysql/mysql.sock', '/var/lib/mysql/mysql.sock.bak') | |
# Now restart it | |
subprocess.Popen('service mysqld start', shell=True) | |
print "Attempted to restart mysql" | |
else: | |
print "Everything looks fine here" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment