add dedicated log dir for raspisms

This commit is contained in:
osaajani 2020-03-04 04:18:26 +01:00
parent ca9397b62d
commit 1be127e260
7 changed files with 26 additions and 8 deletions

View File

@ -3,7 +3,7 @@
# Script to start RaspiSMS daemons # Script to start RaspiSMS daemons
# #
PID_DIR="/var/run/raspisms/" PID_DIR="/var/run/raspisms/"
LOG_FILE="/var/log/raspisms.log" LOG_FILE="/var/log/raspisms/daemons.log"
SCRIPT=$(readlink -f "$0") SCRIPT=$(readlink -f "$0")
RASPISMS_DIR=$(readlink -f "${SCRIPT%/*}/../") RASPISMS_DIR=$(readlink -f "${SCRIPT%/*}/../")
CONSOLE_PATH="$RASPISMS_DIR/console.php" CONSOLE_PATH="$RASPISMS_DIR/console.php"

View File

@ -11,11 +11,15 @@
namespace controllers\publics; namespace controllers\publics;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
/** /**
* Controller of callback pages, like sms status update notification. * Controller of callback pages, like sms status update notification.
*/ */
class Callback extends \descartes\Controller class Callback extends \descartes\Controller
{ {
private $logger;
private $user; private $user;
private $internal_user; private $internal_user;
private $internal_sended; private $internal_sended;
@ -29,8 +33,12 @@ namespace controllers\publics;
$this->internal_sended = new \controllers\internals\Sended($bdd); $this->internal_sended = new \controllers\internals\Sended($bdd);
$this->internal_adapter = new \controllers\internals\Adapter(); $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; $this->user = false;
$api_key = $_GET['api_key'] ?? false; $api_key = $_GET['api_key'] ?? false;
if ($api_key) if ($api_key)
@ -42,8 +50,11 @@ namespace controllers\publics;
{ {
http_response_code(401); http_response_code(401);
echo json_encode(['error' => 'Invalid API key. You must provide a valid GET or POST api_key param.']); 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); 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) public function update_sended_status(string $adapter_name)
{ {
$this->logger->info('Callback status call with adapter name : ' . $adapter_name);
//Search for an adapter //Search for an adapter
$find_adapter = false; $find_adapter = false;
$adapters = $this->internal_adapter->list_adapters(); $adapters = $this->internal_adapter->list_adapters();
@ -68,6 +81,7 @@ namespace controllers\publics;
if (false === $find_adapter) if (false === $find_adapter)
{ {
$this->logger->error('Callback status use non existing adapter : ' . $adapter_name);
return false; return false;
} }
@ -75,21 +89,25 @@ namespace controllers\publics;
$adapter_classname = $find_adapter['meta_classname']; $adapter_classname = $find_adapter['meta_classname'];
if (!$find_adapter['meta_support_status_change']) if (!$find_adapter['meta_support_status_change'])
{ {
$this->logger->error('Callback status use adapter ' . $adapter_name . ' which does not support status change.');
return false; return false;
} }
$callback_return = $adapter_classname::status_change_callback(); $callback_return = $adapter_classname::status_change_callback();
if (!$callback_return) if (!$callback_return)
{ {
$this->logger->error('Callback status with adapter ' . $adapter_name . ' failed on adapter compute.');
return false; return false;
} }
$sended = $this->internal_sended->get_by_uid_and_adapter($callback_return['uid'], $adapter_classname); $sended = $this->internal_sended->get_by_uid_and_adapter($callback_return['uid'], $adapter_classname);
if (!$sended) if (!$sended)
{ {
$this->logger->error('Callback status try update inexisting message with uid = ' . $callback_return['uid'] . '.');
return false; return false;
} }
$this->logger->info('Callback status update message with uid ' . $callback_return['uid'] . '.');
$this->internal_sended->update_status($sended['id'], $callback_return['status']); $this->internal_sended->update_status($sended['id'], $callback_return['status']);
return true; return true;

View File

@ -29,7 +29,7 @@ class Launcher extends AbstractDaemon
$name = 'RaspiSMS Daemon Launcher'; $name = 'RaspiSMS Daemon Launcher';
$logger = new Logger($name); $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; $pid_dir = PWD_PID;
$no_parent = true; //Launcher should be rattach to PID 1 $no_parent = true; //Launcher should be rattach to PID 1
$additional_signals = []; $additional_signals = [];

View File

@ -40,7 +40,7 @@ class Phone extends AbstractDaemon
$name = 'RaspiSMS Daemon Phone ' . $this->phone['id']; $name = 'RaspiSMS Daemon Phone ' . $this->phone['id'];
$logger = new Logger($name); $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; $pid_dir = PWD_PID;
$no_parent = false; //Phone should be rattach to manager, so manager can stop him easily $no_parent = false; //Phone should be rattach to manager, so manager can stop him easily
$additional_signals = []; $additional_signals = [];

View File

@ -29,7 +29,7 @@ class Sender extends AbstractDaemon
{ {
$name = 'RaspiSMS Daemon Sender'; $name = 'RaspiSMS Daemon Sender';
$logger = new Logger($name); $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; $pid_dir = PWD_PID;
$no_parent = false; //Webhook should be rattach to manager, so manager can stop him easily $no_parent = false; //Webhook should be rattach to manager, so manager can stop him easily
$additional_signals = []; $additional_signals = [];

View File

@ -34,7 +34,7 @@ class Webhook extends AbstractDaemon
{ {
$name = 'RaspiSMS Daemon Webhook'; $name = 'RaspiSMS Daemon Webhook';
$logger = new Logger($name); $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; $pid_dir = PWD_PID;
$no_parent = false; //Sended should be rattach to manager, so manager can stop him easily $no_parent = false; //Sended should be rattach to manager, so manager can stop him easily
$additional_signals = []; $additional_signals = [];

View File

@ -16,7 +16,7 @@
'HTTP_PWD_SOUND' => HTTP_PWD_ASSETS . '/sounds', 'HTTP_PWD_SOUND' => HTTP_PWD_ASSETS . '/sounds',
'PWD_ADAPTERS' => PWD . '/adapters', 'PWD_ADAPTERS' => PWD . '/adapters',
'PWD_DATAS' => PWD . '/datas', 'PWD_DATAS' => PWD . '/datas',
'PWD_LOGS' => '/var/log/', 'PWD_LOGS' => '/var/log/raspisms',
'PWD_PID' => '/var/run/raspisms', 'PWD_PID' => '/var/run/raspisms',
'APP_SECRET' => '%APP_SECRET%', 'APP_SECRET' => '%APP_SECRET%',