add dedicated log dir for raspisms
This commit is contained in:
parent
ca9397b62d
commit
1be127e260
|
@ -3,7 +3,7 @@
|
|||
# Script to start RaspiSMS daemons
|
||||
#
|
||||
PID_DIR="/var/run/raspisms/"
|
||||
LOG_FILE="/var/log/raspisms.log"
|
||||
LOG_FILE="/var/log/raspisms/daemons.log"
|
||||
SCRIPT=$(readlink -f "$0")
|
||||
RASPISMS_DIR=$(readlink -f "${SCRIPT%/*}/../")
|
||||
CONSOLE_PATH="$RASPISMS_DIR/console.php"
|
||||
|
|
|
@ -11,11 +11,15 @@
|
|||
|
||||
namespace controllers\publics;
|
||||
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Controller of callback pages, like sms status update notification.
|
||||
*/
|
||||
class Callback extends \descartes\Controller
|
||||
{
|
||||
private $logger;
|
||||
private $user;
|
||||
private $internal_user;
|
||||
private $internal_sended;
|
||||
|
@ -29,8 +33,12 @@ namespace controllers\publics;
|
|||
$this->internal_sended = new \controllers\internals\Sended($bdd);
|
||||
$this->internal_adapter = new \controllers\internals\Adapter();
|
||||
|
||||
//Logger
|
||||
$this->logger = new Logger('Callback ' . uniqid());
|
||||
$this->logger->pushHandler(new StreamHandler(PWD_LOGS . '/callback.log', Logger::DEBUG));
|
||||
|
||||
//If no user, quit with error
|
||||
|
||||
//If invalid api key, quit with error
|
||||
$this->user = false;
|
||||
$api_key = $_GET['api_key'] ?? false;
|
||||
if ($api_key)
|
||||
|
@ -42,8 +50,11 @@ namespace controllers\publics;
|
|||
{
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'Invalid API key. You must provide a valid GET or POST api_key param.']);
|
||||
$this->logger->error('Callback call failed with invalid api key : ' . $api);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$this->logger->info('Callback call succed for user id : ' . $this->user['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,6 +66,8 @@ namespace controllers\publics;
|
|||
*/
|
||||
public function update_sended_status(string $adapter_name)
|
||||
{
|
||||
$this->logger->info('Callback status call with adapter name : ' . $adapter_name);
|
||||
|
||||
//Search for an adapter
|
||||
$find_adapter = false;
|
||||
$adapters = $this->internal_adapter->list_adapters();
|
||||
|
@ -68,6 +81,7 @@ namespace controllers\publics;
|
|||
|
||||
if (false === $find_adapter)
|
||||
{
|
||||
$this->logger->error('Callback status use non existing adapter : ' . $adapter_name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -75,21 +89,25 @@ namespace controllers\publics;
|
|||
$adapter_classname = $find_adapter['meta_classname'];
|
||||
if (!$find_adapter['meta_support_status_change'])
|
||||
{
|
||||
$this->logger->error('Callback status use adapter ' . $adapter_name . ' which does not support status change.');
|
||||
return false;
|
||||
}
|
||||
|
||||
$callback_return = $adapter_classname::status_change_callback();
|
||||
if (!$callback_return)
|
||||
{
|
||||
$this->logger->error('Callback status with adapter ' . $adapter_name . ' failed on adapter compute.');
|
||||
return false;
|
||||
}
|
||||
|
||||
$sended = $this->internal_sended->get_by_uid_and_adapter($callback_return['uid'], $adapter_classname);
|
||||
if (!$sended)
|
||||
{
|
||||
$this->logger->error('Callback status try update inexisting message with uid = ' . $callback_return['uid'] . '.');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->logger->info('Callback status update message with uid ' . $callback_return['uid'] . '.');
|
||||
$this->internal_sended->update_status($sended['id'], $callback_return['status']);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -29,7 +29,7 @@ class Launcher extends AbstractDaemon
|
|||
$name = 'RaspiSMS Daemon Launcher';
|
||||
|
||||
$logger = new Logger($name);
|
||||
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/raspisms.log', Logger::DEBUG));
|
||||
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/daemons.log', Logger::DEBUG));
|
||||
$pid_dir = PWD_PID;
|
||||
$no_parent = true; //Launcher should be rattach to PID 1
|
||||
$additional_signals = [];
|
||||
|
|
|
@ -40,7 +40,7 @@ class Phone extends AbstractDaemon
|
|||
|
||||
$name = 'RaspiSMS Daemon Phone ' . $this->phone['id'];
|
||||
$logger = new Logger($name);
|
||||
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/raspisms.log', Logger::DEBUG));
|
||||
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/daemons.log', Logger::DEBUG));
|
||||
$pid_dir = PWD_PID;
|
||||
$no_parent = false; //Phone should be rattach to manager, so manager can stop him easily
|
||||
$additional_signals = [];
|
||||
|
|
|
@ -29,7 +29,7 @@ class Sender extends AbstractDaemon
|
|||
{
|
||||
$name = 'RaspiSMS Daemon Sender';
|
||||
$logger = new Logger($name);
|
||||
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/raspisms.log', Logger::DEBUG));
|
||||
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/daemons.log', Logger::DEBUG));
|
||||
$pid_dir = PWD_PID;
|
||||
$no_parent = false; //Webhook should be rattach to manager, so manager can stop him easily
|
||||
$additional_signals = [];
|
||||
|
|
|
@ -34,7 +34,7 @@ class Webhook extends AbstractDaemon
|
|||
{
|
||||
$name = 'RaspiSMS Daemon Webhook';
|
||||
$logger = new Logger($name);
|
||||
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/raspisms.log', Logger::DEBUG));
|
||||
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/daemons.log', Logger::DEBUG));
|
||||
$pid_dir = PWD_PID;
|
||||
$no_parent = false; //Sended should be rattach to manager, so manager can stop him easily
|
||||
$additional_signals = [];
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
'HTTP_PWD_SOUND' => HTTP_PWD_ASSETS . '/sounds',
|
||||
'PWD_ADAPTERS' => PWD . '/adapters',
|
||||
'PWD_DATAS' => PWD . '/datas',
|
||||
'PWD_LOGS' => '/var/log/',
|
||||
'PWD_LOGS' => '/var/log/raspisms',
|
||||
'PWD_PID' => '/var/run/raspisms',
|
||||
'APP_SECRET' => '%APP_SECRET%',
|
||||
|
||||
|
|
Loading…
Reference in New Issue