Configuration options can be overridden by setting env values
This commit is contained in:
@@ -14,6 +14,7 @@ Version 5.0
|
|||||||
- If the client doesn’t specify any limit, MAM results contain at most 100
|
- If the client doesn’t specify any limit, MAM results contain at most 100
|
||||||
messages, instead of the whole archive.
|
messages, instead of the whole archive.
|
||||||
- Multiline topics are now properly handled
|
- Multiline topics are now properly handled
|
||||||
|
- Configuration options can be overridden by values found in the process env.
|
||||||
|
|
||||||
Version 4.1 - 2017-03-21
|
Version 4.1 - 2017-03-21
|
||||||
========================
|
========================
|
||||||
|
|||||||
+7
-3
@@ -35,15 +35,19 @@ details on its content.
|
|||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
|
|
||||||
The configuration file uses a simple format of the form
|
The configuration file uses a simple format of the form ``option=value``.
|
||||||
``option=value``.
|
|
||||||
|
The values from the configuration file can be overridden by environment
|
||||||
|
variables, with the name all in upper case and prefixed with "BIBOUMI_".
|
||||||
|
For example, if the environment contains “BIBOUMI_PASSWORD=blah", this will
|
||||||
|
override the value of the “password” option in the configuration file.
|
||||||
|
|
||||||
Sending SIGUSR1 or SIGUSR2 (see kill(1)) to the process will force it to
|
Sending SIGUSR1 or SIGUSR2 (see kill(1)) to the process will force it to
|
||||||
re-read the configuration and make it close and re-open the log files. You
|
re-read the configuration and make it close and re-open the log files. You
|
||||||
can use this to change any configuration option at runtime, or do a log
|
can use this to change any configuration option at runtime, or do a log
|
||||||
rotation.
|
rotation.
|
||||||
|
|
||||||
Here is a description of each possible option:
|
Here is a description of every possible option:
|
||||||
|
|
||||||
hostname
|
hostname
|
||||||
--------
|
--------
|
||||||
|
|||||||
+35
-11
@@ -1,10 +1,15 @@
|
|||||||
#include <config/config.hpp>
|
#include <config/config.hpp>
|
||||||
|
#include <utils/tolower.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
|
extern char** environ;
|
||||||
|
|
||||||
std::string Config::filename{};
|
std::string Config::filename{};
|
||||||
std::map<std::string, std::string> Config::values{};
|
std::map<std::string, std::string> Config::values{};
|
||||||
std::vector<t_config_changed_callback> Config::callbacks{};
|
std::vector<t_config_changed_callback> Config::callbacks{};
|
||||||
@@ -71,21 +76,40 @@ bool Config::read_conf(const std::string& name)
|
|||||||
|
|
||||||
Config::clear();
|
Config::clear();
|
||||||
|
|
||||||
|
auto parse_line = [](const std::string& line, const bool env)
|
||||||
|
{
|
||||||
|
static const auto env_option_prefix = "BIBOUMI_"s;
|
||||||
|
|
||||||
|
if (line == "" || line[0] == '#')
|
||||||
|
return;
|
||||||
|
size_t pos = line.find('=');
|
||||||
|
if (pos == std::string::npos)
|
||||||
|
return;
|
||||||
|
std::string option = line.substr(0, pos);
|
||||||
|
std::string value = line.substr(pos+1);
|
||||||
|
if (env)
|
||||||
|
{
|
||||||
|
auto a = option.substr(0, env_option_prefix.size());
|
||||||
|
if (a == env_option_prefix)
|
||||||
|
option = utils::tolower(option.substr(env_option_prefix.size()));
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Config::values[option] = value;
|
||||||
|
};
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
size_t pos;
|
|
||||||
std::string option;
|
|
||||||
std::string value;
|
|
||||||
while (file.good())
|
while (file.good())
|
||||||
{
|
{
|
||||||
std::getline(file, line);
|
std::getline(file, line);
|
||||||
if (line == "" || line[0] == '#')
|
parse_line(line, false);
|
||||||
continue ;
|
}
|
||||||
pos = line.find('=');
|
|
||||||
if (pos == std::string::npos)
|
char** env_line = environ;
|
||||||
continue ;
|
while (*env_line)
|
||||||
option = line.substr(0, pos);
|
{
|
||||||
value = line.substr(pos+1);
|
parse_line(*env_line, true);
|
||||||
Config::values[option] = value;
|
env_line++;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user