Commit accaeb74 authored by osdaniellee's avatar osdaniellee

Add -graceful_quit_on_sigterm for SIGTERM handler

parent 30b1d7f2
...@@ -77,6 +77,8 @@ BAIDU_REGISTER_ERRNO(brpc::EITP, "Bad Itp response"); ...@@ -77,6 +77,8 @@ BAIDU_REGISTER_ERRNO(brpc::EITP, "Bad Itp response");
namespace brpc { namespace brpc {
DEFINE_bool(graceful_quit_on_sigterm, false, "Register SIGTERM handle func to quit graceful");
const IdlNames idl_single_req_single_res = { "req", "res" }; const IdlNames idl_single_req_single_res = { "req", "res" };
const IdlNames idl_single_req_multi_res = { "req", "" }; const IdlNames idl_single_req_multi_res = { "req", "" };
const IdlNames idl_multi_req_single_res = { "", "res" }; const IdlNames idl_multi_req_single_res = { "", "res" };
...@@ -1403,15 +1405,17 @@ static void RegisterQuitSignalOrDie() { ...@@ -1403,15 +1405,17 @@ static void RegisterQuitSignalOrDie() {
} }
} }
prev = signal(SIGTERM, quit_handler); if (FLAGS_graceful_quit_on_sigterm) {
if (prev != SIG_DFL && prev = signal(SIGTERM, quit_handler);
prev != SIG_IGN) { // shell may install SIGTERM of background jobs with SIG_IGN if (prev != SIG_DFL &&
if (prev == SIG_ERR) { prev != SIG_IGN) { // shell may install SIGTERM of background jobs with SIG_IGN
LOG(ERROR) << "Fail to register SIGTERM, abort"; if (prev == SIG_ERR) {
abort(); LOG(ERROR) << "Fail to register SIGTERM, abort";
} else { abort();
s_prev_sigterm_handler = prev; } else {
LOG(WARNING) << "SIGTERM was installed with " << prev; s_prev_sigterm_handler = prev;
LOG(WARNING) << "SIGTERM was installed with " << prev;
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment