log_warning(msg.str());
}
}
+
+
+/**
+ * Starting shutdown
+ */
+void Logger::print_starting_shutdown() const
+{
+ if ( 0 <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Shutting down ..." << endl;
+ log_notice(msg.str());
+ }
+}
+
+
+/**
+ * Shutdown complete
+ */
+void Logger::print_shutdown_succeeded() const
+{
+ if ( 0 <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Shutting down complete ..." << endl;
+ log_notice(msg.str());
+ }
+}
+
+
+/**
+ * Shutdown parent succeeded
+ */
+void Logger::print_shutdown_parent_succeeded() const
+{
+ if ( 0 <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Shutting down parent process completed ..." << endl;
+ log_notice(msg.str());
+ }
+}
+
+
+/**
+ * Starting shutdown parent
+ */
+void Logger::print_starting_shutdown_parent() const
+{
+ if ( 0 <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Shutting down parent process ..." << endl;
+ log_notice(msg.str());
+ }
+}
void print_update_not_allowed(const int current_time, const int old_time, const int MaxUpdatesWithinInterval, const std::string& service) const;
void print_update_service_failure(const std::string& service) const;
+
+ void print_starting_shutdown() const;
+
+ void print_shutdown_succeeded() const;
+
+ void print_shutdown_parent_succeeded() const;
+
+ void print_starting_shutdown_parent() const;
};
#endif
#define REVISION 1
#define RELEASE 0
-#define PIDFILE "/var/run/bpdyndnsd.pid"
+#define PIDFILE "/home/bjoern/intranator/bpdyndnsd/var/run/bpdyndnsd.pid"
#define OBJECT_FILE "/home/bjoern/intranator/bpdyndnsd/objects.ser"
#include <iostream>
/**
+ * Parent shutdown function
+ * @return 0 if all is fine, -1 otherwise
+ */
+int shutdown_parent(bool remove_pid, int ret_val)
+{
+ // starting shutdown_parent
+ updater->get_logger()->print_starting_shutdown_parent();
+
+ // remove pidfile if requested
+ if(remove_pid)
+ unlink(PIDFILE);
+
+ // shutdown parent complete
+ updater->get_logger()->print_shutdown_parent_succeeded();
+
+ // release shared pointer
+ updater.reset();
+
+ exit(ret_val);
+}
+
+
+/**
+ * Shutdown function
+ * @return 0 if all is fine, -1 otherwise
+ */
+int shutdown()
+{
+ int ret_val = 0;
+
+ // starting shutdown
+ updater->get_logger()->print_starting_shutdown();
+
+ // serialize actual service objects
+ if ( updater->get_service_holder()->serialize_services() != 0 )
+ ret_val = -1;
+
+ // unlink pidfile
+ unlink(PIDFILE);
+
+ // shutdown complete
+ updater->get_logger()->print_shutdown_succeeded();
+
+ // release shared pointer
+ updater.reset();
+
+ return ret_val;
+}
+
+
+/**
* Signal SIGTERM caught, releasing resources and exit.
* @param param Parameter from the signal interface.
*/
{
updater->get_logger()->print_caught_sigterm();
- // unfortunately we can't call serialize_services in any destructor
- // cause some singleton are already destroyed !?!
- if ( updater->get_service_holder()->serialize_services() != 0 )
- {
- updater.reset();
- exit(-1);
- }
- updater.reset();
- exit(0);
+ exit(shutdown());
}
-
/**
* Signal SIGUSR1 caught, switching to offline mode.
* @param param Parameter from the signal interface.
if ( write_pidfile(pid) != 0 )
{
if ( kill(pid,SIGTERM) != 0 )
+ {
updater->get_logger()->print_error_kill_child(pid);
+ shutdown_parent(false,-1); // keep pidfile
+ }
else
+ {
updater->get_logger()->print_child_killed(pid);
- exit(-1);
+ shutdown_parent(true,-1); // remove pidfile
+ }
}
updater->get_logger()->print_runnig_as_daemon(pid);
- exit(0);
+ shutdown_parent(false,0); // keep pidfile
}
// child starts here
}
+ else
+ {
+ if ( write_pidfile(getpid()) != 0 )
+ {
+ shutdown();
+ exit(-1);
+ }
+ }
return 0;
}
// Serialize services to save their actual state.
- if ( updater->get_service_holder()->serialize_services() != 0 )
+ if ( shutdown() != 0 )
return -1;
return 0;