-
Notifications
You must be signed in to change notification settings - Fork 1
/
watchDog.php
40 lines (36 loc) · 1.41 KB
/
watchDog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
function value_in($element_name, $xml, $content_only = true)
{
if ($xml == false) {
return false;
}
$found = preg_match('#<'.$element_name.'(?:\s+[^>]+)?>(.*?)'.
'</'.$element_name.'>#s', $xml, $matches);
if ($found != false) {
if ($content_only) {
return $matches[1]; //ignore the enclosing tags
} else {
return $matches[0]; //return the full pattern match
}
}
// No match found: return false.
return false;
}
$xml = exec('curl -s --connect-timeout 3 --max-time 3 http://localhost/?ElectronicScales=1');
$value = value_in('Value',$xml); //var_dump(is_float($value)); die;
if (strlen($value)<2) {
`sudo pkill python`;
sleep(1);
`git --work-tree="/home/pi/PiCons/" checkout settings.ini`;
`sudo python /home/pi/PiCons/main.py > /dev/null 2>&1 &`;
file_put_contents('/home/pi/PiCons/watchDog.log',date("Y-m-d H:i:s") . " - restarted ... \n", FILE_APPEND);
exit;
}
// 20 % от пусканията рестартираме PiCons сървъра, защото по незнайни причини се губи теглото.
if (rand(1,5)%4 == 0) {
`sudo pkill python`;
sleep(1);
`sudo python /home/pi/PiCons/main.py > /dev/null 2>&1 &`;
file_put_contents('/home/pi/PiCons/watchDog.log',date("Y-m-d H:i:s") . " - RAND restarted ... \n", FILE_APPEND);
}
// file_put_contents('/home/pi/PiCons/watchDog.log',date("Y-m-d H:i:s") . " - OK ... \n", FILE_APPEND);