mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-07-24 22:08:45 +02:00
Properly handle error on stop and start daemons
This commit is contained in:
parent
1f8cdcd67c
commit
08cbb0f12e
2 changed files with 56 additions and 54 deletions
|
@ -14,11 +14,11 @@ namespace controllers\internals;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to call the console scripts.
|
* Class to call the console scripts.
|
||||||
*/
|
*/
|
||||||
class Console extends \descartes\InternalController
|
class Console extends \descartes\InternalController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Start launcher daemon.
|
* Start launcher daemon.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -150,12 +150,12 @@ abstract class AbstractDaemon
|
||||||
//Write the pid of the process into a file
|
//Write the pid of the process into a file
|
||||||
file_put_contents($this->pid_dir . '/' . $this->name . '.pid', getmypid());
|
file_put_contents($this->pid_dir . '/' . $this->name . '.pid', getmypid());
|
||||||
|
|
||||||
//Really start the daemon
|
|
||||||
$this->on_start();
|
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//Really start the daemon
|
||||||
|
$this->on_start();
|
||||||
|
|
||||||
while ($this->is_running)
|
while ($this->is_running)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -168,7 +168,8 @@ abstract class AbstractDaemon
|
||||||
$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;
|
$exit_code = $t->getCode() ?: 1;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
//Stop the daemon
|
//Stop the daemon
|
||||||
$this->on_stop();
|
$this->on_stop();
|
||||||
|
|
||||||
|
@ -180,6 +181,7 @@ abstract class AbstractDaemon
|
||||||
|
|
||||||
exit($exit_code ?? 0);
|
exit($exit_code ?? 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override to implement the code that run infinetly (actually, it run one time but repeat the operation infinetly.
|
* Override to implement the code that run infinetly (actually, it run one time but repeat the operation infinetly.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue