]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: wait for SIGINT and SIGTERM before stopping 41666/head
authorKefu Chai <kchai@redhat.com>
Thu, 3 Jun 2021 05:26:17 +0000 (13:26 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 3 Jun 2021 05:30:01 +0000 (13:30 +0800)
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 <kchai@redhat.com>
src/crimson/osd/CMakeLists.txt
src/crimson/osd/main.cc
src/crimson/osd/stop_signal.cc [new file with mode: 0644]
src/crimson/osd/stop_signal.h [new file with mode: 0644]

index 934f96f3cd34b4ae8ce6e3e880826723190c7cee..8bf9c7796ae02a90c62729243338fd916f0186da 100644 (file)
@@ -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
index 2024d2bef8f471452877761217a02b5604c17319..4b47d89b1510720a232b2a2fce69382d011c4abb 100644 (file)
@@ -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 (file)
index 0000000..975f9ed
--- /dev/null
@@ -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 <csignal>
+#include <seastar/core/reactor.hh>
+
+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 (file)
index 0000000..995b735
--- /dev/null
@@ -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 <seastar/core/condition-variable.hh>
+#include <seastar/core/sharded.hh>
+
+class StopSignal {
+public:
+  StopSignal();
+  ~StopSignal();
+  seastar::future<> wait();
+
+private:
+  void signaled();
+
+private:
+  bool caught;
+  seastar::condition_variable should_stop;
+};