Make config auto-reading/writing configurable with command line flag
This commit is contained in:
parent
e0eb624e53
commit
282c736746
1 changed files with 36 additions and 11 deletions
|
@ -73,6 +73,11 @@ void createAccount(std::string account){
|
|||
}
|
||||
}
|
||||
|
||||
/// Bitmask:
|
||||
/// 1 = Auto-read config from disk
|
||||
/// 2 = Auto-write config to disk
|
||||
static int configrw;
|
||||
|
||||
/// Status monitoring thread.
|
||||
/// Checks status of "protocols" (listening outputs)
|
||||
/// Updates config from disk when changed
|
||||
|
@ -102,6 +107,7 @@ void statusMonitor(void *np){
|
|||
Controller::lastConfigSeen = currConfig;
|
||||
}
|
||||
}
|
||||
if (configrw & 1){
|
||||
// Read from disk if they are newer than our last read
|
||||
if (confTime && confTime > lastConfRead){
|
||||
INFO_MSG("Configuration files changed - reloading configuration from disk");
|
||||
|
@ -109,12 +115,15 @@ void statusMonitor(void *np){
|
|||
Controller::readConfigFromDisk();
|
||||
lastConfRead = Controller::lastConfigChange;
|
||||
}
|
||||
}
|
||||
if (configrw & 2){
|
||||
// Write to disk if we have made no changes in the last 60 seconds and the files are older than the last change
|
||||
if (Controller::lastConfigChange > Controller::lastConfigWrite && Controller::lastConfigChange < Util::epoch() - 60){
|
||||
tthread::lock_guard<tthread::mutex> guard(Controller::configMutex);
|
||||
Controller::writeConfigToDisk();
|
||||
if (lastConfRead < Controller::lastConfigWrite){lastConfRead = Controller::lastConfigWrite;}
|
||||
}
|
||||
}
|
||||
|
||||
{ // this scope prevents the configMutex from being locked constantly
|
||||
tthread::lock_guard<tthread::mutex> guard(Controller::configMutex);
|
||||
|
@ -294,6 +303,10 @@ int main_loop(int argc, char **argv){
|
|||
"configFile", JSON::fromString("{\"long\":\"config\", \"short\":\"c\", \"arg\":\"string\" "
|
||||
"\"default\":\"config.json\", \"help\":\"Specify a config "
|
||||
"file other than default.\"}"));
|
||||
|
||||
Controller::conf.addOption(
|
||||
"configrw", JSON::fromString("{\"long\":\"configrw\", \"short\":\"C\", \"arg\":\"string\" "
|
||||
"\"default\":\"rw\", \"help\":\"If 'r', read config changes from disk. If 'w', writes them to disk after 60 seconds of no changes. If 'rw', does both (default). In all other cases does neither.\"}"));
|
||||
#ifdef UPDATER
|
||||
Controller::conf.addOption(
|
||||
"update", JSON::fromString("{\"default\":0, \"help\":\"Check for and install updates before "
|
||||
|
@ -502,6 +515,18 @@ int main_loop(int argc, char **argv){
|
|||
}while (Controller::instanceId.size() < 16);
|
||||
}
|
||||
|
||||
// Set configrw to correct value
|
||||
{
|
||||
configrw = 0;
|
||||
if (Controller::conf.getString("configrw") == "r"){
|
||||
configrw = 1;
|
||||
}else if (Controller::conf.getString("configrw") == "w"){
|
||||
configrw = 2;
|
||||
}else if (Controller::conf.getString("configrw") == "rw"){
|
||||
configrw = 3;
|
||||
}
|
||||
}
|
||||
|
||||
// start stats thread
|
||||
tthread::thread statsThread(Controller::SharedMemStats, &Controller::conf);
|
||||
// start monitoring thread
|
||||
|
|
Loading…
Add table
Reference in a new issue