Skip to content

Instantly share code, notes, and snippets.

@allanlaal
Created March 11, 2014 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allanlaal/9491720 to your computer and use it in GitHub Desktop.
Save allanlaal/9491720 to your computer and use it in GitHub Desktop.
<?php
/**
* @desc MySQL restarter
* @example # /root/scripts/mysql_restarter.php >> /root/scripts/mysql_restarter.log
* @author Allan Laal <allan@permanent.ee>
* @since 2013-10-05
* @version DIRTY
*/
// monitortest can be an unprivileged user:
$connection_result = mysql_connect('localhost', 'monitortest', 'INSERT_PASSWORD_HERE');
if ($connection_result === FALSE)
{
echo date('Y-m-d H:i:s')." MySQL is DOWN, attempting restart\n";
exec(
'PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'.";\n".
'/usr/sbin/service mysql restart >> /root/scripts/mysql_restarter.log'.";\n"
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment