Skip to content

Instantly share code, notes, and snippets.

@MattHealy
Last active April 26, 2016 09:14
Show Gist options
  • Save MattHealy/d0e4168132f93759271f918270744b80 to your computer and use it in GitHub Desktop.
Save MattHealy/d0e4168132f93759271f918270744b80 to your computer and use it in GitHub Desktop.
Check if MySQL/MariaDB is down, and if so, restart it.
#!/bin/sh
PORT=3306
HP=:$PORT
echo 'Checking to see if MariaDB is up...'
if ( /usr/sbin/lsof -Pni $HP | grep "$PORT (LISTEN)" 2>&1 >/dev/null ); then
echo 'MariaDB is up';
else
echo 'MariaDB is down, restarting...';
/sbin/service mariadb restart
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment