mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-22 06:14:19 -07:00
Create scanps.php
This commit is contained in:
parent
8d4eee37d0
commit
aa493287f3
1 changed files with 58 additions and 0 deletions
58
src/deb/for-download/tools/scanps/scanps.php
Normal file
58
src/deb/for-download/tools/scanps/scanps.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
The script is checking if MySQL/MariaDB server process is up.
|
||||||
|
If it's not, it assumes that it was killed by Kernel OOM Killer, and reboots the server, in order to bring the back server to a normal state.
|
||||||
|
It can detect 'apt upgrade' process and avoid a reboot.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function my_exec($command) {
|
||||||
|
$out=array();
|
||||||
|
$ret_no=0;
|
||||||
|
if (strpos($command, " > ")!==FALSE) $command.=" 2> /dev/null";
|
||||||
|
else {
|
||||||
|
if (strpos($command, " 2>&1")===FALSE) $command.=" 2>&1";
|
||||||
|
}
|
||||||
|
$ret = exec($command, $out, $ret_no);
|
||||||
|
return implode("\n", $out);
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_there($list, $what) {
|
||||||
|
$arr=explode("\n", $list);
|
||||||
|
$c=count($arr);
|
||||||
|
for ($i=1; $i<$c; $i++) if (strpos($arr[$i], $what)!==false) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$list=my_exec("ps -Af");
|
||||||
|
if (is_there($list, "apt")) exit; // the server is in upgrading proccess
|
||||||
|
|
||||||
|
$search_for1="mysqld";
|
||||||
|
$search_for2="mariadbd";
|
||||||
|
$v1=is_there($list, $search_for1);
|
||||||
|
$v2=is_there($list, $search_for2);
|
||||||
|
$sufix="";
|
||||||
|
|
||||||
|
if ($v1==false && $v2==false) {
|
||||||
|
echo "- reboot\n";
|
||||||
|
$buffer="- reboot\n".$list;
|
||||||
|
$sufix="_".time();
|
||||||
|
$fp = fopen('/home/cron'.$sufix.'.log', 'w');
|
||||||
|
fwrite($fp, $buffer);
|
||||||
|
fclose($fp);
|
||||||
|
$out=array();
|
||||||
|
$ret_no=0;
|
||||||
|
$uname_arr=posix_uname();
|
||||||
|
$hostname=$uname_arr['nodename'];
|
||||||
|
$email=my_exec("/usr/local/vesta/bin/v-list-user 'admin' | grep 'EMAIL' | awk '{print $2}'");
|
||||||
|
mail($email, 'VPS reboot - '.$hostname, $buffer, "From: ".$hostname." <admin@".$hostname.">");
|
||||||
|
sleep(10);
|
||||||
|
$ret = exec("sudo reboot", $out, $ret_no);
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
echo "- mysql ok\n";
|
||||||
|
$fp = fopen('/home/cron.log', 'w');
|
||||||
|
fwrite($fp, "- mysql ok");
|
||||||
|
fclose($fp);
|
||||||
|
exit;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue