osd: install async signal handlers for SIG{HUP,INT,TERM}

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
This commit is contained in:
Sage Weil 2012-02-11 16:36:33 -08:00
parent be704fe1d9
commit e905564bb2
3 changed files with 31 additions and 5 deletions

View 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) {

View 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()
{

View 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);