return Opt_desc_conf_service;
}
+
/**
* Getter for member Loglevel.
* @return Member Loglevel.
return Loglevel;
}
+
/**
* Getter for member Daemon_mode.
* @return TRUE if enabled, FALSE if disabled.
{
return Daemon_mode;
}
+
+
+/**
+ * Resets all shared Service pointers and clears the Services list.
+ */
+void Config::delete_services()
+{
+ BOOST_FOREACH( ServicePtr service, Services )
+ {
+ service.reset();
+ }
+ Services.clear();
+}
}
+/**
+ * Process running as daemon.
+ * @param pid The pid of the daemon.
+ */
void Logger::print_runnig_as_daemon(const int pid)
{
cout << "Runnig as daemon: " << pid << endl;
}
+
+/**
+ * Prints out the daemon mode.
+ * @param daemon_mode The daemon mode.
+ */
void Logger::print_daemon_mode(const bool daemon_mode)
{
string mode = "disabled";
}
+/**
+ * There was an error while trying to fork.
+ */
void Logger::print_error_fork()
{
cerr << "Error while trying to fork." << endl;
}
+/**
+ * A pid in the pidfile was found.
+ * @param pid The pid found in the pidfile.
+ */
void Logger::print_pid_found(const int pid)
{
cout << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl;
}
+/**
+ * Another process is already running.
+ * @param pid The pid of the other process.
+ */
void Logger::print_process_already_running(const int pid)
{
cerr << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl;
}
+
+
+/**
+ * SIGTERM caught.
+ */
+void Logger::print_caught_sigterm()
+{
+ cout << "Caught SIGTERM. Exiting..." << endl;
+}
+
+
+/**
+ * SIGUSR1 caught.
+ */
+void Logger::print_caught_siguser1()
+{
+ cout << "Caught SIGUSR1. Switching to offline mode..." << endl;
+}
+
+
+/**
+ * SIGHUP caught.
+ */
+void Logger::print_caught_sighup()
+{
+ cout << "Caught SIGHUP. Reloading config and switching to online mode..." << endl;
+}
typedef boost::shared_ptr<Updater> UpdaterPtr;
+UpdaterPtr updater;
+bool online_mode = 1;
+
/**
* Checks if a bpdyndnsd process is already running.
* @param updater Shared Pointer to updater, needed for logging.
* @return 0 if process not running already or pid of already running process.
*/
-int check_for_running_process(UpdaterPtr updater)
+int check_for_running_process()
{
ifstream pidfile(PIDFILE);
if ( pidfile.is_open() )
return 0;
}
+
+/**
+ * Writes the pid into the pidfile.
+ * @param pid The process's pid.
+ */
void write_pidfile(int pid)
{
ofstream pidfile(PIDFILE);
pidfile.close();
}
+
+/**
+ * Signal SIGTERM caught, releasing resources and exit.
+ * @param param Parameter from the signal interface.
+ */
+void terminate(int param)
+{
+ updater->get_logger()->print_caught_sigterm();
+ updater.reset();
+ exit(1);
+}
+
+
+/**
+ * Signal SIGUSR1 caught, switching to offline mode.
+ * @param param Parameter from the signal interface.
+ */
+void switch_to_offline(int param)
+{
+ online_mode = 0;
+}
+
+
+/**
+ * Signal SIGHUP caught, reloading config and switching to online mode.
+ * @param param
+ */
+void reload_config(int param)
+{
+ updater->reload_config();
+ online_mode = 1;
+}
+
+
+/**
+ * Initialize the signals we handle.
+ */
+void init_signals()
+{
+ signal(SIGTERM,terminate);
+ signal(SIGUSR1,switch_to_offline);
+ signal(SIGHUP,reload_config);
+}
+
+
/**
* @brief The main part.
* @param argc Number of arguments
int main(int argc, char *argv[])
{
// initialize Updater
- UpdaterPtr updater(new Updater);
+ UpdaterPtr _updater(new Updater);
+ updater = _updater;
+ _updater.reset();
// load the cmd options
if ( updater->init_config_from_cmd(argc,argv) != 0 )
return 0;
// open pidfile and check for running process
- if ( check_for_running_process(updater) != 0)
+ if ( check_for_running_process() != 0)
return 0;
+ // init signal handling
+ init_signals();
+
// set the configured loggin facility, default stdout
// initialize daemon mode if configured
// service processing starts here
do
{
- // update all configured services
- updater->update_services();
- sleep(3);
+ if ( online_mode == 1 )
+ {
+ // update all configured services
+ updater->update_services();
+ }
+ sleep(2);
}while ( daemon_mode == 1 );