From: Elena Mamontova Date: Thu, 17 Mar 2016 07:39:43 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/stg-2.409' into ticket26 X-Git-Tag: 2.409~174^2~1^2~9 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/8c7e6453aff765245cc5c28f37543f13d92dbe74?hp=72635da73fc450b040d72fbeca4becd73c99008d Merge remote-tracking branch 'origin/stg-2.409' into ticket26 --- diff --git a/include/stg/plugin.h b/include/stg/plugin.h index 114ffc8b..2deabcc3 100644 --- a/include/stg/plugin.h +++ b/include/stg/plugin.h @@ -59,7 +59,7 @@ public: virtual int Start() = 0; virtual int Stop() = 0; - virtual int Reload() = 0; + virtual int Reload(const MODULE_SETTINGS &) = 0; virtual bool IsRunning() = 0; virtual const std::string & GetStrError() const = 0; virtual std::string GetVersion() const = 0; diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 3c216977..34fc4bd0 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -338,8 +338,22 @@ while (running) switch (sig) { case SIGHUP: + { + SETTINGS_IMPL newSettings(settings); + if (newSettings.ReadSettings()) + { + STG_LOGGER & WriteServLog = GetStgLogger(); + + if (newSettings.GetLogFileName() != "") + WriteServLog.SetLogFileName(newSettings.GetLogFileName()); + + WriteServLog("ReadSettings error. %s", newSettings.GetStrError().c_str()); + return -1; + } + settings = newSettings; traffCnt.Reload(); - manager.reload(); + manager.reload(settings); + } break; case SIGTERM: running = false; diff --git a/projects/stargazer/plugin_mgr.cpp b/projects/stargazer/plugin_mgr.cpp index b87ab277..10911b97 100644 --- a/projects/stargazer/plugin_mgr.cpp +++ b/projects/stargazer/plugin_mgr.cpp @@ -60,11 +60,12 @@ PluginManager::PluginManager(const SETTINGS_IMPL& settings, for (size_t i = 0; i < modSettings.size(); i++) { std::string modulePath = basePath + "/mod_" + modSettings[i].moduleName + ".so"; + std::string moduleName = modSettings[i].moduleName; printfd(__FILE__, "Module: %s\n", modulePath.c_str()); try { m_modules.push_back( - new PLUGIN_RUNNER(modulePath, modSettings[i], admins, tariffs, + new PLUGIN_RUNNER(modulePath, moduleName, modSettings[i], admins, tariffs, users, services, corporations, traffcounter, store, settings) ); @@ -102,17 +103,24 @@ PluginManager::~PluginManager() delete m_modules[i]; } -void PluginManager::reload() +void PluginManager::reload(const SETTINGS_IMPL& settings) { + const std::vector & modSettings(settings.GetModulesSettings()); for (size_t i = 0; i < m_modules.size(); ++i) { - PLUGIN & plugin = m_modules[i]->GetPlugin(); - if (m_modules[i]->Reload()) + for (size_t j = 0; j < modSettings.size(); j++) { - m_log("Error reloading module '%s': '%s'", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - printfd(__FILE__, "Error reloading module '%s': '%s'\n", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); + if (modSettings[j].moduleName == m_modules[i]->GetName()) + { + PLUGIN & plugin = m_modules[i]->GetPlugin(); + if (m_modules[i]->Reload(modSettings[j])) + { + m_log("Error reloading module '%s': '%s'", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + printfd(__FILE__, "Error reloading module '%s': '%s'\n", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + } + } } } } diff --git a/projects/stargazer/plugin_mgr.h b/projects/stargazer/plugin_mgr.h index c9ec8dff..a37052d5 100644 --- a/projects/stargazer/plugin_mgr.h +++ b/projects/stargazer/plugin_mgr.h @@ -48,7 +48,7 @@ class PluginManager USERS_IMPL& users, TRAFFCOUNTER_IMPL& traffcounter); ~PluginManager(); - void reload(); + void reload(const SETTINGS_IMPL& settings); void stop(); private: diff --git a/projects/stargazer/plugin_runner.cpp b/projects/stargazer/plugin_runner.cpp index eaf51058..e57a421e 100644 --- a/projects/stargazer/plugin_runner.cpp +++ b/projects/stargazer/plugin_runner.cpp @@ -28,6 +28,7 @@ //----------------------------------------------------------------------------- PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & fileName, + const std::string & name, const MODULE_SETTINGS & ms, ADMINS & admins, TARIFFS & tariffs, @@ -38,6 +39,7 @@ PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & fileName, STORE & store, const SETTINGS & settings) : pluginFileName(fileName), + pluginName(name), libHandle(NULL), m_plugin(Load(ms, admins, tariffs, users, services, corporations, traffcounter, store, settings)) @@ -67,9 +69,9 @@ errorStr = m_plugin.GetStrError(); return res; } //----------------------------------------------------------------------------- -int PLUGIN_RUNNER::Reload() +int PLUGIN_RUNNER::Reload(const MODULE_SETTINGS & ms) { -int res = m_plugin.Reload(); +int res = m_plugin.Reload(ms); errorStr = m_plugin.GetStrError(); return res; } diff --git a/projects/stargazer/plugin_runner.h b/projects/stargazer/plugin_runner.h index 1402d2ef..2d0c22c4 100644 --- a/projects/stargazer/plugin_runner.h +++ b/projects/stargazer/plugin_runner.h @@ -46,6 +46,7 @@ public: }; PLUGIN_RUNNER(const std::string & pluginFileName, + const std::string & pluginName, const MODULE_SETTINGS & ms, ADMINS & admins, TARIFFS & tariffs, @@ -59,13 +60,14 @@ public: int Start(); int Stop(); - int Reload(); + int Reload(const MODULE_SETTINGS & ms); int Restart(); bool IsRunning() { return m_plugin.IsRunning(); } const std::string & GetStrError() const { return errorStr; } PLUGIN & GetPlugin() { return m_plugin; } const std::string & GetFileName() const { return pluginFileName; } + const std::string & GetName() const { return pluginName; } uint16_t GetStartPosition() const { return m_plugin.GetStartPosition(); } uint16_t GetStopPosition() const { return m_plugin.GetStopPosition(); } @@ -85,6 +87,7 @@ private: const SETTINGS & settings); std::string pluginFileName; + std::string pluginName; void * libHandle; PLUGIN & m_plugin; diff --git a/projects/stargazer/plugins/authorization/ao/ao.h b/projects/stargazer/plugins/authorization/ao/ao.h index d8b6dc88..34c15d91 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.h +++ b/projects/stargazer/plugins/authorization/ao/ao.h @@ -89,7 +89,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS &) {} int ParseSettings() { return 0; } diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 8be662e9..6b34618f 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -524,6 +524,23 @@ if (ret) return ret; } //----------------------------------------------------------------------------- +int AUTH_IA::Reload(const MODULE_SETTINGS & ms) +{ +AUTH_IA_SETTINGS newIaSettings; +if (newIaSettings.ParseSettings(ms)) + { + STG_LOGGER & WriteServLog = GetStgLogger(); + printfd(__FILE__, "AUTH_IA::Reload() - Failed to reload InetAccess.\n"); + WriteServLog("AUTH_IA: Cannot reload InetAccess. Errors found."); + return -1; + } + +STG_LOGGER & WriteServLog = GetStgLogger(); +printfd(__FILE__, "AUTH_IA::Reload() - Reloaded InetAccess successfully.\n"); +WriteServLog("AUTH_IA: Reloaded InetAccess successfully."); +return 0; +} +//----------------------------------------------------------------------------- int AUTH_IA::PrepareNet() { struct sockaddr_in listenAddr; diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index 5e454124..2b527076 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -247,7 +247,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms); bool IsRunning() { return isRunningRunTimeouter || isRunningRun; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/authorization/stress/stress.h b/projects/stargazer/plugins/authorization/stress/stress.h index 83ab3231..8ab8122a 100644 --- a/projects/stargazer/plugins/authorization/stress/stress.h +++ b/projects/stargazer/plugins/authorization/stress/stress.h @@ -93,7 +93,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning(); void SetSettings(const MODULE_SETTINGS & s); int ParseSettings(); diff --git a/projects/stargazer/plugins/capture/cap_debug/debug_cap.h b/projects/stargazer/plugins/capture/cap_debug/debug_cap.h index 6bea457f..c9a629c6 100644 --- a/projects/stargazer/plugins/capture/cap_debug/debug_cap.h +++ b/projects/stargazer/plugins/capture/cap_debug/debug_cap.h @@ -69,7 +69,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } int ParseSettings() { return 0; } bool IsRunning(); const std::string & GetStrError() const; diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h index bcb8b743..ae0b3763 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h @@ -99,7 +99,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return runningTCP || runningUDP; } const std::string & GetStrError() const { return errorStr; } std::string GetVersion() const { return VERSION; } diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h index b34f832e..3c52701d 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h @@ -51,7 +51,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h index 76785ed2..2a9840ae 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h @@ -98,7 +98,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h index 8dfb6c04..73455658 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h @@ -52,7 +52,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return isRunning; } int ParseSettings() { return 0; } diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h index 39ed5766..7144d177 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h @@ -47,7 +47,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return isRunning; } int ParseSettings() { return 0; } diff --git a/projects/stargazer/plugins/capture/nfqueue/nfqueue.h b/projects/stargazer/plugins/capture/nfqueue/nfqueue.h index 87124784..60829626 100644 --- a/projects/stargazer/plugins/capture/nfqueue/nfqueue.h +++ b/projects/stargazer/plugins/capture/nfqueue/nfqueue.h @@ -51,7 +51,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h index 72a14f21..593f346d 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h @@ -70,7 +70,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return running && !stopped; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h index 287c3813..87756b4a 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h @@ -60,7 +60,7 @@ class STG_CONFIG : public PLUGIN int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/ping/ping.h b/projects/stargazer/plugins/other/ping/ping.h index 29e4974e..1a7e1b97 100644 --- a/projects/stargazer/plugins/other/ping/ping.h +++ b/projects/stargazer/plugins/other/ping/ping.h @@ -112,7 +112,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning(); const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 8f5ba2a4..77dde0d5 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -98,7 +98,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms) { return 0; } bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index 928629ad..74bf87a1 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -296,7 +296,7 @@ if (isRunning) return 0; } //----------------------------------------------------------------------------- -int REMOTE_SCRIPT::Reload() +int REMOTE_SCRIPT::Reload(const MODULE_SETTINGS & ms) { NRMapParser nrMapParser; diff --git a/projects/stargazer/plugins/other/rscript/rscript.h b/projects/stargazer/plugins/other/rscript/rscript.h index e0412fb0..0de1ea2e 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.h +++ b/projects/stargazer/plugins/other/rscript/rscript.h @@ -185,7 +185,7 @@ public: int Start(); int Stop(); - int Reload(); + int Reload(const MODULE_SETTINGS & ms); bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index 9ff739cb..5a20d495 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -269,7 +269,7 @@ printfd(__FILE__, "SMUX::Stop() - After\n"); return 0; } -int SMUX::Reload() +int SMUX::Reload(const MODULE_SETTINGS & ms) { if (Stop()) return -1; diff --git a/projects/stargazer/plugins/other/smux/smux.h b/projects/stargazer/plugins/other/smux/smux.h index e379ea7f..3b217eb7 100644 --- a/projects/stargazer/plugins/other/smux/smux.h +++ b/projects/stargazer/plugins/other/smux/smux.h @@ -116,7 +116,7 @@ public: int Start(); int Stop(); - int Reload(); + int Reload(const MODULE_SETTINGS & ms); bool IsRunning() { return running && !stopped; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index d115919d..a50a0a65 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -99,6 +99,39 @@ SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) { } //----------------------------------------------------------------------------- +SETTINGS_IMPL & SETTINGS_IMPL::operator=(const SETTINGS_IMPL & set) +{ + modulesPath = set.modulesPath; + dirName = set.dirName; + confDir = set.confDir; + scriptsDir = set.scriptsDir; + rules = set.rules; + logFile = set.logFile; + pidFile = set.pidFile; + monitorDir = set.monitorDir; + scriptParams = set.scriptParams; + monitoring = set.monitoring; + detailStatWritePeriod = set.detailStatWritePeriod; + statWritePeriod = set.statWritePeriod; + stgExecMsgKey = set.stgExecMsgKey; + executersNum = set.executersNum; + fullFee = set.fullFee; + dayFee = set.dayFee; + dayResetTraff = set.dayResetTraff; + spreadFee = set.spreadFee; + freeMbAllowInet = set.freeMbAllowInet; + dayFeeIsLastDay = set.dayFeeIsLastDay; + writeFreeMbTraffCost = set.writeFreeMbTraffCost; + showFeeInCash = set.showFeeInCash; + messageTimeout = set.messageTimeout; + feeChargeType = set.feeChargeType; + reconnectOnTariffChange = set.reconnectOnTariffChange; + + modulesSettings = set.modulesSettings; + storeModuleSettings = set.storeModuleSettings; + return *this; +} +//----------------------------------------------------------------------------- int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector * params) { const DOTCONFDocumentNode * childNode; diff --git a/projects/stargazer/settings_impl.h b/projects/stargazer/settings_impl.h index 69013764..253b8bbc 100644 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@ -42,7 +42,6 @@ #include "stg/settings.h" #include "stg/common.h" -#include "stg/logger.h" #include "stg/module_settings.h" //----------------------------------------------------------------------------- @@ -61,6 +60,8 @@ public: SETTINGS_IMPL(const std::string &); SETTINGS_IMPL(const SETTINGS_IMPL &); virtual ~SETTINGS_IMPL() {} + SETTINGS_IMPL & operator=(const SETTINGS_IMPL &); + int Reload() { return ReadSettings(); } int ReadSettings();