diff --git a/src/ceph_osd.cc b/src/ceph_osd.cc index 110234a46dd..25bf0b68aa1 100644 --- a/src/ceph_osd.cc +++ b/src/ceph_osd.cc @@ -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) { diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index bb3e4c2851b..8a7c3a7d7e3 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -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() { diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 356aeab3f95..08e6ebefab9 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -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);