| Kea 3.0.2-git

daemon.h
Go to the documentation of this file.
1// Copyright (C) 2014-2025 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 <asiolink/io_service_signal.h>
14
15#include <boost/noncopyable.hpp>
16#include <boost/date_time/posix_time/posix_time.hpp>
17
18#include <list>
19#include <string>
20
21 namespace isc {
22 namespace process {
23
25 class DaemonPIDExists : public Exception {
26 public:
27 DaemonPIDExists(const char* file, size_t line, const char* what) :
28 isc::Exception(file, line, what) { }
29};
30
48 class Daemon : public boost::noncopyable {
49
50 public:
55 Daemon();
56
61 virtual ~Daemon();
62
71 virtual void cleanup();
72
74 virtual void shutdown();
75
85 static void loggerInit(const char* log_name, bool verbose);
86
97 static void configureLogger(const isc::data::ConstElementPtr& log_config,
98 const isc::process::ConfigPtr& storage);
99
107 static void setVerbose(const bool verbose);
108
112 static bool getVerbose();
113
127 static std::string getVersion(bool extended);
128
131 std::string getConfigFile() const;
132
136 void setConfigFile(const std::string& config_file);
137
140 void checkConfigFile() const;
141
149 void checkWriteConfigFile(std::string& file);
150
166 virtual size_t
167 writeConfigFile(const std::string& config_file,
168 isc::data::ConstElementPtr cfg = isc::data::ConstElementPtr()) const;
169
173 static std::string getProcName();
174
177 static void setProcName(const std::string& proc_name);
178
181 std::string getPIDFileDir() const;
182
186 void setPIDFileDir(const std::string& pid_file_dir);
187
190 std::string getPIDFileName() const;
191
200 void setPIDFileName(const std::string& pid_file_name);
201
213 void createPIDFile(int pid = 0);
214
216 static std::string getDefaultLoggerName() {
217 return (default_logger_name_);
218 }
219
224 static void setDefaultLoggerName(const std::string& logger) {
225 default_logger_name_ = logger;
226 }
227
229 int getExitValue() {
230 return (exit_value_);
231 }
232
236 void setExitValue(int value) {
237 exit_value_ = value;
238 }
239
248 virtual std::list<std::list<std::string>> jsonPathsToRedact() const;
249
257 isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr const& config);
258
259 protected:
260
266 isc::asiolink::IOSignalSetPtr signal_set_;
267
269 std::string makePIDFileName() const;
270
272 boost::posix_time::ptime start_;
273
274 private:
276 std::string config_file_;
277
279 static std::string proc_name_;
280
283 std::string pid_file_dir_;
284
286 isc::util::PIDFilePtr pid_file_;
287
289 static bool verbose_;
290
292 static std::string default_logger_name_;
293
295 bool am_file_author_;
296
299 int exit_value_;
300};
301
302} // namespace process
303} // namespace isc
304
305#endif
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::process::DaemonPIDExists::DaemonPIDExists
DaemonPIDExists(const char *file, size_t line, const char *what)
Definition daemon.h:27
isc::process::Daemon::getConfigFile
std::string getConfigFile() const
Returns config file name.
Definition daemon.cc:104
isc::process::Daemon::writeConfigFile
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:250
isc::process::Daemon::getVersion
static std::string getVersion(bool extended)
returns Kea version on stdout and exits.
Definition daemon.cc:99
isc::process::Daemon::setVerbose
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
Definition daemon.cc:79
isc::process::Daemon::getPIDFileName
std::string getPIDFileName() const
Returns the current PID file name.
Definition daemon.cc:171
isc::process::Daemon::jsonPathsToRedact
virtual std::list< std::list< std::string > > jsonPathsToRedact() const
Return a list of all paths that contain passwords or secrets.
Definition daemon.cc:272
isc::process::Daemon::Daemon
Daemon()
Default constructor.
Definition daemon.cc:41
isc::process::Daemon::shutdown
virtual void shutdown()
Initiates shutdown procedure for the whole server.
Definition daemon.cc:63
isc::process::Daemon::getPIDFileDir
std::string getPIDFileDir() const
Returns the directory used when forming default PID file name.
Definition daemon.cc:161
isc::process::Daemon::~Daemon
virtual ~Daemon()
Destructor.
Definition daemon.cc:54
isc::process::Daemon::signal_set_
isc::asiolink::IOSignalSetPtr signal_set_
A pointer to the object installing custom signal handlers.
Definition daemon.h:266
isc::process::Daemon::configureLogger
static void configureLogger(const isc::data::ConstElementPtr &log_config, const isc::process::ConfigPtr &storage)
Configures logger.
Definition daemon.cc:66
isc::process::Daemon::start_
boost::posix_time::ptime start_
Timestamp of the start of the daemon.
Definition daemon.h:272
isc::process::Daemon::getVerbose
static bool getVerbose()
Returns if running in verbose mode.
Definition daemon.cc:84
isc::process::Daemon::loggerInit
static void loggerInit(const char *log_name, bool verbose)
Initializes logger.
Definition daemon.cc:88
isc::process::Daemon::checkWriteConfigFile
void checkWriteConfigFile(std::string &file)
Checks the to-be-written configuration file name.
Definition daemon.cc:129
isc::process::Daemon::getProcName
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
Definition daemon.cc:151
isc::process::Daemon::setExitValue
void setExitValue(int value)
Sets the exit value.
Definition daemon.h:236
isc::process::Daemon::cleanup
virtual void cleanup()
Performs final deconfiguration.
Definition daemon.cc:60
isc::process::Daemon::redactConfig
isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr const &config)
Redact a configuration.
Definition daemon.cc:278
isc::process::Daemon::checkConfigFile
void checkConfigFile() const
Checks the configuration file name.
Definition daemon.cc:114
isc::process::Daemon::setDefaultLoggerName
static void setDefaultLoggerName(const std::string &logger)
Sets the default logger name.
Definition daemon.h:224
isc::process::Daemon::setPIDFileName
void setPIDFileName(const std::string &pid_file_name)
Sets PID file name.
Definition daemon.cc:180
isc::process::Daemon::setProcName
static void setProcName(const std::string &proc_name)
Sets the process name.
Definition daemon.cc:156
isc::process::Daemon::getExitValue
int getExitValue()
Fetches the exit value.
Definition daemon.h:229
isc::process::Daemon::createPIDFile
void createPIDFile(int pid=0)
Creates the PID file.
Definition daemon.cc:224
isc::process::Daemon::setPIDFileDir
void setPIDFileDir(const std::string &pid_file_dir)
Sets the PID file directory.
Definition daemon.cc:166
isc::process::Daemon::getDefaultLoggerName
static std::string getDefaultLoggerName()
Returns default logger name.
Definition daemon.h:216
isc::process::Daemon::makePIDFileName
std::string makePIDFileName() const
Manufacture the pid file name.
Definition daemon.cc:195
isc::process::Daemon::setConfigFile
void setConfigFile(const std::string &config_file)
Sets the configuration file name.
Definition daemon.cc:109
config_base.h
data.h
io_service_signal.h
isc::asiolink::IOSignalSetPtr
boost::shared_ptr< IOSignalSet > IOSignalSetPtr
Defines a pointer to an IOSignalSet.
Definition io_service_signal.h:55
isc::config
Definition command_interpreter.cc:23
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
isc::process
Definition cb_ctl_base.h:22
isc::process::ConfigPtr
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the ConfigBase.
Definition config_base.h:176
isc::util::PIDFilePtr
boost::shared_ptr< PIDFile > PIDFilePtr
Defines a shared pointer to a PIDFile.
Definition pid_file.h:92
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
pid_file.h