scanps fixes

This commit is contained in:
myvesta 2022-11-09 17:04:10 +01:00 committed by GitHub
commit 7e37ed4711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View file

@ -1,10 +1,12 @@
<?php <?php
/* // The script is checking if MySQL/MariaDB server process is up.
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.
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.
It can detect 'apt upgrade' process and avoid a reboot.
*/ // You can put this script in cronjob every 5 minutes:
// Run 'crontab -e' and add the following:
// */5 * * * * php /home/scanps.php > /dev/null 2>&1
function my_exec($command) { function my_exec($command) {
$out=array(); $out=array();
@ -37,21 +39,21 @@ if ($v1==false && $v2==false) {
echo "- reboot\n"; echo "- reboot\n";
$buffer="- reboot\n".$list; $buffer="- reboot\n".$list;
$sufix="_".time(); $sufix="_".time();
$fp = fopen('/home/cron'.$sufix.'.log', 'w'); $fp = fopen('/var/log/scanps_cron'.$sufix.'.log', 'w');
fwrite($fp, $buffer); fwrite($fp, $buffer);
fclose($fp); fclose($fp);
$out=array(); $out=array();
$ret_no=0; $ret_no=0;
$uname_arr=posix_uname(); $uname_arr=posix_uname();
$hostname=$uname_arr['nodename']; $hostname=$uname_arr['nodename'];
$email=my_exec("/usr/local/vesta/bin/v-list-user 'admin' | grep 'EMAIL' | awk '{print $2}'"); $email=my_exec("export VESTA=/usr/local/vesta && /usr/local/vesta/bin/v-list-user 'admin' | grep 'EMAIL' | awk '{print $2}'");
mail($email, 'VPS reboot - '.$hostname, $buffer, "From: ".$hostname." <admin@".$hostname.">"); mail($email, 'VPS reboot - '.$hostname, $buffer, "From: ".$hostname." <admin@".$hostname.">");
sleep(10); sleep(10);
$ret = exec("sudo reboot", $out, $ret_no); $ret = exec("sudo reboot", $out, $ret_no);
exit; exit;
} else { } else {
echo "- mysql ok\n"; echo "- mysql ok\n";
$fp = fopen('/home/cron.log', 'w'); $fp = fopen('/var/log/scanps_cron.log', 'w');
fwrite($fp, "- mysql ok"); fwrite($fp, "- mysql ok");
fclose($fp); fclose($fp);
exit; exit;

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# run 'crontab -e' and add the following: # run 'crontab -e' and add the following:
# 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/scanps.sh > /dev/null 2>&1 # */5 * * * * /home/scanps.sh > /dev/null 2>&1
cd /home cd /home
php scanps.php php scanps.php