]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: install async signal handlers for SIG{HUP,INT,TERM}
authorSage Weil <sage.weil@dreamhost.com>
Sun, 12 Feb 2012 00:36:33 +0000 (16:36 -0800)
committerSage Weil <sage.weil@dreamhost.com>
Wed, 15 Feb 2012 05:03:53 +0000 (21:03 -0800)
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/ceph_osd.cc
src/osd/OSD.cc
src/osd/OSD.h

index 110234a46dd20321ad33294cc824ac5702dd874f..25bf0b68aa15cea2e57ff427a6cf15b217c6e27e 100644 (file)
@@ -34,15 +34,25 @@ using namespace std;
 #include "msg/SimpleMessenger.h"
 
 #include "common/Timer.h"
-#include "global/global_init.h"
 #include "common/ceph_argparse.h"
 
+#include "global/global_init.h"
+#include "global/signal_handler.h"
+
 #include "include/color.h"
 #include "common/errno.h"
 #include "common/pick_address.h"
 
 #include "perfglue/heap_profiler.h"
 
+OSD *osd = NULL;
+
+void handle_osd_signal(int signum)
+{
+  if (osd)
+    osd->handle_signal(signum);
+}
+
 void usage() 
 {
   derr << "usage: ceph-osd -i osdid [--osd-data=path] [--osd-journal=path] "
@@ -374,10 +384,10 @@ int main(int argc, const char **argv)
     return -1;
   global_init_chdir(g_ceph_context);
 
-  OSD *osd = new OSD(whoami, cluster_messenger, client_messenger,
-                    messenger_hbin, messenger_hbout,
-                    &mc,
-                    g_conf->osd_data, g_conf->osd_journal);
+  osd = new OSD(whoami, cluster_messenger, client_messenger,
+               messenger_hbin, messenger_hbout,
+               &mc,
+               g_conf->osd_data, g_conf->osd_journal);
   err = osd->pre_init();
   if (err < 0) {
     derr << TEXT_RED << " ** ERROR: initializing osd failed: " << cpp_strerror(-err)
@@ -393,6 +403,12 @@ int main(int argc, const char **argv)
   messenger_hbout->start();
   cluster_messenger->start();
 
+  // install signal handlers
+  init_async_signal_handler();
+  register_async_signal_handler(SIGHUP, sighup_handler);
+  register_async_signal_handler_oneshot(SIGINT, handle_osd_signal);
+  register_async_signal_handler_oneshot(SIGTERM, handle_osd_signal);
+
   // start osd
   err = osd->init();
   if (err < 0) {
index bb3e4c2851bb09af7d3925ed13c4602303702935..8a7c3a7d7e3a75bfd0d7796dc2014a33445f5e14 100644 (file)
@@ -597,6 +597,14 @@ OSD::~OSD()
 
 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(0);
+}
 
 int OSD::pre_init()
 {
index 356aeab3f95fcdedf3b3fb7c6beee5c6fdfa8627..08e6ebefab9d438f9d4fc6299818362d58e6c4a7 100644 (file)
@@ -1053,6 +1053,8 @@ public:
   int init();
   int shutdown();
 
+  void handle_signal(int signum);
+
   void reply_op_error(OpRequest *op, int r);
   void reply_op_error(OpRequest *op, int r, eversion_t v);
   void handle_misdirected_op(PG *pg, OpRequest *op);