diff --git a/include/NebulaTemplate.h b/include/NebulaTemplate.h index 5df1be651e..61bbb373e8 100644 --- a/include/NebulaTemplate.h +++ b/include/NebulaTemplate.h @@ -30,9 +30,16 @@ public: NebulaTemplate(const std::string& etc_location, const char * _conf_name, const char * root_name) : Template(false, '=', root_name) - , conf_file(etc_location + _conf_name) , hidden_attributes{ { "DB", { "PASSWD" } } } { + if (_conf_name[0] == '/') + { + conf_file = _conf_name; + } + else + { + conf_file = etc_location + _conf_name; + } } virtual ~NebulaTemplate() = default; diff --git a/include/OpenNebulaTemplate.h b/include/OpenNebulaTemplate.h index 3ac549602c..c88e727ce2 100644 --- a/include/OpenNebulaTemplate.h +++ b/include/OpenNebulaTemplate.h @@ -30,8 +30,9 @@ class OpenNebulaTemplate : public NebulaTemplate public: OpenNebulaTemplate(const std::string& etc_location, - const std::string& _var_location): - NebulaTemplate(etc_location, conf_name, "OPENNEBULA_CONFIGURATION"), + const std::string& _var_location, + const std::string& _conf_name = conf_name): + NebulaTemplate(etc_location, _conf_name.c_str(), "OPENNEBULA_CONFIGURATION"), var_location(_var_location) {}; diff --git a/src/monitor/src/monitor/Monitor.cc b/src/monitor/src/monitor/Monitor.cc index b43f24906a..0c6e3c1e79 100644 --- a/src/monitor/src/monitor/Monitor.cc +++ b/src/monitor/src/monitor/Monitor.cc @@ -36,7 +36,7 @@ void Monitor::start() // ------------------------------------------------------------------------- // Configuration File // ------------------------------------------------------------------------- - OpenNebulaTemplate oned_config(get_defaults_location(), get_var_location()); + OpenNebulaTemplate oned_config(get_defaults_location(), get_var_location(), oned_filename); if (oned_config.load_configuration() != 0) { diff --git a/src/monitor/src/monitor/onemonitord.cc b/src/monitor/src/monitor/onemonitord.cc index 0f96927ecd..303dfad263 100644 --- a/src/monitor/src/monitor/onemonitord.cc +++ b/src/monitor/src/monitor/onemonitord.cc @@ -79,10 +79,19 @@ int main(int argc, char **argv) if ( argv[1] != 0 ) { - //oned passes a single string with all the arguments for monitord + // oned passes all arguments as single string, we need to split + // the first argument and add the rest to allow also execution from + // command line: + // onemonitord -c monitord.conf -o oned.conf std::string argv_1 = argv[1]; std::vector _argv = one_util::split(argv_1, ' '); + + for (int i = 2; i < argc; ++i) + { + _argv.push_back(argv[i]); + } + int _argc = _argv.size() + 1; char ** _argv_c = (char **) malloc(sizeof(char *) * (_argc + 1)); @@ -99,15 +108,15 @@ int main(int argc, char **argv) static struct option long_options[] = { {"version",no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, - {"config", no_argument, 0, 'c'}, - {"oned-config", no_argument, 0, 'o'}, + {"config", required_argument, 0, 'c'}, + {"oned-config", required_argument, 0, 'o'}, {0, 0, 0, 0} }; int long_index = 0; int opt; - while ((opt = getopt_long(_argc, _argv_c, "vhc:", + while ((opt = getopt_long(_argc, _argv_c, "vhc:o:", long_options, &long_index)) != -1) { switch(opt)