|
@ -17,6 +17,7 @@ class Service { |
|
|
/** @var Service\Driver */ |
|
|
/** @var Service\Driver */ |
|
|
protected $drv; |
|
|
protected $drv; |
|
|
protected $loop = false; |
|
|
protected $loop = false; |
|
|
|
|
|
protected $reload = false; |
|
|
|
|
|
|
|
|
public function __construct() { |
|
|
public function __construct() { |
|
|
$driver = Arsse::$conf->serviceDriver; |
|
|
$driver = Arsse::$conf->serviceDriver; |
|
@ -44,6 +45,9 @@ class Service { |
|
|
do { |
|
|
do { |
|
|
sleep((int) max(0, $t->getTimestamp() - time())); |
|
|
sleep((int) max(0, $t->getTimestamp() - time())); |
|
|
pcntl_signal_dispatch(); |
|
|
pcntl_signal_dispatch(); |
|
|
|
|
|
if ($this->hangup) { |
|
|
|
|
|
$this->reload(); |
|
|
|
|
|
} |
|
|
} while ($this->loop && $t->getTimestamp() > time()); |
|
|
} while ($this->loop && $t->getTimestamp() > time()); |
|
|
} |
|
|
} |
|
|
// @codeCoverageIgnoreEnd |
|
|
// @codeCoverageIgnoreEnd |
|
@ -51,6 +55,13 @@ class Service { |
|
|
return $t; |
|
|
return $t; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function reload(): void { |
|
|
|
|
|
$this->reload = false; |
|
|
|
|
|
unset(Arsse::$user, Arsse::$db, Arsse::$conf, Arsse::$lang, Arsse::$obj, $this->drv); |
|
|
|
|
|
Arsse::bootstrap(); |
|
|
|
|
|
$this->__construct(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function checkIn(): bool { |
|
|
public function checkIn(): bool { |
|
|
return Arsse::$db->metaSet("service_last_checkin", time(), "datetime"); |
|
|
return Arsse::$db->metaSet("service_last_checkin", time(), "datetime"); |
|
|
} |
|
|
} |
|
@ -100,6 +111,7 @@ class Service { |
|
|
foreach ([\SIGABRT, \SIGINT, \SIGTERM] as $sig) { |
|
|
foreach ([\SIGABRT, \SIGINT, \SIGTERM] as $sig) { |
|
|
pcntl_signal($sig, [$this, "sigTerm"]); |
|
|
pcntl_signal($sig, [$this, "sigTerm"]); |
|
|
} |
|
|
} |
|
|
|
|
|
pcntl_signal(\SIGHUP, [$this, "sigHup"]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -109,4 +121,11 @@ class Service { |
|
|
protected function sigTerm(int $signo): void { |
|
|
protected function sigTerm(int $signo): void { |
|
|
$this->loop = false; |
|
|
$this->loop = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Changes the condition for the service loop upon receiving a hangup signal |
|
|
|
|
|
* |
|
|
|
|
|
* @codeCoverageIgnore */ |
|
|
|
|
|
protected function sigHup(int $signo): void { |
|
|
|
|
|
$this->hangup = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|