mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-07-23 13:28:47 +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,55 +14,55 @@ namespace controllers\internals;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to call the console scripts.
|
||||||
|
*/
|
||||||
|
class Console extends \descartes\InternalController
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Class to call the console scripts.
|
* Start launcher daemon.
|
||||||
*/
|
*/
|
||||||
class Console extends \descartes\InternalController
|
public function launcher()
|
||||||
{
|
{
|
||||||
/**
|
new \daemons\Launcher();
|
||||||
* Start launcher daemon.
|
}
|
||||||
*/
|
|
||||||
public function launcher()
|
|
||||||
{
|
|
||||||
new \daemons\Launcher();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start sender daemon.
|
* Start sender daemon.
|
||||||
*/
|
*/
|
||||||
public function sender()
|
public function sender()
|
||||||
{
|
{
|
||||||
new \daemons\Sender();
|
new \daemons\Sender();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start webhook daemon.
|
* Start webhook daemon.
|
||||||
*/
|
*/
|
||||||
public function webhook()
|
public function webhook()
|
||||||
{
|
{
|
||||||
new \daemons\Webhook();
|
new \daemons\Webhook();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start mailer daemon.
|
* Start mailer daemon.
|
||||||
*/
|
*/
|
||||||
public function mailer()
|
public function mailer()
|
||||||
{
|
{
|
||||||
new \daemons\Mailer();
|
new \daemons\Mailer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a phone daemon.
|
* Start a phone daemon.
|
||||||
*
|
*
|
||||||
* @param $id_phone : Phone id
|
* @param $id_phone : Phone id
|
||||||
*/
|
*/
|
||||||
public function phone($id_phone)
|
public function phone($id_phone)
|
||||||
{
|
{
|
||||||
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
||||||
$internal_phone = new \controllers\internals\Phone($bdd);
|
$internal_phone = new \controllers\internals\Phone($bdd);
|
||||||
|
|
||||||
$phone = $internal_phone->get($id_phone);
|
$phone = $internal_phone->get($id_phone);
|
||||||
if (!$phone)
|
if (!$phone)
|
||||||
{
|
{
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,17 +168,19 @@ 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
|
|
||||||
$this->on_stop();
|
|
||||||
|
|
||||||
//Delete pid file
|
|
||||||
if (file_exists($this->pid_dir . '/' . $this->name . '.pid'))
|
|
||||||
{
|
{
|
||||||
unlink($this->pid_dir . '/' . $this->name . '.pid');
|
//Stop the daemon
|
||||||
}
|
$this->on_stop();
|
||||||
|
|
||||||
exit($exit_code ?? 0);
|
//Delete pid file
|
||||||
|
if (file_exists($this->pid_dir . '/' . $this->name . '.pid'))
|
||||||
|
{
|
||||||
|
unlink($this->pid_dir . '/' . $this->name . '.pid');
|
||||||
|
}
|
||||||
|
|
||||||
|
exit($exit_code ?? 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue