Kea 3.3.3
daemon.h
Go to the documentation of this file.
1// Copyright (C) 2014-2026 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>
14
15#include <boost/noncopyable.hpp>
16#include <boost/date_time/posix_time/posix_time.hpp>
17
18#include <list>
19#include <string>
20
21namespace isc {
22namespace process {
23
25class DaemonPIDExists : public Exception {
26public:
27 DaemonPIDExists(const char* file, size_t line, const char* what) :
28 isc::Exception(file, line, what) { }
29};
30
48class Daemon : public boost::noncopyable {
49
50public:
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,
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
194 std::string getPIDLockName() const;
195
204 void setPIDFileName(const std::string& pid_file_name);
205
219 void createPIDFile(int pid = 0);
220
222 static std::string getDefaultLoggerName() {
223 return (default_logger_name_);
224 }
225
230 static void setDefaultLoggerName(const std::string& logger) {
231 default_logger_name_ = logger;
232 }
233
236 return (exit_value_);
237 }
238
242 void setExitValue(int value) {
243 exit_value_ = value;
244 }
245
254 virtual std::list<std::list<std::string>> jsonPathsToRedact() const;
255
264
268 static bool getShutdownOnFailure() {
269 return (shutdown_on_failure_);
270 }
271
275 static void setShutdownOnFailure(bool shutdown) {
276 shutdown_on_failure_ = shutdown;
277 }
278
282 static bool getCBRepairMode() {
283 return (cb_repair_mode_);
284 }
285
289 static void setCBRepairMode(bool cb_repair_mode) {
290 cb_repair_mode_ = cb_repair_mode;
291 }
292
293protected:
294
301
303 std::string makePIDFileName() const;
304
306 boost::posix_time::ptime start_;
307
308private:
310 std::string config_file_;
311
313 static std::string proc_name_;
314
317 std::string pid_file_dir_;
318
320 isc::util::PIDFilePtr pid_file_;
321
323 static bool verbose_;
324
326 static std::string default_logger_name_;
327
329 bool am_file_author_;
330
333 int exit_value_;
334
337 static bool shutdown_on_failure_;
338
340 static bool cb_repair_mode_;
341};
342
343} // namespace process
344} // namespace isc
345
346#endif
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
DaemonPIDExists(const char *file, size_t line, const char *what)
Definition daemon.h:27
static void setShutdownOnFailure(bool shutdown)
Set the shutdown on critical failure flag.
Definition daemon.h:275
static bool getCBRepairMode()
Get the CB repair mode flag.
Definition daemon.h:282
std::string getConfigFile() const
Returns config file name.
Definition daemon.cc:109
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:271
static std::string getVersion(bool extended)
returns Kea version on stdout and exits.
Definition daemon.cc:104
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
Definition daemon.cc:84
std::string getPIDFileName() const
Returns the current PID file name.
Definition daemon.cc:176
virtual std::list< std::list< std::string > > jsonPathsToRedact() const
Return a list of all paths that contain passwords or secrets.
Definition daemon.cc:293
Daemon()
Default constructor.
Definition daemon.cc:46
static void setCBRepairMode(bool cb_repair_mode)
Set the CB repair mode flag.
Definition daemon.h:289
virtual void shutdown()
Initiates shutdown procedure for the whole server.
Definition daemon.cc:68
std::string getPIDFileDir() const
Returns the directory used when forming default PID file name.
Definition daemon.cc:166
virtual ~Daemon()
Destructor.
Definition daemon.cc:59
isc::asiolink::IOSignalSetPtr signal_set_
A pointer to the object installing custom signal handlers.
Definition daemon.h:300
static void configureLogger(const isc::data::ConstElementPtr &log_config, const isc::process::ConfigPtr &storage)
Configures logger.
Definition daemon.cc:71
boost::posix_time::ptime start_
Timestamp of the start of the daemon.
Definition daemon.h:306
static bool getVerbose()
Returns if running in verbose mode.
Definition daemon.cc:89
static void loggerInit(const char *log_name, bool verbose)
Initializes logger.
Definition daemon.cc:93
void checkWriteConfigFile(std::string &file)
Checks the to-be-written configuration file name.
Definition daemon.cc:134
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
Definition daemon.cc:156
void setExitValue(int value)
Sets the exit value.
Definition daemon.h:242
virtual void cleanup()
Performs final deconfiguration.
Definition daemon.cc:65
isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr const &config)
Redact a configuration.
Definition daemon.cc:299
void checkConfigFile() const
Checks the configuration file name.
Definition daemon.cc:119
static void setDefaultLoggerName(const std::string &logger)
Sets the default logger name.
Definition daemon.h:230
void setPIDFileName(const std::string &pid_file_name)
Sets PID file name.
Definition daemon.cc:194
static void setProcName(const std::string &proc_name)
Sets the process name.
Definition daemon.cc:161
int getExitValue()
Fetches the exit value.
Definition daemon.h:235
void createPIDFile(int pid=0)
Creates the PID file.
Definition daemon.cc:238
void setPIDFileDir(const std::string &pid_file_dir)
Sets the PID file directory.
Definition daemon.cc:171
static std::string getDefaultLoggerName()
Returns default logger name.
Definition daemon.h:222
std::string getPIDLockName() const
Returns the current PID lock file name.
Definition daemon.cc:185
std::string makePIDFileName() const
Manufacture the pid file name.
Definition daemon.cc:209
static bool getShutdownOnFailure()
Get the shutdown on critical failure flag.
Definition daemon.h:268
void setConfigFile(const std::string &config_file)
Sets the configuration file name.
Definition daemon.cc:114
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the ConfigBase.
boost::shared_ptr< PIDFile > PIDFilePtr
Defines a shared pointer to a PIDFile.
Definition pid_file.h:107
Defines the logger used by the top-level component of kea-lfc.