]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: semi-clean shutdown on signal
authorSage Weil <sage.weil@dreamhost.com>
Sun, 12 Feb 2012 22:35:03 +0000 (14:35 -0800)
committerSage Weil <sage.weil@dreamhost.com>
Wed, 15 Feb 2012 05:03:54 +0000 (21:03 -0800)
Make some effort to stop work in progress, remove pid file, and exit with
informative error code.

Note that this is much simpler than the shutdown() exit path; I'm not sure
whether a complete teardown is useful.  It's also difficult to maintain
and get right with everything else going on, and it's not clear that it's
worth the effort right now.

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/osd/OSD.cc
src/osd/OSD.h

index 40cd2ac699d67e4ae2a57b94cb3244441fa961a8..21fe3e01fdc99826e7c9d2add1fb4e64a3968939 100644 (file)
@@ -93,6 +93,9 @@
 #include "common/safe_io.h"
 #include "common/HeartbeatMap.h"
 
+#include "global/signal_handler.h"
+#include "global/pidfile.h"
+
 #include "include/color.h"
 #include "perfglue/cpu_profiler.h"
 #include "perfglue/heap_profiler.h"
@@ -600,10 +603,8 @@ void cls_initialize(ClassHandler *ch);
 void OSD::handle_signal(int signum)
 {
   assert(signum == SIGINT || signum == SIGTERM);
-  derr << "*** got signal " << sys_siglist[signum] << " ***" << dendl;
-
-  // FIXME!
-  exit(1);
+  derr << "*** Got signal " << sys_siglist[signum] << " ***" << dendl;
+  suicide(128 + signum);
 }
 
 int OSD::pre_init()
@@ -809,6 +810,24 @@ void OSD::create_logger()
   g_ceph_context->get_perfcounters_collection()->add(logger);
 }
 
+void OSD::suicide(int exitcode)
+{
+  derr << " pausing thread pools" << dendl;
+  op_tp.pause();
+  disk_tp.pause();
+  recovery_tp.pause();
+  command_tp.pause();
+
+  derr << " flushing io" << dendl;
+  store->sync_and_flush();
+
+  derr << " removing pid file" << dendl;
+  pidfile_remove();
+
+  derr << " exit" << dendl;
+  exit(exitcode);
+}
+
 int OSD::shutdown()
 {
   g_ceph_context->_conf->set_val("debug_osd", "100");
@@ -817,7 +836,7 @@ int OSD::shutdown()
   g_ceph_context->_conf->set_val("debug_ms", "100");
   g_ceph_context->_conf->apply_changes(NULL);
   
-  derr << "OSD::shutdown" << dendl;
+  derr << "shutdown" << dendl;
 
   state = STATE_STOPPING;
 
@@ -925,6 +944,7 @@ int OSD::shutdown()
   delete watch;
 
   clear_map_cache();
+
   return r;
 }
 
index 08e6ebefab9d438f9d4fc6299818362d58e6c4a7..db57a9486a95b59fc29b088032cfee4d3677e0ee 100644 (file)
@@ -1051,6 +1051,8 @@ public:
   // startup/shutdown
   int pre_init();
   int init();
+
+  void suicide(int exitcode);
   int shutdown();
 
   void handle_signal(int signum);