Added chkconfig runlevel info.
[bpdyndnsd] / src / updater.cpp
CommitLineData
b1be615b
BS
1/** @file
2 * @brief The updater class implementation. This class implements the updater logic.
3 *
4 *
5 *
6 * @copyright Intra2net AG
7 * @license GPLv2
8*/
9
4545a371
BS
10#include "updater.h"
11
12#include <boost/foreach.hpp>
13
8bca3c5d 14using namespace std;
527536b3 15
b1be615b
BS
16/**
17 * Default constructor which initializes the member Conf.
18 */
4545a371
BS
19Updater::Updater()
20{
254bbf53
BS
21 // initialize Logger
22 LoggerPtr _log(new Logger);
23 Log = _log;
4545a371 24
254bbf53
BS
25 // initialize Config
26 ConfigPtr _config(new Config(Log));
27 Conf = _config;
527536b3 28
254bbf53 29 Log->print_constructor_call("Updater");
4545a371
BS
30}
31
527536b3 32
b1be615b
BS
33/**
34 * Default destructor.
35 */
4545a371
BS
36Updater::~Updater()
37{
254bbf53 38 Log->print_destructor_call("Updater");
4545a371
BS
39}
40
527536b3 41
b1be615b 42/**
254bbf53
BS
43 * Parse the command line arguments and initialize corresponding options.
44 * @param argc Number command line arguments.
45 * @param argv[] Array with arguments.
46 * @return 0 if cmd options successfully parsed, 1 if usage or version.
38060291 47 */
254bbf53 48int Updater::init_config_from_cmd(int argc, char *argv[])
38060291
BS
49{
50 // Load the command line parameters
254bbf53
BS
51 if( Conf->parse_cmd_line( argc, argv ) != 0)
52 return 1;
38060291 53
59c8d63c
BS
54 // If we have loaded the cmd options we need to init the log facility immediately in case debugging is enabled from cmd.
55 init_log_facility();
56
254bbf53
BS
57 // successful parsed
58 Log->print_cmd_parsed();
38060291
BS
59 return 0;
60}
61
62
63/**
254bbf53
BS
64 * Load the main config and the service definition files in config path.
65 * @return 0 if all is fine,
b1be615b 66 */
254bbf53 67int Updater::init_config_from_files()
4545a371 68{
254bbf53
BS
69 // Load the main and service config files in config path
70 if( Conf->load_config_from_files() != 0)
71 return 1;
4545a371 72
59c8d63c
BS
73 // Re-init log facility, perhaps new config file options for logger are set.
74 // These config file options will only overwrite the cmd options if the SIGHUP (reload config) is caught.
75 init_log_facility();
76
254bbf53
BS
77 // successful loaded
78 return 0;
4545a371
BS
79}
80
527536b3 81
b1be615b 82/**
3434b35f
BS
83 * Getter for member Config.
84 * @return Member Config.
85 */
86ConfigPtr Updater::get_config()
87{
88 return Conf;
89}
90
91
92/**
93 * Getter for member Logger.
94 * @return Member Logger.
95 */
96LoggerPtr Updater::get_logger()
97{
98 return Log;
99}
100
101
102/**
c5675c01
BS
103 * Reloading the config. Delete all Service objects and then init new Service objects from config files.
104 */
105void Updater::reload_config()
106{
8bca3c5d 107 // delete all service objects
c5675c01 108 Conf->delete_services();
8bca3c5d
BS
109
110 // delete the actual Variables_map, perhaps with old cmd options which would overwrite new config file options.
111 Conf->delete_variables_map();
112
113 // load only config files
c5675c01 114 init_config_from_files();
8bca3c5d
BS
115}
116
117
118void Updater::init_log_facility()
119{
120 Log->set_log_facility(Conf->get_loglevel(),Conf->get_syslog());
121 Log->print_init_log_facility();
c5675c01
BS
122}
123
124
125/**
b1be615b
BS
126 * Update all configured services.
127 */
4545a371
BS
128void Updater::update_services()
129{
85a0abf9 130 list<ServicePtr> services = this->Conf->get_services();
4545a371
BS
131
132 string ip = "192.168.1.1";
133
85a0abf9 134 BOOST_FOREACH( ServicePtr service, services )
4545a371
BS
135 {
136 service->update(ip);
137 }
b1be615b 138}