Better handling of raspisms service restart after exception in daemons, and add 5 seconds delay between restart retries

This commit is contained in:
osaajani 2025-07-15 23:59:12 +02:00
parent aaa0fe5701
commit 1f8cdcd67c
3 changed files with 7 additions and 1 deletions

View file

@ -11,6 +11,7 @@ ExecStart=/usr/share/raspisms/bin/start.sh
ExecStop=/usr/share/raspisms/bin/stop.sh ExecStop=/usr/share/raspisms/bin/stop.sh
WorkingDirectory=/usr/share/raspisms WorkingDirectory=/usr/share/raspisms
Restart=on-failure Restart=on-failure
RestartSec=5
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -18,7 +18,7 @@ use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\SMTP;
/** /**
* Mailing class. * Link shortner class.
*/ */
class LinkShortener class LinkShortener
{ {

View file

@ -153,10 +153,12 @@ abstract class AbstractDaemon
//Really start the daemon //Really start the daemon
$this->on_start(); $this->on_start();
try try
{ {
while ($this->is_running) while ($this->is_running)
{ {
pcntl_signal_dispatch(); //Call dispatcher for signals pcntl_signal_dispatch(); //Call dispatcher for signals
$this->run(); $this->run();
} }
@ -164,6 +166,7 @@ abstract class AbstractDaemon
catch (\Throwable $t) catch (\Throwable $t)
{ {
$this->logger->critical('Exception : ' . $t->getMessage() . ' in ' . $t->getFile() . ' line ' . $t->getLine()); $this->logger->critical('Exception : ' . $t->getMessage() . ' in ' . $t->getFile() . ' line ' . $t->getLine());
$exit_code = $t->getCode() ?: 1;
} }
//Stop the daemon //Stop the daemon
@ -174,6 +177,8 @@ abstract class AbstractDaemon
{ {
unlink($this->pid_dir . '/' . $this->name . '.pid'); unlink($this->pid_dir . '/' . $this->name . '.pid');
} }
exit($exit_code ?? 0);
} }
/** /**