]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: use code_environment_t for daemon-ness in config
authorJohn Spray <john.spray@redhat.com>
Mon, 24 Jul 2017 10:01:36 +0000 (06:01 -0400)
committerJohn Spray <john.spray@redhat.com>
Mon, 24 Jul 2017 13:03:59 +0000 (09:03 -0400)
...and reinstate the set_daemon_default versions of config options
in place of the special casing in common_init.

Signed-off-by: John Spray <john.spray@redhat.com>
src/common/ceph_context.cc
src/common/ceph_context.h
src/common/common_init.cc
src/common/options.cc

index 1d5c6facadeef355963f62d36ebd36de59e0dd56..2cf0f7d8c5866a474fe69addc71921afef23a787 100644 (file)
@@ -550,21 +550,11 @@ void CephContext::do_command(std::string command, cmdmap_t& cmdmap,
                         << "result is " << out->length() << " bytes" << dendl;
 }
 
-
-static bool is_daemon(uint32_t module_type)
-{
-  if (module_type == CEPH_ENTITY_TYPE_OSD ||
-      module_type == CEPH_ENTITY_TYPE_MDS ||
-      module_type == CEPH_ENTITY_TYPE_MON) {
-    return true;
-  } else {
-    return false;
-  }
-}
-
-CephContext::CephContext(uint32_t module_type_, int init_flags_)
+CephContext::CephContext(uint32_t module_type_,
+                         enum code_environment_t code_env,
+                         int init_flags_)
   : nref(1),
-    _conf(new md_config_t(is_daemon(module_type_))),
+    _conf(new md_config_t(code_env == CODE_ENVIRONMENT_DAEMON)),
     _log(NULL),
     _module_type(module_type_),
     _init_flags(init_flags_),
index 64aec93f768e4d39c08db6540a52ede193f2e18a..e024dba70f2ac08f93467acd237affc7007052cf 100644 (file)
@@ -20,6 +20,7 @@
 #include <boost/noncopyable.hpp>
 
 #include "common/cmdparse.h"
+#include "common/code_environment.h"
 #include "crush/CrushLocation.h"
 #include "include/Spinlock.h"
 
@@ -50,7 +51,9 @@ namespace ceph {
  */
 class CephContext {
 public:
-  CephContext(uint32_t module_type_, int init_flags_ = 0);
+  CephContext(uint32_t module_type_,
+              enum code_environment_t code_env=CODE_ENVIRONMENT_UTILITY,
+              int init_flags_ = 0);
 
   // ref count!
 private:
index a62f67e2ee7fe59e7d24cbf8c2a9c74cce471e46..b74633cf94879eb24be62acb450a9566bd54c256 100644 (file)
@@ -32,7 +32,7 @@ CephContext *common_preinit(const CephInitParameters &iparams,
   g_code_env = code_env;
 
   // Create a configuration object
-  CephContext *cct = new CephContext(iparams.module_type, flags);
+  CephContext *cct = new CephContext(iparams.module_type, code_env, flags);
 
   md_config_t *conf = cct->_conf;
   // add config observers here
@@ -43,44 +43,19 @@ CephContext *common_preinit(const CephInitParameters &iparams,
   if (data_dir_option)
     conf->data_dir_option = data_dir_option;
 
-  // Set some defaults based on code type
-  switch (code_env) {
-  case CODE_ENVIRONMENT_DAEMON:
-    conf->set_val_or_die("daemonize", "true");
-    conf->set_val_or_die("log_to_stderr", "false");
-    conf->set_val_or_die("err_to_stderr", "true");
-
-    // different default keyring locations for osd and mds.  this is
-    // for backward compatibility.  moving forward, we want all keyrings
-    // in these locations.  the mon already forces $mon_data/keyring.
-    if (conf->name.is_mds())
-      conf->set_val("keyring", "$mds_data/keyring", false);
-    else if (conf->name.is_osd())
-      conf->set_val("keyring", "$osd_data/keyring", false);
-    break;
-
-  case CODE_ENVIRONMENT_UTILITY_NODOUT:
-  case CODE_ENVIRONMENT_LIBRARY:
+  // different default keyring locations for osd and mds.  this is
+  // for backward compatibility.  moving forward, we want all keyrings
+  // in these locations.  the mon already forces $mon_data/keyring.
+  if (conf->name.is_mds()) {
+    conf->set_val("keyring", "$mds_data/keyring", false);
+  } else if (conf->name.is_osd()) {
+    conf->set_val("keyring", "$osd_data/keyring", false);
+  }
+
+  if (code_env == CODE_ENVIRONMENT_LIBRARY) {
     conf->set_val_or_die("log_to_stderr", "false");
     conf->set_val_or_die("err_to_stderr", "false");
     conf->set_val_or_die("log_flush_on_exit", "false");
-    break;
-
-  default:
-    break;
-  }
-
-  if (flags & CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS) {
-    // do nothing special!  we used to do no default log, pid_file,
-    // admin_socket, but changed our minds.  let's make ceph-fuse
-    // and radosgw use the same defaults as ceph-{osd,mon,mds,...}
-  } else if (code_env != CODE_ENVIRONMENT_DAEMON) {
-    // no default log, pid_file, admin_socket
-    conf->set_val_or_die("pid_file", "");
-    conf->set_val_or_die("admin_socket", "");
-    conf->set_val_or_die("log_file", "");
-    // use less memory for logs
-    conf->set_val_or_die("log_max_recent", "500");
   }
 
   return cct;
index 4bbe7693998ed3efc80a442a1fb075e8897bd6e8..7a333f01d1e8694e9875ea6a08e6efbae6c6f224 100644 (file)
@@ -205,7 +205,8 @@ std::vector<Option> global_options = {
   .add_see_also("admin_socket"),
 
   Option("admin_socket", Option::TYPE_STR, Option::LEVEL_ADVANCED)
-  .set_default("$run_dir/$cluster-$name.asok")
+  .set_default("")
+  .set_daemon_default("$run_dir/$cluster-$name.asok")
   .set_description("path for the runtime control socket file, used by the 'ceph daemon' command")
   .add_service("common"),
 
@@ -221,6 +222,7 @@ std::vector<Option> global_options = {
   // daemon
   Option("daemonize", Option::TYPE_BOOL, Option::LEVEL_ADVANCED)
   .set_default(false)
+  .set_daemon_default(true)
   .set_description("whether to daemonize (background) after startup")
   .add_service("mon mgr osd mds")
   .add_tag("service")
@@ -280,7 +282,8 @@ std::vector<Option> global_options = {
 
   // logging
   Option("log_file", Option::TYPE_STR, Option::LEVEL_BASIC)
-  .set_default("/var/log/ceph/$cluster-$name.log")
+  .set_default("")
+  .set_daemon_default("/var/log/ceph/$cluster-$name.log")
   .set_description("path to log file")
   .add_see_also("log_to_stderr")
   .add_see_also("err_to_stderr")
@@ -293,16 +296,19 @@ std::vector<Option> global_options = {
   .add_see_also("log_max_recent"),
 
   Option("log_max_recent", Option::TYPE_INT, Option::LEVEL_ADVANCED)
-  .set_default(10000)
+  .set_default(500)
+  .set_daemon_default(10000)
   .set_description("recent log entries to keep in memory to dump in the event of a crash")
   .set_long_description("The purpose of this option is to log at a higher debug level only to the in-memory buffer, and write out the detailed log messages only if there is a crash.  Only log entries below the lower log level will be written unconditionally to the log.  For example, debug_osd=1/5 will write everything <= 1 to the log unconditionally but keep entries at levels 2-5 in memory.  If there is a seg fault or assertion failure, all entries will be dumped to the log."),
 
   Option("log_to_stderr", Option::TYPE_BOOL, Option::LEVEL_BASIC)
   .set_default(true)
+  .set_daemon_default(false)
   .set_description("send log lines to stderr"),
 
   Option("err_to_stderr", Option::TYPE_BOOL, Option::LEVEL_BASIC)
   .set_default(false)
+  .set_daemon_default(true)
   .set_description("send critical error log lines to stderr"),
 
   Option("log_to_syslog", Option::TYPE_BOOL, Option::LEVEL_BASIC)