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;
PIDFile pidFile(settings.GetPIDFileName());
+struct sigaction sa;
+memset(&sa, 0, sizeof(sa));
+sa.sa_handler = SIG_DFL;
+sigaction(SIGHUP, &sa, NULL); // Apparently FreeBSD ignores SIGHUP by default when launched from rc.d at bot time.
+
sigset_t signalSet;
sigfillset(&signalSet);
pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
switch (sig)
{
case SIGHUP:
+ {
+ SETTINGS_IMPL newSettings(settings);
+ if (newSettings.ReadSettings())
+ WriteServLog("ReadSettings error. %s", newSettings.GetStrError().c_str());
+ else
+ settings = newSettings;
+ WriteServLog.SetLogFileName(settings.GetLogFileName());
traffCnt.Reload();
- manager.reload();
+ manager.reload(settings);
+ }
break;
case SIGTERM:
running = false;
const std::vector<MODULE_SETTINGS> & 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)
);
delete m_modules[i];
}
-void PluginManager::reload()
+void PluginManager::reload(const SETTINGS_IMPL& settings)
{
+ const std::vector<MODULE_SETTINGS> & 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;
+ }
}
}
}
USERS_IMPL& users, TRAFFCOUNTER_IMPL& traffcounter);
~PluginManager();
- void reload();
+ void reload(const SETTINGS_IMPL& settings);
void stop();
private:
//-----------------------------------------------------------------------------
PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & fileName,
+ const std::string & name,
const MODULE_SETTINGS & ms,
ADMINS & admins,
TARIFFS & tariffs,
STORE & store,
const SETTINGS & settings)
: pluginFileName(fileName),
+ pluginName(name),
libHandle(NULL),
m_plugin(Load(ms, admins, tariffs, users, services, corporations,
traffcounter, store, settings))
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;
}
};
PLUGIN_RUNNER(const std::string & pluginFileName,
+ const std::string & pluginName,
const MODULE_SETTINGS & ms,
ADMINS & admins,
TARIFFS & tariffs,
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(); }
const SETTINGS & settings);
std::string pluginFileName;
+ std::string pluginName;
void * libHandle;
PLUGIN & m_plugin;
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; }
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;
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; }
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();
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;
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; }
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; }
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; }
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
int ParseSettings() { return 0; }
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
int ParseSettings() { return 0; }
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; }
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; }
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; }
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; }
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return m_running; }
const std::string& GetStrError() const { return m_error; }
return 0;
}
//-----------------------------------------------------------------------------
-int REMOTE_SCRIPT::Reload()
+int REMOTE_SCRIPT::Reload(const MODULE_SETTINGS & /*ms*/)
{
NRMapParser nrMapParser;
int Start();
int Stop();
- int Reload();
+ int Reload(const MODULE_SETTINGS & ms);
bool IsRunning() { return isRunning; }
const std::string & GetStrError() const { return errorStr; }
return 0;
}
-int SMUX::Reload()
+int SMUX::Reload(const MODULE_SETTINGS & /*ms*/)
{
if (Stop())
return -1;
int Start();
int Stop();
- int Reload();
+ int Reload(const MODULE_SETTINGS & ms);
bool IsRunning() { return running && !stopped; }
const std::string & GetStrError() const { return errorStr; }
{
}
//-----------------------------------------------------------------------------
+SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval)
+ : SETTINGS(),
+ strError(),
+ modulesPath(rval.modulesPath),
+ dirName(rval.dirName),
+ confDir(rval.confDir),
+ scriptsDir(rval.scriptsDir),
+ rules(rval.rules),
+ logFile(rval.logFile),
+ pidFile(rval.pidFile),
+ monitorDir(rval.monitorDir),
+ monitoring(rval.monitoring),
+ detailStatWritePeriod(rval.detailStatWritePeriod),
+ statWritePeriod(rval.statWritePeriod),
+ stgExecMsgKey(rval.stgExecMsgKey),
+ executersNum(rval.executersNum),
+ fullFee(rval.fullFee),
+ dayFee(rval.dayFee),
+ dayResetTraff(rval.dayResetTraff),
+ spreadFee(rval.spreadFee),
+ freeMbAllowInet(rval.freeMbAllowInet),
+ dayFeeIsLastDay(rval.dayFeeIsLastDay),
+ writeFreeMbTraffCost(rval.writeFreeMbTraffCost),
+ showFeeInCash(rval.showFeeInCash),
+ messageTimeout(rval.messageTimeout),
+ feeChargeType(rval.feeChargeType),
+ reconnectOnTariffChange(rval.reconnectOnTariffChange),
+ modulesSettings(rval.modulesSettings),
+ storeModuleSettings(rval.storeModuleSettings),
+ logger(GetStgLogger())
+{
+}
+//-----------------------------------------------------------------------------
+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<PARAM_VALUE> * params)
+{
+const DOTCONFDocumentNode * childNode;
+PARAM_VALUE pv;
+const char * value;
+
+pv.param = node->getName();
+
+if (node->getValue(1))
+ {
+ strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'.";
+ return -1;
+ }
+
+value = node->getValue(0);
+
+if (!value)
+ {
+ strError = "Module name expected.";
+ return -1;
+ }
+
+childNode = node->getChildNode();
+while (childNode)
+ {
+ pv.param = childNode->getName();
+ int i = 0;
+ while ((value = childNode->getValue(i++)) != NULL)
+ {
+ pv.value.push_back(value);
+ }
+ params->push_back(pv);
+ pv.value.clear();
+ childNode = childNode->getNextNode();
+ }
+
+return 0;
+}
+//-----------------------------------------------------------------------------
void SETTINGS_IMPL::ErrorCallback(void * data, const char * buf)
{
printfd(__FILE__, "SETTINGS_IMPL::ErrorCallback() - %s\n", buf);
#include <vector>
#include "stg/settings.h"
+#include "stg/common.h"
#include "stg/module_settings.h"
#include "stg/ref.h"
class SETTINGS_IMPL : public SETTINGS {
public:
SETTINGS_IMPL(const std::string &);
+ SETTINGS_IMPL(const SETTINGS_IMPL & rhs);
virtual ~SETTINGS_IMPL() {}
+ SETTINGS_IMPL & operator=(const SETTINGS_IMPL &);
+
int Reload() { return ReadSettings(); }
int ReadSettings();
{ return modulesSettings; }
const std::vector<std::string> & GetScriptParams() const { return scriptParams; }
+ int ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector<PARAM_VALUE> * params);
+
private:
static void ErrorCallback(void * data, const char * buf);
//-----------------------------------------------------------------------------
void CHG_TARIFF_NOTIFIER::Notify(const std::string &, const std::string & newTariff)
{
+STG_LOCKER lock(&user->mutex);
if (user->settings->GetReconnectOnTariffChange() && user->connected)
user->Disconnect(false, "Change tariff");
user->tariff = user->tariffs->FindByName(newTariff);
if (user->settings->GetReconnectOnTariffChange() &&
!user->authorizedBy.empty() &&
user->IsInetable())
+ {
+ // This notifier gets called *before* changing the tariff, and in Connect we want to see new tariff name.
+ user->property.Conf().tariffName = newTariff;
user->Connect(false);
+ }
}
//-----------------------------------------------------------------------------
void CHG_CASH_NOTIFIER::Notify(const double & oldCash, const double & newCash)
mutable pthread_mutex_t mutex;
};
//-----------------------------------------------------------------------------
-class PLUGIN_LOGGER : private STG_LOGGER
+class PLUGIN_LOGGER
{
-friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName);
+friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER& logger, const std::string& pluginName);
public:
- PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs);
- void operator()(const char * fmt, ...) const;
- void operator()(const std::string & line) const;
+ PLUGIN_LOGGER(const PLUGIN_LOGGER& rhs) : m_parent(rhs.m_parent), m_pluginName(rhs.m_pluginName) {}
+ void operator()(const char* fmt, ...) const;
+ void operator()(const std::string& line) const;
private:
PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn);
- std::string pluginName;
+ const STG_LOGGER& m_parent;
+ std::string m_pluginName;
};
PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName);
}
}
//-----------------------------------------------------------------------------
-PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn)
- : STG_LOGGER(),
- pluginName(pn)
+PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER& logger, const std::string& pn)
+ : m_parent(logger),
+ m_pluginName(pn)
{
- SetLogFileName(logger.fileName);
-}
-//-----------------------------------------------------------------------------
-PLUGIN_LOGGER::PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs)
- : STG_LOGGER(),
- pluginName(rhs.pluginName)
-{
- SetLogFileName(fileName);
}
//-----------------------------------------------------------------------------
void PLUGIN_LOGGER::operator()(const char * fmt, ...) const
vsnprintf(buff, sizeof(buff), fmt, vl);
va_end(vl);
-STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), buff);
+m_parent("[%s] %s", m_pluginName.c_str(), buff);
}
//-----------------------------------------------------------------------------
void PLUGIN_LOGGER::operator()(const std::string & line) const
{
-STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), line.c_str());
+m_parent("[%s] %s", m_pluginName.c_str(), line.c_str());
}
//-----------------------------------------------------------------------------
PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName)