From aa493287f3b77aba380e3cd9cf0d8cc39a9fb0da Mon Sep 17 00:00:00 2001 From: myvesta <38690722+myvesta@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:15:48 +0100 Subject: [PATCH] Create scanps.php --- src/deb/for-download/tools/scanps/scanps.php | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/deb/for-download/tools/scanps/scanps.php diff --git a/src/deb/for-download/tools/scanps/scanps.php b/src/deb/for-download/tools/scanps/scanps.php new file mode 100644 index 00000000..7b52064d --- /dev/null +++ b/src/deb/for-download/tools/scanps/scanps.php @@ -0,0 +1,58 @@ + ")!==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." "); + 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; +}