Integrated and fixed gracetime/graceline logic

This commit is contained in:
pezcurrel 2024-01-02 00:40:26 +01:00
parent 618ebfa54b
commit b9ab074e1c

View file

@ -23,7 +23,7 @@ define('CHILD','getinstinfo.php');
define('LIBDP','/../lib'); define('LIBDP','/../lib');
require __DIR__.LIBDP.'/ght.php'; require __DIR__.LIBDP.'/ght.php';
require __DIR__.LIBDP.'/gracetime.php'; require __DIR__.LIBDP.'/grace.php';
require __DIR__.LIBDP.'/parsetime.php'; require __DIR__.LIBDP.'/parsetime.php';
use function mysqli_real_escape_string as myesc; use function mysqli_real_escape_string as myesc;
@ -71,8 +71,8 @@ OPTIONS
time. time.
DEFAULT: '.ght($opts['gracetime'],null,0).' DEFAULT: '.ght($opts['gracetime'],null,0).'
-G, --graceline -G, --graceline
Return the “graceline” (now - gracetime: see option above) in unix time and Return the “graceline” (0:0:0 of today minus gracetime: see option above) in
local time, then exit. unix time and local time, then exit.
-p, --peersfp <file> -p, --peersfp <file>
Defines the path to a file containing a list of instances to consider in Defines the path to a file containing a list of instances to consider in
addition to those which are already present in the database. Note that this addition to those which are already present in the database. Note that this
@ -135,8 +135,7 @@ for ($i=1; $i<$argc; $i++) {
$i++; $i++;
$opts['gracetime']=$time; $opts['gracetime']=$time;
} elseif ($argv[$i]=='-G' || $argv[$i]=='--graceline') { } elseif ($argv[$i]=='-G' || $argv[$i]=='--graceline') {
$graceline=time()-$opts['gracetime']; echo 'Graceline: '.$graceline.' ('.date('Y-m-d H:i:s',$graceline).').'.N;
echo('Graceline: '.$graceline.' ('.date('Y-m-d H:i:s',$graceline).').'.N);
exit(0); exit(0);
} elseif ($argv[$i]=='-p' || $argv[$i]=='--peersfp') { } elseif ($argv[$i]=='-p' || $argv[$i]=='--peersfp') {
if ($i+1>=$argc || !file_exists($argv[$i+1]) || !is_file($argv[$i+1]) || !is_readable($argv[$i+1])) if ($i+1>=$argc || !file_exists($argv[$i+1]) || !is_file($argv[$i+1]) || !is_readable($argv[$i+1]))
@ -165,8 +164,6 @@ for ($i=1; $i<$argc; $i++) {
} }
} }
$graceline=time()-$opts['gracetime'];
$rundirpath=__DIR__.'/run'; $rundirpath=__DIR__.'/run';
$lockfp=$rundirpath.'/'.FNAME.'.lock'; $lockfp=$rundirpath.'/'.FNAME.'.lock';
@ -241,7 +238,7 @@ if ($restore) {
$insts=[]; $insts=[];
eecho(0,'loading instances from the database...'.N); eecho(0,'loading instances from the database...'.N);
$res=myq($link,'SELECT URI FROM Instances WHERE LastOkCheckTS>='.$graceline.' OR (LastOkCheckTS IS NULL AND InsertTS>='.$graceline.')',__LINE__); $res=myq($link,'SELECT URI FROM Instances WHERE LastOkCheckTS IS NOT NULL AND LastOkCheckTS>='.$graceline,__LINE__);
while($row=mysqli_fetch_assoc($res)) while($row=mysqli_fetch_assoc($res))
if (!in_array($row['URI'],$insts)) if (!in_array($row['URI'],$insts))
$insts[]=$row['URI']; $insts[]=$row['URI'];
@ -249,7 +246,7 @@ if ($restore) {
if (!is_null($opts['peersfp'])) { if (!is_null($opts['peersfp'])) {
eecho(0,'loading “dead” instances from the database...'.N); eecho(0,'loading “dead” instances from the database...'.N);
$res=myq($link,'SELECT URI FROM Instances WHERE LastOkCheckTS<'.$graceline.' OR (LastOkCheckTS IS NULL AND InsertTS<'.$graceline.')',__LINE__); $res=myq($link,'SELECT URI FROM Instances WHERE LastOkCheckTS IS NULL OR LastOkCheckTS<'.$graceline,__LINE__);
$deadinsts=[]; $deadinsts=[];
while($row=mysqli_fetch_assoc($res)) while($row=mysqli_fetch_assoc($res))
if (!in_array($row['URI'],$deadinsts)) if (!in_array($row['URI'],$deadinsts))