Kea 1.5.0
daemon.h
Go to the documentation of this file.
1// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef DAEMON_H
8#define DAEMON_H
9
10#include <cc/data.h>
11#include <process/config_base.h>
12#include <util/pid_file.h>
13#include <util/signal_set.h>
14#include <boost/noncopyable.hpp>
15#include <string>
16
17namespace isc {
18namespace process {
19
21class DaemonPIDExists : public Exception {
22public:
23 DaemonPIDExists(const char* file, size_t line, const char* what) :
24 isc::Exception(file, line, what) { };
25};
26
49class Daemon : public boost::noncopyable {
50
51public:
56 Daemon();
57
62 virtual ~Daemon();
63
72 virtual void cleanup();
73
75 virtual void shutdown();
76
86 static void loggerInit(const char* log_name, bool verbose);
87
98 static void configureLogger(const isc::data::ConstElementPtr& log_config,
99 const isc::process::ConfigPtr& storage);
100
108 static void setVerbose(const bool verbose);
109
113 static bool getVerbose();
114
128 static std::string getVersion(bool extended);
129
132 std::string getConfigFile() const;
133
137 void setConfigFile(const std::string& config_file);
138
141 void checkConfigFile() const;
142
158 virtual size_t
159 writeConfigFile(const std::string& config_file,
161
165 std::string getProcName() const;
166
169 void setProcName(const std::string& proc_name);
170
173 std::string getPIDFileDir() const;
174
178 void setPIDFileDir(const std::string& pid_file_dir);
179
182 std::string getPIDFileName() const;
183
192 void setPIDFileName(const std::string& pid_file_name);
193
205 void createPIDFile(int pid = 0);
206
208 static std::string getDefaultLoggerName() {
209 return (default_logger_name_);
210 }
211
216 static void setDefaultLoggerName(const std::string& logger) {
217 default_logger_name_ = logger;
218 }
219
220protected:
221
231 virtual void handleSignal();
232
239
247
249 std::string makePIDFileName() const;
250
251private:
253 std::string config_file_;
254
256 std::string proc_name_;
257
260 std::string pid_file_dir_;
261
263 isc::util::PIDFilePtr pid_file_;
264
266 static bool verbose_;
267
269 static std::string default_logger_name_;
270
272 bool am_file_author_;
273};
274
275}; // end of isc::dhcp namespace
276}; // end of isc namespace
277
278#endif
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception thrown when a the PID file points to a live PID.
Definition: daemon.h:21
DaemonPIDExists(const char *file, size_t line, const char *what)
Definition: daemon.h:23
Base class for all services.
Definition: daemon.h:49
std::string getConfigFile() const
Returns config file name.
Definition: daemon.cc:105
virtual size_t writeConfigFile(const std::string &config_file, isc::data::ConstElementPtr cfg=isc::data::ConstElementPtr()) const
Writes current configuration to specified file.
Definition: daemon.cc:229
isc::util::SignalSetPtr signal_set_
A pointer to the object installing custom signal handlers.
Definition: daemon.h:238
static std::string getVersion(bool extended)
returns Kea version on stdout and exits.
Definition: daemon.cc:100
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
Definition: daemon.cc:79
isc::util::SignalHandler signal_handler_
Pointer to the common signal handler invoked by the handleSignal function.
Definition: daemon.h:246
std::string getPIDFileName() const
Returns the current PID file name.
Definition: daemon.cc:150
Daemon()
Default constructor.
Definition: daemon.cc:34
virtual void shutdown()
Initiates shutdown procedure for the whole DHCPv6 server.
Definition: daemon.cc:56
std::string getPIDFileDir() const
Returns the directory used when forming default PID file name.
Definition: daemon.cc:140
virtual ~Daemon()
Destructor.
Definition: daemon.cc:46
static void configureLogger(const isc::data::ConstElementPtr &log_config, const isc::process::ConfigPtr &storage)
Configures logger.
Definition: daemon.cc:66
virtual void handleSignal()
Invokes handler for the next received signal.
Definition: daemon.cc:60
static bool getVerbose()
Returns if running in verbose mode.
Definition: daemon.cc:84
static void loggerInit(const char *log_name, bool verbose)
Initializes logger.
Definition: daemon.cc:88
virtual void cleanup()
Performs final deconfiguration.
Definition: daemon.cc:52
void checkConfigFile() const
Checks the configuration file name.
Definition: daemon.cc:115
static void setDefaultLoggerName(const std::string &logger)
Sets the default logger name.
Definition: daemon.h:216
void setPIDFileName(const std::string &pid_file_name)
Sets PID file name.
Definition: daemon.cc:159
void setProcName(const std::string &proc_name)
Sets the process name.
Definition: daemon.cc:135
void createPIDFile(int pid=0)
Creates the PID file.
Definition: daemon.cc:203
void setPIDFileDir(const std::string &pid_file_dir)
Sets the PID file directory.
Definition: daemon.cc:145
std::string getProcName() const
returns the process name This value is used as when forming the default PID file name
Definition: daemon.cc:130
static std::string getDefaultLoggerName()
Returns default logger name.
Definition: daemon.h:208
std::string makePIDFileName() const
Manufacture the pid file name.
Definition: daemon.cc:174
void setConfigFile(const std::string &config_file)
Sets the configuration file name.
Definition: daemon.cc:110
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the SrvConfig.
Definition: config_base.h:119
boost::shared_ptr< PIDFile > PIDFilePtr
Defines a shared pointer to a PIDFile.
Definition: pid_file.h:92
boost::shared_ptr< SignalSet > SignalSetPtr
Pointer to the isc::util::SignalSet.
Definition: signal_set.h:45
boost::function< void(int signum)> SignalHandler
Pointer to the signal handling function.
Definition: signal_set.h:47
Defines the logger used by the top-level component of kea-dhcp-ddns.