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>
pg_meta.cc
replicated_backend.cc
shard_services.cc
+ stop_signal.cc
object_context.cc
ops_executer.cc
osd_operation.cc
#include "global/pidfile.h"
#include "osd.h"
+#include "stop_signal.h"
using config_t = crimson::common::ConfigProxy;
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
} 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;
--- /dev/null
+// -*- 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();
+}
--- /dev/null
+// -*- 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;
+};