mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-10-29 18:02:29 +00:00
Fixing daemon reload.
This commit is contained in:
@@ -154,6 +154,42 @@ namespace OpenWifi {
|
||||
return Res;
|
||||
}
|
||||
|
||||
void MicroService::LoadConfigurationFile() {
|
||||
std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR,".");
|
||||
Poco::Path ConfigFile;
|
||||
|
||||
ConfigFile = ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_;
|
||||
|
||||
if(!ConfigFile.isFile())
|
||||
{
|
||||
std::cerr << DAEMON_APP_NAME << ": Configuration "
|
||||
<< ConfigFile.toString() << " does not seem to exist. Please set " + DAEMON_CONFIG_ENV_VAR
|
||||
+ " env variable the path of the " + DAEMON_PROPERTIES_FILENAME + " file." << std::endl;
|
||||
std::exit(Poco::Util::Application::EXIT_CONFIG);
|
||||
}
|
||||
|
||||
loadConfiguration(ConfigFile.toString());
|
||||
}
|
||||
|
||||
void MicroService::Reload() {
|
||||
LoadConfigurationFile();
|
||||
LoadMyConfig();
|
||||
}
|
||||
|
||||
void MicroService::LoadMyConfig() {
|
||||
std::string KeyFile = ConfigPath("openwifi.service.key");
|
||||
std::string KeyFilePassword = ConfigPath("openwifi.service.key.password" , "" );
|
||||
AppKey_ = Poco::SharedPtr<Poco::Crypto::RSAKey>(new Poco::Crypto::RSAKey("", KeyFile, KeyFilePassword));
|
||||
Cipher_ = CipherFactory_.createCipher(*AppKey_);
|
||||
ID_ = Utils::GetSystemId();
|
||||
if(!DebugMode_)
|
||||
DebugMode_ = ConfigGetBool("openwifi.system.debug",false);
|
||||
MyPrivateEndPoint_ = ConfigGetString("openwifi.system.uri.private");
|
||||
MyPublicEndPoint_ = ConfigGetString("openwifi.system.uri.public");
|
||||
UIURI_ = ConfigGetString("openwifi.system.uri.ui");
|
||||
MyHash_ = CreateHash(MyPublicEndPoint_);
|
||||
}
|
||||
|
||||
void MicroService::initialize(Poco::Util::Application &self) {
|
||||
// add the default services
|
||||
SubSystems_.push_back(KafkaManager());
|
||||
@@ -164,22 +200,10 @@ namespace OpenWifi {
|
||||
Poco::Net::HTTPSStreamFactory::registerFactory();
|
||||
Poco::Net::FTPStreamFactory::registerFactory();
|
||||
Poco::Net::FTPSStreamFactory::registerFactory();
|
||||
std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR,".");
|
||||
Poco::Path ConfigFile;
|
||||
|
||||
ConfigFile = ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_;
|
||||
LoadConfigurationFile();
|
||||
|
||||
if(!ConfigFile.isFile())
|
||||
{
|
||||
std::cerr << DAEMON_APP_NAME << ": Configuration "
|
||||
<< ConfigFile.toString() << " does not seem to exist. Please set " + DAEMON_CONFIG_ENV_VAR
|
||||
+ " env variable the path of the " + DAEMON_PROPERTIES_FILENAME + " file." << std::endl;
|
||||
std::exit(Poco::Util::Application::EXIT_CONFIG);
|
||||
}
|
||||
|
||||
static const char * LogFilePathKey = "logging.channels.c2.path";
|
||||
|
||||
loadConfiguration(ConfigFile.toString());
|
||||
static const char * LogFilePathKey = "logging.channels.c2.path";
|
||||
|
||||
if(LogDir_.empty()) {
|
||||
std::string OriginalLogFileValue = ConfigPath(LogFilePathKey);
|
||||
@@ -187,6 +211,7 @@ namespace OpenWifi {
|
||||
} else {
|
||||
config().setString(LogFilePathKey, LogDir_);
|
||||
}
|
||||
|
||||
Poco::File DataDir(ConfigPath("openwifi.system.data"));
|
||||
DataDir_ = DataDir.path();
|
||||
if(!DataDir.exists()) {
|
||||
@@ -196,17 +221,9 @@ namespace OpenWifi {
|
||||
logger().log(E);
|
||||
}
|
||||
}
|
||||
std::string KeyFile = ConfigPath("openwifi.service.key");
|
||||
std::string KeyFilePassword = ConfigPath("openwifi.service.key.password" , "" );
|
||||
AppKey_ = Poco::SharedPtr<Poco::Crypto::RSAKey>(new Poco::Crypto::RSAKey("", KeyFile, KeyFilePassword));
|
||||
Cipher_ = CipherFactory_.createCipher(*AppKey_);
|
||||
ID_ = Utils::GetSystemId();
|
||||
if(!DebugMode_)
|
||||
DebugMode_ = ConfigGetBool("openwifi.system.debug",false);
|
||||
MyPrivateEndPoint_ = ConfigGetString("openwifi.system.uri.private");
|
||||
MyPublicEndPoint_ = ConfigGetString("openwifi.system.uri.public");
|
||||
UIURI_ = ConfigGetString("openwifi.system.uri.ui");
|
||||
MyHash_ = CreateHash(MyPublicEndPoint_);
|
||||
|
||||
LoadMyConfig();
|
||||
|
||||
InitializeSubSystemServers();
|
||||
ServerApplication::initialize(self);
|
||||
|
||||
|
||||
@@ -142,7 +142,12 @@ namespace OpenWifi {
|
||||
static inline uint64_t GetPID() { return Poco::Process::id(); };
|
||||
[[nodiscard]] inline const std::string GetPublicAPIEndPoint() { return MyPublicEndPoint_ + "/api/v1"; };
|
||||
[[nodiscard]] inline const std::string & GetUIURI() const { return UIURI_;};
|
||||
void Reload(const std::string &Name);
|
||||
|
||||
void Reload(const std::string &Name); // reload a subsystem
|
||||
void Reload(); // reload the daemon itself
|
||||
void LoadMyConfig();
|
||||
|
||||
void LoadConfigurationFile();
|
||||
|
||||
private:
|
||||
bool HelpRequested_ = false;
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void RESTAPI_InternalServer::reinitialize(Poco::Util::Application &self) {
|
||||
Daemon()->LoadConfigurationFile();
|
||||
Logger_.information("Reinitializing.");
|
||||
Stop();
|
||||
Start();
|
||||
|
||||
@@ -83,6 +83,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void RESTAPI_Server::reinitialize(Poco::Util::Application &self) {
|
||||
Daemon()->LoadConfigurationFile();
|
||||
Logger_.information("Reinitializing.");
|
||||
Stop();
|
||||
Start();
|
||||
|
||||
@@ -85,7 +85,10 @@ namespace OpenWifi {
|
||||
std::thread ReloadThread([Names](){
|
||||
std::this_thread::sleep_for(10000ms);
|
||||
for(const auto &i:Names) {
|
||||
Daemon()->Reload(i);
|
||||
if(i=="daemon")
|
||||
Daemon()->Reload();
|
||||
else
|
||||
Daemon()->Reload(i);
|
||||
}
|
||||
});
|
||||
ReloadThread.detach();
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenWifi {
|
||||
|
||||
class SMTPMailerService * SMTPMailerService::instance_ = nullptr;
|
||||
|
||||
int SMTPMailerService::Start() {
|
||||
void SMTPMailerService::LoadMyConfig() {
|
||||
MailHost_ = Daemon()->ConfigGetString("mailer.hostname");
|
||||
SenderLoginUserName_ = Daemon()->ConfigGetString("mailer.username");
|
||||
SenderLoginPassword_ = Daemon()->ConfigGetString("mailer.password");
|
||||
@@ -32,6 +32,10 @@ namespace OpenWifi {
|
||||
LoginMethod_ = Daemon()->ConfigGetString("mailer.loginmethod");
|
||||
MailHostPort_ = (int)Daemon()->ConfigGetInt("mailer.port");
|
||||
TemplateDir_ = Daemon()->ConfigPath("mailer.templates", Daemon()->DataDir());
|
||||
}
|
||||
|
||||
int SMTPMailerService::Start() {
|
||||
LoadMyConfig();
|
||||
SenderThr_.start(*this);
|
||||
return 0;
|
||||
}
|
||||
@@ -42,6 +46,12 @@ namespace OpenWifi {
|
||||
SenderThr_.join();
|
||||
}
|
||||
|
||||
void SMTPMailerService::reinitialize(Poco::Util::Application &self) {
|
||||
Daemon()->LoadConfigurationFile();
|
||||
Logger_.information("Reinitializing.");
|
||||
LoadMyConfig();
|
||||
}
|
||||
|
||||
bool SMTPMailerService::SendMessage(const std::string &Recipient, const std::string &Name, const MessageAttributes &Attrs) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
|
||||
@@ -78,7 +78,8 @@ namespace OpenWifi {
|
||||
void Stop() override;
|
||||
bool SendMessage(const std::string &Recipient, const std::string &Name, const MessageAttributes &Attrs);
|
||||
bool SendIt(const MessageEvent &Msg);
|
||||
|
||||
void LoadMyConfig();
|
||||
void reinitialize(Poco::Util::Application &self) override;
|
||||
private:
|
||||
static SMTPMailerService * instance_;
|
||||
std::string MailHost_;
|
||||
|
||||
Reference in New Issue
Block a user