README: Point to remote-testbed.googlecode.com for more info
[remote/remote-mci.git] / diku_mcs / Configuration.cc
blobabb844f6c3f36bfa00e8de7ba774f7d6fee9b4ab
1 #include "Configuration.h"
3 namespace remote { namespace diku_mcs {
5 void Configuration::printHelp(po::options_description& desc)
7 std::cerr << PACKAGE_NAME << " (MCH) version " << PACKAGE_VERSION
8 << std::endl << std::endl
9 << desc
10 << std::endl;
11 exit(0);
14 void Configuration::read(int argc, char **argv)
16 // command line options
17 po::options_description cmdline_options("Command line options");
19 cmdline_options.add_options()
20 ("help", "Print usage help and exit")
21 ("config-help", "Print config file usage help and exit")
22 ("config-file",
23 po::value<std::string>()->default_value("/etc/diku_mcs.cfg"),
24 "Path to the configuration file.")
25 ("daemonize",
26 po::value<int>()->default_value(false),
27 "Run as a daemon.");
29 // declare all configuration groups
30 po::options_description config("Configuration options");
32 config.add_options()
33 ("dbName",
34 po::value<std::string>(),
35 "Name of the infrastructure database.")
36 ("dbHost",
37 po::value<std::string>(),
38 "Host name of the infrastructure database server.")
39 ("dbUser",
40 po::value<std::string>(),
41 "User name for the infrastructure database.")
42 ("dbPassword",
43 po::value<std::string>(),
44 "Password for the infrastructure database.")
45 ("sessionListenerPort",
46 po::value<unsigned int>()->default_value(10000),
47 "Port number to use when listening for new sessions.")
48 ("hostListenerPort",
49 po::value<unsigned int>()->default_value(10001),
50 "Port number to use when listening for new hosts.")
51 ("log-file",
52 po::value<std::string>()->default_value("/var/log/diku_mcs.log"),
53 "Path to the output log file when running as a daemon.")
54 ("errorlog-file",
55 po::value<std::string>()->default_value("/var/log/diku_mcs_error.log"),
56 "Path to the error log file when running as a daemon.")
59 try {
60 store(po::parse_command_line(argc, argv, cmdline_options), vm);
61 } catch (boost::program_options::error exception) {
62 std::cerr << "Error while parsing command line options: "
63 << exception.what() << std::endl << std::endl;
64 printHelp(cmdline_options);
66 notify(vm);
68 if (vm.count("help"))
69 printHelp(cmdline_options);
70 if (vm.count("config-help"))
71 printHelp(config);
73 // get the configuration settings from a file
74 std::ifstream ifs(Configuration::vm["config-file"].as<std::string>().c_str());
75 try {
76 store(parse_config_file(ifs, config), vm);
77 } catch (boost::program_options::error exception) {
78 std::cerr << "Error while parsing configuration file: "
79 << exception.what() << std::endl << std::endl;
80 printHelp(config);
82 notify(vm);
85 po::variables_map Configuration::vm;