From 5bdd09d08a4950f71c01e9198924555c5fa5fb6c Mon Sep 17 00:00:00 2001 From: Takuya ASADA Date: Wed, 10 Jun 2020 06:35:44 +0900 Subject: [PATCH] supervisor: drop unused Upstart code, always use libsystemd Since we don't support Ubuntu 14.04 anymore, we can drop Upstart related code from supervisor.[cc|hh]. Also, "#ifdef HAVE_LIBSYSTEMD" was for compiling Scylla on older distribution which does not provide libsystemd, we nolonger need this since we always build Scylla on latest Fedora. Dropping HAVE_LIBSYSTEMD also means removing libsystemd from optional_packages in configure.py, make it required library. Note that we still may run Scylla without systemd such as our Docker image, but sd_notify() does nothing when systemd does not detected, so we can ignore such case. Reference: https://www.freedesktop.org/software/systemd/man/sd_notify.html Reference: https://github.com/systemd/systemd/blob/master/src/libsystemd/sd-daemon/sd-daemon.c --- configure.py | 25 ++--------------- supervisor.cc | 76 --------------------------------------------------- supervisor.hh | 26 ++++++++++++------ 3 files changed, 20 insertions(+), 107 deletions(-) delete mode 100644 supervisor.cc diff --git a/configure.py b/configure.py index daeedfd80c..5bc1654512 100755 --- a/configure.py +++ b/configure.py @@ -510,7 +510,6 @@ scylla_core = (['database.cc', 'frozen_mutation.cc', 'memtable.cc', 'schema_mutations.cc', - 'supervisor.cc', 'utils/logalloc.cc', 'utils/large_bitset.cc', 'utils/buffer_input_stream.cc', @@ -1087,34 +1086,14 @@ else: # a list element means a list of alternative packages to consider # the first element becomes the HAVE_pkg define # a string element is a package name with no alternatives -optional_packages = [['libsystemd', 'libsystemd-daemon']] +optional_packages = [[]] pkgs = [] # Lua can be provided by lua53 package on Debian-like # systems and by Lua on others. pkgs.append('lua53' if have_pkg('lua53') else 'lua') - -def setup_first_pkg_of_list(pkglist): - # The HAVE_pkg symbol is taken from the first alternative - upkg = pkglist[0].upper().replace('-', '_') - for pkg in pkglist: - if have_pkg(pkg): - pkgs.append(pkg) - defines.append('HAVE_{}=1'.format(upkg)) - return True - return False - - -for pkglist in optional_packages: - if isinstance(pkglist, str): - pkglist = [pkglist] - if not setup_first_pkg_of_list(pkglist): - if len(pkglist) == 1: - print('Missing optional package {pkglist[0]}'.format(**locals())) - else: - alternatives = ':'.join(pkglist[1:]) - print('Missing optional package {pkglist[0]} (or alteratives {alternatives})'.format(**locals())) +pkgs.append('libsystemd') compiler_test_src = ''' diff --git a/supervisor.cc b/supervisor.cc deleted file mode 100644 index f6c89150d6..0000000000 --- a/supervisor.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2017 ScyllaDB - */ - -/* - * This file is part of Scylla. - * - * Scylla is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Scylla is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Scylla. If not, see . - */ - -#include "supervisor.hh" -#include "log.hh" -#include -#include -#include - -#ifdef HAVE_LIBSYSTEMD -#include -#endif - -extern logger startlog; - -const sstring supervisor::scylla_upstart_job_str("scylla-server"); -const sstring supervisor::upstart_job_env("UPSTART_JOB"); -const sstring supervisor::systemd_ready_msg("READY=1"); -const sstring supervisor::systemd_status_msg_prefix("STATUS"); - -sstring supervisor::get_upstart_job_env() { - const char* upstart_job = std::getenv(upstart_job_env.c_str()); - return !upstart_job ? "" : upstart_job; -} - -bool supervisor::try_notify_upstart(sstring msg, bool ready) { - static const sstring upstart_job_str(get_upstart_job_env()); - - if (upstart_job_str != scylla_upstart_job_str) { - return false; - } - - if (ready) { - std::raise(SIGSTOP); - } - - return true; -} - -void supervisor::try_notify_systemd(sstring msg, bool ready) { -#ifdef HAVE_LIBSYSTEMD - if (ready) { - sd_notify(0, format("{}\n{}={}\n", systemd_ready_msg, systemd_status_msg_prefix, msg).c_str()); - } else { - sd_notify(0, format("{}={}\n", systemd_status_msg_prefix, msg).c_str()); - } -#endif -} - -void supervisor::notify(sstring msg, bool ready) { - startlog.info("{}", msg); - - if (try_notify_upstart(msg, ready) == true) { - return; - } else { - try_notify_systemd(msg, ready); - } -} diff --git a/supervisor.hh b/supervisor.hh index a8d120f288..3575910ea6 100644 --- a/supervisor.hh +++ b/supervisor.hh @@ -22,25 +22,35 @@ #pragma once #include +#include #include "seastarx.hh" +#include +#include "log.hh" + +extern logger startlog; class supervisor { public: - static const sstring scylla_upstart_job_str; - static const sstring upstart_job_env; - static const sstring systemd_ready_msg; + static constexpr auto systemd_ready_msg = "READY=1"; /** A systemd status message has a format = */ - static const sstring systemd_status_msg_prefix; + static constexpr auto systemd_status_msg_prefix = "STATUS"; public: /** * @brief Notify the Supervisor with the given message. * @param msg message to notify the Supervisor with * @param ready set to TRUE when scylla service becomes ready */ - static void notify(sstring msg, bool ready = false); + static inline void notify(sstring msg, bool ready = false) { + startlog.info("{}", msg); + try_notify_systemd(msg, ready); + } private: - static void try_notify_systemd(sstring msg, bool ready); - static bool try_notify_upstart(sstring msg, bool ready); - static sstring get_upstart_job_env(); + static inline void try_notify_systemd(sstring msg, bool ready) { + if (ready) { + sd_notify(0, format("{}\n{}={}\n", systemd_ready_msg, systemd_status_msg_prefix, msg).c_str()); + } else { + sd_notify(0, format("{}={}\n", systemd_status_msg_prefix, msg).c_str()); + } + } };