From e001df0a3534d1ccf2ea7004e2813a1ecf14168f Mon Sep 17 00:00:00 2001 From: Calle Wilund Date: Wed, 2 Sep 2015 13:15:49 +0200 Subject: [PATCH] Main: Resolve scylla.conf based on ENV vars + do more explicit error logging Refs #135 --- main.cc | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/main.cc b/main.cc index d459a569c5..2378ea100f 100644 --- a/main.cc +++ b/main.cc @@ -27,14 +27,34 @@ #include "release.hh" #include +logging::logger startlog("init"); + namespace bpo = boost::program_options; static future<> read_config(bpo::variables_map& opts, db::config& cfg) { - if (opts.count("options-file") == 0) { - return make_ready_future<>(); + sstring file; + + if (opts.count("options-file") > 0) { + file = opts["options-file"].as(); + } else { + sstring confdir; + auto* cd = std::getenv("SCYLLA_CONF"); + if (cd != nullptr) { + confdir = cd; + } else { + auto* p = std::getenv("SCYLLA_HOME"); + if (p != nullptr) { + confdir = sstring(p) + "/"; + } + confdir += "conf"; + } + file = confdir + "/scylla.yaml"; } - return cfg.read_from_file(opts["options-file"].as()); + return cfg.read_from_file(file).handle_exception([file](auto ep) { + startlog.error("Could not read configuration file {}: {}", file, ep); + return make_exception_future<>(ep); + }); } static void do_help_loggers() { @@ -68,8 +88,6 @@ static void apply_logger_settings(sstring default_level, db::config::string_map logging::logger::set_syslog_enabled(log_to_syslog); } -logging::logger startlog("init"); - class directories { public: future<> touch_and_lock(sstring path) { @@ -122,7 +140,7 @@ int main(int ac, char** av) { bool help_loggers = false; cfg->add_options(opt_add) // TODO : default, always read? - ("options-file", bpo::value()->default_value("conf/scylla.yaml"), "scylla.yaml file to read options from") + ("options-file", bpo::value(), "configuration file (i.e. /conf/scylla.yaml)") ("help-loggers", bpo::bool_switch(&help_loggers), "print a list of logger names and exit") ;