mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Handle hangup signal
This commit is contained in:
parent
88fe3e76cb
commit
37c58e186a
4 changed files with 28 additions and 5 deletions
|
@ -25,8 +25,7 @@ if (\PHP_SAPI === "cli") {
|
|||
exit($exitStatus);
|
||||
} else {
|
||||
// load configuration
|
||||
$conf = file_exists(BASE."config.php") ? new Conf(BASE."config.php") : new Conf;
|
||||
Arsse::load($conf);
|
||||
Arsse::bootstrap();
|
||||
// handle Web requests
|
||||
$emitter = new \Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
|
||||
$response = (new REST)->dispatch();
|
||||
|
|
|
@ -29,6 +29,12 @@ class Arsse {
|
|||
/** @var User */
|
||||
public static $user;
|
||||
|
||||
/** @codeCoverageIgnore */
|
||||
public static function bootstrap(): void {
|
||||
$conf = file_exists(BASE."config.php") ? new Conf(BASE."config.php") : new Conf;
|
||||
static::load($conf);
|
||||
}
|
||||
|
||||
public static function load(Conf $conf): void {
|
||||
static::$obj = static::$obj ?? new Factory;
|
||||
static::$lang = static::$lang ?? new Lang;
|
||||
|
|
|
@ -61,8 +61,7 @@ USAGE_TEXT;
|
|||
|
||||
/** @codeCoverageIgnore */
|
||||
protected function loadConf(): bool {
|
||||
$conf = file_exists(BASE."config.php") ? new Conf(BASE."config.php") : new Conf;
|
||||
Arsse::load($conf);
|
||||
Arsse::bootstrap();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ class Service {
|
|||
/** @var Service\Driver */
|
||||
protected $drv;
|
||||
protected $loop = false;
|
||||
protected $reload = false;
|
||||
|
||||
public function __construct() {
|
||||
$driver = Arsse::$conf->serviceDriver;
|
||||
|
@ -44,6 +45,9 @@ class Service {
|
|||
do {
|
||||
sleep((int) max(0, $t->getTimestamp() - time()));
|
||||
pcntl_signal_dispatch();
|
||||
if ($this->hangup) {
|
||||
$this->reload();
|
||||
}
|
||||
} while ($this->loop && $t->getTimestamp() > time());
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
@ -51,6 +55,13 @@ class Service {
|
|||
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 {
|
||||
return Arsse::$db->metaSet("service_last_checkin", time(), "datetime");
|
||||
}
|
||||
|
@ -100,6 +111,7 @@ class Service {
|
|||
foreach ([\SIGABRT, \SIGINT, \SIGTERM] as $sig) {
|
||||
pcntl_signal($sig, [$this, "sigTerm"]);
|
||||
}
|
||||
pcntl_signal(\SIGHUP, [$this, "sigHup"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,4 +121,11 @@ class Service {
|
|||
protected function sigTerm(int $signo): void {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue