Add --config option to rpc process (#2287)
* Add --config option to rpc process * Single block so error isn't repeated
This commit is contained in:
parent
9b6a7fb40f
commit
b7714a2ef0
4 changed files with 42 additions and 17 deletions
|
@ -187,7 +187,7 @@ nano::error nano::rpc_config::deserialize_toml (nano::tomlconfig & toml)
|
|||
|
||||
namespace nano
|
||||
{
|
||||
nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, nano::rpc_config & config_a)
|
||||
nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, nano::rpc_config & config_a, std::vector<std::string> const & config_overrides)
|
||||
{
|
||||
nano::error error;
|
||||
auto json_config_path = nano::get_rpc_config_path (data_path_a);
|
||||
|
@ -233,10 +233,24 @@ nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, n
|
|||
// Parse and deserialize
|
||||
nano::tomlconfig toml;
|
||||
|
||||
// Make sure we don't create an empty toml file if it doesn't exist. Running without a toml file is the default.
|
||||
if (!error && boost::filesystem::exists (toml_config_path))
|
||||
std::stringstream config_overrides_stream;
|
||||
for (auto const & entry : config_overrides)
|
||||
{
|
||||
error = toml.read (toml_config_path);
|
||||
config_overrides_stream << entry << std::endl;
|
||||
}
|
||||
config_overrides_stream << std::endl;
|
||||
|
||||
// Make sure we don't create an empty toml file if it doesn't exist. Running without a toml file is the default.
|
||||
if (!error)
|
||||
{
|
||||
if (boost::filesystem::exists (toml_config_path))
|
||||
{
|
||||
error = toml.read (config_overrides_stream, toml_config_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
toml.read (config_overrides_stream);
|
||||
}
|
||||
}
|
||||
|
||||
if (!error)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <boost/thread.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace nano
|
||||
{
|
||||
|
@ -75,7 +76,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, nano::rpc_config & config_a);
|
||||
nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, nano::rpc_config & config_a, std::vector<std::string> const & config_overrides = std::vector<std::string> ());
|
||||
nano::error read_and_update_rpc_config (boost::filesystem::path const & data_path, nano::rpc_config & config_a);
|
||||
|
||||
std::string get_default_rpc_filepath ();
|
||||
|
|
|
@ -35,7 +35,7 @@ void logging_init (boost::filesystem::path const & application_path_a)
|
|||
|
||||
volatile sig_atomic_t sig_int_or_term = 0;
|
||||
|
||||
void run (boost::filesystem::path const & data_path)
|
||||
void run (boost::filesystem::path const & data_path, std::vector<std::string> const & config_overrides)
|
||||
{
|
||||
boost::filesystem::create_directories (data_path);
|
||||
boost::system::error_code error_chmod;
|
||||
|
@ -43,7 +43,7 @@ void run (boost::filesystem::path const & data_path)
|
|||
std::unique_ptr<nano::thread_runner> runner;
|
||||
|
||||
nano::rpc_config rpc_config;
|
||||
auto error = nano::read_rpc_config_toml (data_path, rpc_config);
|
||||
auto error = nano::read_rpc_config_toml (data_path, rpc_config, config_overrides);
|
||||
if (!error)
|
||||
{
|
||||
logging_init (data_path);
|
||||
|
@ -92,6 +92,7 @@ int main (int argc, char * const * argv)
|
|||
// clang-format off
|
||||
description.add_options ()
|
||||
("help", "Print out options")
|
||||
("config", boost::program_options::value<std::vector<std::string>>()->multitoken(), "Pass RPC configuration values. This takes precedence over any values in the configuration file. This option can be repeated multiple times.")
|
||||
("daemon", "Start RPC daemon")
|
||||
("data_path", boost::program_options::value<std::string> (), "Use the supplied path as the data directory")
|
||||
("network", boost::program_options::value<std::string> (), "Use the supplied network (live, beta or test)")
|
||||
|
@ -136,7 +137,13 @@ int main (int argc, char * const * argv)
|
|||
boost::filesystem::path data_path ((data_path_it != vm.end ()) ? data_path_it->second.as<std::string> () : nano::working_path ());
|
||||
if (vm.count ("daemon") > 0)
|
||||
{
|
||||
run (data_path);
|
||||
std::vector<std::string> config_overrides;
|
||||
auto config (vm.find ("config"));
|
||||
if (config != vm.end ())
|
||||
{
|
||||
config_overrides = config->second.as<std::vector<std::string>> ();
|
||||
}
|
||||
run (data_path, config_overrides);
|
||||
}
|
||||
else if (vm.count ("version"))
|
||||
{
|
||||
|
|
|
@ -202,21 +202,24 @@ nano::error read_node_config_toml (boost::filesystem::path const & data_path_a,
|
|||
// Parse and deserialize
|
||||
nano::tomlconfig toml;
|
||||
|
||||
std::stringstream config_stream;
|
||||
std::stringstream config_overrides_stream;
|
||||
for (auto const & entry : config_overrides)
|
||||
{
|
||||
config_stream << entry << std::endl;
|
||||
config_overrides_stream << entry << std::endl;
|
||||
}
|
||||
config_stream << std::endl;
|
||||
config_overrides_stream << std::endl;
|
||||
|
||||
// Make sure we don't create an empty toml file if it doesn't exist. Running without a toml file is the default.
|
||||
if (!error && boost::filesystem::exists (toml_config_path))
|
||||
if (!error)
|
||||
{
|
||||
toml.read (config_stream, toml_config_path);
|
||||
}
|
||||
else if (!error)
|
||||
{
|
||||
toml.read (config_stream);
|
||||
if (boost::filesystem::exists (toml_config_path))
|
||||
{
|
||||
error = toml.read (config_overrides_stream, toml_config_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
toml.read (config_overrides_stream);
|
||||
}
|
||||
}
|
||||
|
||||
if (!error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue