From d535fab6ac4a025541340ded0d3568f565acf1cd Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Wed, 30 Jul 2014 23:08:43 -0300 Subject: [PATCH] daemons: write pid file even when told not to daemonize systemd wants to run daemons in foreground, but daemons wouldn't write out the pid file with -f. Fixed. Signed-off-by: Alexandre Oliva (cherry picked from commit bccb0eb64891f65fd475e96b6386494044cae8c1) --- src/ceph_mon.cc | 3 +-- src/common/config.cc | 2 -- src/global/global_init.cc | 10 +++++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index 47b6913b77721..80b17a14946c0 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -423,8 +423,7 @@ int main(int argc, const char **argv) // screwing us over Preforker prefork; if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS)) { - if (g_conf->daemonize) { - global_init_prefork(g_ceph_context, 0); + if (global_init_prefork(g_ceph_context, 0) >= 0) { prefork.prefork(); if (prefork.is_parent()) { return prefork.parent_wait(); diff --git a/src/common/config.cc b/src/common/config.cc index 0e28a83b0a44c..23bfe351e634e 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -389,12 +389,10 @@ int md_config_t::parse_argv(std::vector& args) } else if (ceph_argparse_flag(args, i, "--foreground", "-f", (char*)NULL)) { set_val_or_die("daemonize", "false"); - set_val_or_die("pid_file", ""); } else if (ceph_argparse_flag(args, i, "-d", (char*)NULL)) { set_val_or_die("daemonize", "false"); set_val_or_die("log_file", ""); - set_val_or_die("pid_file", ""); set_val_or_die("log_to_stderr", "true"); set_val_or_die("err_to_stderr", "true"); set_val_or_die("log_to_syslog", "false"); diff --git a/src/global/global_init.cc b/src/global/global_init.cc index 7b203433b552d..f03677c028c39 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -166,8 +166,16 @@ int global_init_prefork(CephContext *cct, int flags) if (g_code_env != CODE_ENVIRONMENT_DAEMON) return -1; const md_config_t *conf = cct->_conf; - if (!conf->daemonize) + if (!conf->daemonize) { + if (atexit(pidfile_remove_void)) { + derr << "global_init_daemonize: failed to set pidfile_remove function " + << "to run at exit." << dendl; + } + + pidfile_write(g_conf); + return -1; + } // stop log thread g_ceph_context->_log->flush(); -- 2.39.5