From: Kefu Chai Date: Thu, 3 Jun 2021 05:26:17 +0000 (+0800) Subject: crimson/osd: wait for SIGINT and SIGTERM before stopping X-Git-Tag: v17.1.0~1772^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4945ff12e9e1dc68f884f6fa14f358efd2b44210;p=ceph.git crimson/osd: wait for SIGINT and SIGTERM before stopping this change addresses an regression introduced by 37b83f4ed7ca69f105b93bf482cb2289cbaf9a4d. as we should not stop services without being asked to do so. in this change, signal handler for SIGINT and SIGTERM is registered to handle these signals, and in the seastar thread, we wait until any of these two signals is caught. Signed-off-by: Kefu Chai --- diff --git a/src/crimson/osd/CMakeLists.txt b/src/crimson/osd/CMakeLists.txt index 934f96f3cd34..8bf9c7796ae0 100644 --- a/src/crimson/osd/CMakeLists.txt +++ b/src/crimson/osd/CMakeLists.txt @@ -10,6 +10,7 @@ add_executable(crimson-osd pg_meta.cc replicated_backend.cc shard_services.cc + stop_signal.cc object_context.cc ops_executer.cc osd_operation.cc diff --git a/src/crimson/osd/main.cc b/src/crimson/osd/main.cc index 2024d2bef8f4..4b47d89b1510 100644 --- a/src/crimson/osd/main.cc +++ b/src/crimson/osd/main.cc @@ -23,6 +23,7 @@ #include "global/pidfile.h" #include "osd.h" +#include "stop_signal.h" using config_t = crimson::common::ConfigProxy; @@ -208,6 +209,7 @@ int main(int argc, char* argv[]) return seastar::async([&] { try { FatalSignal fatal_signal; + StopSignal should_stop; if (config.count("debug")) { seastar::global_logger_registry().set_all_loggers_level( seastar::log_level::debug @@ -271,6 +273,10 @@ int main(int argc, char* argv[]) } else { osd.invoke_on(0, &crimson::osd::OSD::start).get(); } + seastar::fprint(std::cout, "crimson startup completed."); + should_stop.wait().get(); + seastar::fprint(std::cout, "crimson shutting down."); + // stop()s registered using defer() are called here } catch (...) { seastar::fprint(std::cerr, "FATAL: startup failed: %s\n", std::current_exception()); return EXIT_FAILURE; diff --git a/src/crimson/osd/stop_signal.cc b/src/crimson/osd/stop_signal.cc new file mode 100644 index 000000000000..975f9edd8274 --- /dev/null +++ b/src/crimson/osd/stop_signal.cc @@ -0,0 +1,33 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*- +// vim: ts=8 sw=2 smarttab + +#include "stop_signal.h" + +#include +#include + +StopSignal::StopSignal() +{ + seastar::engine().handle_signal(SIGINT, [this] { signaled(); }); + seastar::engine().handle_signal(SIGTERM, [this] { signaled(); }); +} + +StopSignal::~StopSignal() +{ + seastar::engine().handle_signal(SIGINT, [] {}); + seastar::engine().handle_signal(SIGTERM, [] {}); +} + +seastar::future<> StopSignal::wait() +{ + return should_stop.wait([this] { return caught; }); +} + +void StopSignal::signaled() +{ + if (caught) { + return; + } + caught = true; + should_stop.signal(); +} diff --git a/src/crimson/osd/stop_signal.h b/src/crimson/osd/stop_signal.h new file mode 100644 index 000000000000..995b7355aaf1 --- /dev/null +++ b/src/crimson/osd/stop_signal.h @@ -0,0 +1,21 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include +#include + +class StopSignal { +public: + StopSignal(); + ~StopSignal(); + seastar::future<> wait(); + +private: + void signaled(); + +private: + bool caught; + seastar::condition_variable should_stop; +};