Commit 5776ee0c authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[3769] DHCPv6 now uses PID file

Added PID file creation to DHCP6
    src/bin/dhcp6/dhcp6_messages.mes
    -  added log DHCP6_ALREADY_RUNNING

    src/bin/dhcp6/main.cc
    - added logic to create the PID and catch
    exception specific to PID conflict

    src/bin/dhcp6/tests/Makefile.am
    - exports KEA_PIDFILE_DIR

    src/bin/dhcp6/tests/dhcp6_process_tests.sh.in
    - added call to server_pid_file_test

    src/bin/dhcp6/tests/dhcp6_unittests.cc
    - main(int argc, char* argv[])
    sets env var KEA_PIDFILE_DIR
parent 24267d20
......@@ -70,7 +70,7 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) {
throw; // rethrow it
}
Daemon::setProcName(bin_name_);
setProcName(bin_name_);
// 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
......@@ -187,7 +187,7 @@ DControllerBase::parseArgs(int argc, char* argv[])
isc_throw(InvalidUsage, "configuration file name missing");
}
Daemon::setConfigFile(optarg);
setConfigFile(optarg);
break;
case '?': {
......
......@@ -145,8 +145,9 @@ main(int argc, char* argv[]) {
// Remember verbose-mode
server.setVerbose(verbose_mode);
Daemon::setProcName(DHCP4_NAME);
Daemon::setConfigFile(config_file);
// Create our PID file.
server.setProcName(DHCP4_NAME);
server.setConfigFile(config_file);
server.createPIDFile();
try {
......
......@@ -19,6 +19,16 @@ This message is printed when DHCPv6 server enabled an interface to be used
to receive DHCPv6 traffic. IPv6 socket on this interface will be opened once
Interface Manager starts up procedure of opening sockets.
% DHCP6_ALREADY_RUNNING %1 already running? %2
This is an error message that occurs when the DHCPv6 server encounters
a pre-existing PID file which contains the PID of a running process.
This most likely indicates an attempt to start a second instance of
the server using the same configuration file. It is possible, though
unlikely that the PID file is a remnant left behind by a server crash or
power failure and the PID it contains refers to a process other than
the server. In such an event, it would be necessary to manually remove
the PID file.
% DHCP6_ADD_GLOBAL_STATUS_CODE %1: adding Status Code to DHCPv6 packet: %2
This message is logged when the server is adding the top-level
Status Code option. The first argument includes the client and the
......
......@@ -174,9 +174,6 @@ namespace dhcp {
void
ControlledDhcpv6Srv::init(const std::string& file_name) {
// Call parent class's init to initialize file name.
Daemon::init(file_name);
// Configure the server using JSON file.
configure(file_name);
......
......@@ -148,6 +148,11 @@ main(int argc, char* argv[]) {
// Remember verbose-mode
server.setVerbose(verbose_mode);
// Create our PID file
server.setProcName(DHCP6_NAME);
server.setConfigFile(config_file);
server.createPIDFile();
try {
// Initialize the server, e.g. establish control session
// Read a configuration file
......@@ -177,6 +182,17 @@ main(int argc, char* argv[]) {
LOG_INFO(dhcp6_logger, DHCP6_SHUTDOWN);
} catch (const isc::dhcp::DaemonPIDExists& ex) {
// First, we print the error on stderr (that should always work)
cerr << DHCP6_NAME << " already running? " << ex.what()
<< endl;
// Let's also try to log it using logging system, but we're not
// sure if it's usable (the exception may have been thrown from
// the logger subsystem)
LOG_FATAL(dhcp6_logger, DHCP6_ALREADY_RUNNING)
.arg(DHCP6_NAME).arg(ex.what());
ret = EXIT_FAILURE;
} catch (const std::exception& ex) {
// First, we print the error on stderr (that should always work)
......
......@@ -12,6 +12,7 @@ check-local:
for shtest in $(SHTESTS) ; do \
echo Running test: $$shtest ; \
export KEA_LOCKFILE_DIR=$(abs_top_builddir); \
export KEA_PIDFILE_DIR=$(abs_top_builddir); \
${SHELL} $(abs_builddir)/$$shtest || exit ; \
done
......
......@@ -273,6 +273,7 @@ returned %d."
test_finish 0
}
server_pid_file_test "${CONFIG}" DHCP6_ALREADY_RUNNING
dynamic_reconfiguration_test
shutdown_test "dhcpv6.sigterm_test" 15
shutdown_test "dhcpv6.sigint_test" 2
......
......@@ -22,6 +22,7 @@ main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
isc::log::initLogger();
setenv("KEA_PIDFILE_DIR", TEST_DATA_BUILDDIR, 1);
int result = RUN_ALL_TESTS();
return result;
......
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