Kea  2.3.2-git
daemon.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2021 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 
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 
157  virtual size_t
158  writeConfigFile(const std::string& config_file,
160 
164  static std::string getProcName();
165 
168  static void setProcName(const std::string& proc_name);
169 
172  std::string getPIDFileDir() const;
173 
177  void setPIDFileDir(const std::string& pid_file_dir);
178 
181  std::string getPIDFileName() const;
182 
191  void setPIDFileName(const std::string& pid_file_name);
192 
204  void createPIDFile(int pid = 0);
205 
207  static std::string getDefaultLoggerName() {
208  return (default_logger_name_);
209  }
210 
215  static void setDefaultLoggerName(const std::string& logger) {
216  default_logger_name_ = logger;
217  }
218 
220  int getExitValue() {
221  return (exit_value_);
222  }
223 
227  void setExitValue(int value) {
228  exit_value_ = value;
229  }
230 
239  virtual std::list<std::list<std::string>> jsonPathsToRedact() const;
240 
249 
250 protected:
251 
258 
260  std::string makePIDFileName() const;
261 
263  boost::posix_time::ptime start_;
264 
265 private:
267  std::string config_file_;
268 
270  static std::string proc_name_;
271 
274  std::string pid_file_dir_;
275 
277  isc::util::PIDFilePtr pid_file_;
278 
280  static bool verbose_;
281 
283  static std::string default_logger_name_;
284 
286  bool am_file_author_;
287 
290  int exit_value_;
291 };
292 
293 } // namespace process
294 } // namespace isc
295 
296 #endif
static std::string getDefaultLoggerName()
Returns default logger name.
Definition: daemon.h:207
boost::posix_time::ptime start_
Timestamp of the start of the daemon.
Definition: daemon.h:263
int getExitValue()
Fetches the exit value.
Definition: daemon.h:220
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static void setDefaultLoggerName(const std::string &logger)
Sets the default logger name.
Definition: daemon.h:215
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
isc::asiolink::IOSignalSetPtr signal_set_
A pointer to the object installing custom signal handlers.
Definition: daemon.h:257
ConstElementPtr redactConfig(ConstElementPtr const &element, list< string > const &json_path)
Redact a configuration.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
isc::log::Logger logger("asiodns")
Use the ASIO logger.
void setExitValue(int value)
Sets the exit value.
Definition: daemon.h:227
boost::shared_ptr< PIDFile > PIDFilePtr
Defines a shared pointer to a PIDFile.
Definition: pid_file.h:92
Base class for all services.
Definition: daemon.h:48
DaemonPIDExists(const char *file, size_t line, const char *what)
Definition: daemon.h:27
Exception thrown when the PID file points to a live PID.
Definition: daemon.h:25
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the ConfigBase.
Definition: config_base.h:176