Commit 1740704a authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[gitlab1] pid file, signals support implemented for kea-netconf

parent f1ebc54c
......@@ -10,6 +10,10 @@
#include <exceptions/exceptions.h>
#include <dhcpsrv/daemon.h>
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <cstdio>
#include <signal.h>
#include <sysrepo-cpp/Session.h>
......@@ -32,6 +36,32 @@ usage() {
exit(EXIT_FAILURE);
}
/// @name Temporary code until isc::dhcp::Daemon is used.
///
/// @{
const char* PID_FILENAME = "kea-netconf.test_config.pid";
volatile bool SHUTDOWN_FLAG = false;
void
createPIDFile(int pid) {
// This is not a real implemented. We will soon use the one coming
// from isc::dhcp::Daemon AFTER it's moved to libprocess.
ofstream file(PID_FILENAME, ios::trunc);
file << pid;
}
void
deletePIDFile() {
remove(PID_FILENAME);
}
static void signal_handler(int ) {
SHUTDOWN_FLAG = true;
}
/// @}
int
main(int argc, char* argv[]) {
// The standard config file
......@@ -70,10 +100,14 @@ main(int argc, char* argv[]) {
int ret = EXIT_SUCCESS;
try {
// It is important that we set a default logger name because this name
// will be used when the user doesn't provide the logging configuration
// in the Kea configuration file.
//CfgMgr::instance().setDefaultLoggerName(KEA_NETCONF_LOGGER_NAME);
// Temporary code. This will be replaced with isc::dhcp::Daemon
// once it is migrated to libprocess. We DO NOT want to bring
// the whole libdhcpsrv into netconf.
createPIDFile(getpid());
signal(SIGHUP, signal_handler);
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
// Initialize logging. If verbose, we'll use maximum verbosity.
bool verbose_mode = true;
......@@ -86,7 +120,7 @@ main(int argc, char* argv[]) {
LOG_INFO(netconf_logger, NETCONF_STATED).arg(VERSION);
// And run the main loop of the server.
while (true) {
while (!SHUTDOWN_FLAG) {
cout << "Dummy kea-netconf running. Press ctrl-c to terminate."
<< endl;
sleep(1);
......@@ -94,6 +128,8 @@ main(int argc, char* argv[]) {
LOG_INFO(netconf_logger, NETCONF_SHUTDOWN);
deletePIDFile();
} catch (const isc::Exception& ex) {
// First, we parint the error on stderr (that should always work)
cerr << "ERROR:" << ex.what() << endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment