From: Maxim Mamontov Date: Thu, 14 Apr 2016 17:37:49 +0000 (+0300) Subject: Merge remote-tracking branch 'origin/ticket26' into stg-2.409 X-Git-Tag: 2.409~174^2~1 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/c0fff5a4f4e765e5bb9f01a5d380cbdc098d04e6?hp=f6b42411f8193b918e00d06551ed85985913ffa1 Merge remote-tracking branch 'origin/ticket26' into stg-2.409 --- 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 de047687..26bd9727 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -343,8 +343,15 @@ while (running) switch (sig) { case SIGHUP: + { + SETTINGS_IMPL newSettings(settings); + if (newSettings.ReadSettings()) + WriteServLog("ReadSettings error. %s", newSettings.GetStrError().c_str()); + else + 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..85215c7b 100644 --- a/projects/stargazer/plugin_mgr.cpp +++ b/projects/stargazer/plugin_mgr.cpp @@ -59,12 +59,13 @@ PluginManager::PluginManager(const SETTINGS_IMPL& settings, const std::vector & modSettings(settings.GetModulesSettings()); for (size_t i = 0; i < modSettings.size(); i++) { - std::string modulePath = basePath + "/mod_" + modSettings[i].moduleName + ".so"; + std::string moduleName = modSettings[i].moduleName; + std::string modulePath = basePath + "/mod_" + moduleName + ".so"; 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,25 @@ 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()); + } + break; + } } } } 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..99e0a091 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -524,6 +524,22 @@ if (ret) return ret; } //----------------------------------------------------------------------------- +int AUTH_IA::Reload(const MODULE_SETTINGS & ms) +{ +AUTH_IA_SETTINGS newIaSettings; +if (newIaSettings.ParseSettings(ms)) + { + printfd(__FILE__, "AUTH_IA::Reload() - Failed to reload InetAccess.\n"); + logger("AUTH_IA: Cannot reload InetAccess. Errors found."); + return -1; + } + +printfd(__FILE__, "AUTH_IA::Reload() - Reloaded InetAccess successfully.\n"); +logger("AUTH_IA: Reloaded InetAccess successfully."); +iaSettings = newIaSettings; +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..c1a3951c 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 & rhs) +{ + modulesPath = rhs.modulesPath; + dirName = rhs.dirName; + confDir = rhs.confDir; + scriptsDir = rhs.scriptsDir; + rules = rhs.rules; + logFile = rhs.logFile; + pidFile = rhs.pidFile; + monitorDir = rhs.monitorDir; + scriptParams = rhs.scriptParams; + monitoring = rhs.monitoring; + detailStatWritePeriod = rhs.detailStatWritePeriod; + statWritePeriod = rhs.statWritePeriod; + stgExecMsgKey = rhs.stgExecMsgKey; + executersNum = rhs.executersNum; + fullFee = rhs.fullFee; + dayFee = rhs.dayFee; + dayResetTraff = rhs.dayResetTraff; + spreadFee = rhs.spreadFee; + freeMbAllowInet = rhs.freeMbAllowInet; + dayFeeIsLastDay = rhs.dayFeeIsLastDay; + writeFreeMbTraffCost = rhs.writeFreeMbTraffCost; + showFeeInCash = rhs.showFeeInCash; + messageTimeout = rhs.messageTimeout; + feeChargeType = rhs.feeChargeType; + reconnectOnTariffChange = rhs.reconnectOnTariffChange; + + modulesSettings = rhs.modulesSettings; + storeModuleSettings = rhs.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();