From patchwork Thu Jul 31 02:08:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 4652841 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BEE5F9F36A for ; Thu, 31 Jul 2014 02:13:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DC25B20145 for ; Thu, 31 Jul 2014 02:13:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B27F201BB for ; Thu, 31 Jul 2014 02:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752578AbaGaCNW (ORCPT ); Wed, 30 Jul 2014 22:13:22 -0400 Received: from linux-libre.fsfla.org ([208.118.235.54]:58492 "EHLO linux-libre.fsfla.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751028AbaGaCNV (ORCPT ); Wed, 30 Jul 2014 22:13:21 -0400 X-Greylist: delayed 318 seconds by postgrey-1.27 at vger.kernel.org; Wed, 30 Jul 2014 22:13:19 EDT Received: from freie.home (home.lxoliva.fsfla.org [172.31.160.22]) by linux-libre.fsfla.org (8.14.4/8.14.4/Debian-2ubuntu2.1) with ESMTP id s6V28xHq020426 for ; Thu, 31 Jul 2014 02:09:00 GMT Received: from free.home (free.home [172.31.160.1]) by freie.home (8.14.8/8.14.7) with ESMTP id s6V28iqF005036; Wed, 30 Jul 2014 23:08:44 -0300 From: Alexandre Oliva To: ceph-devel@vger.kernel.org Subject: [PATCH] daemons: write pid file even when told not to daemonize Organization: Free thinker, not speaking for the GNU Project Date: Wed, 30 Jul 2014 23:08:43 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP systemd wants to run daemons in foreground, but daemons wouldn't write out the pid file with -f. Fixed. Signed-off-by: Alexandre Oliva --- 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 4e84b4d..14dd6da 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -406,8 +406,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 0ee7f58..4e3b6fe 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 7b20343..f03677c 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();