feature(signal): Add option to disable signal handling (#742)
This commit is contained in:
parent
1901801d59
commit
bcd8e27a36
|
@ -172,6 +172,8 @@
|
|||
},
|
||||
//run_as_daemon: False by default
|
||||
"run_as_daemon": false,
|
||||
//handle_sig_term: True by default
|
||||
"handle_sig_term": true,
|
||||
//relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
|
||||
"relaunch_on_error": false,
|
||||
//use_sendfile: True by default, if true, the program
|
||||
|
|
|
@ -172,6 +172,8 @@
|
|||
},
|
||||
//run_as_daemon: False by default
|
||||
"run_as_daemon": false,
|
||||
//handle_sig_term: True by default
|
||||
"handle_sig_term": true,
|
||||
//relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
|
||||
"relaunch_on_error": false,
|
||||
//use_sendfile: True by default, if true, the program
|
||||
|
|
|
@ -87,6 +87,8 @@
|
|||
},
|
||||
//run_as_daemon: False by default
|
||||
"run_as_daemon": false,
|
||||
//handle_sig_term: True by default
|
||||
"handle_sig_term": true,
|
||||
//relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
|
||||
"relaunch_on_error": false,
|
||||
//use_sendfile: True by default, if true, the program
|
||||
|
|
|
@ -816,6 +816,16 @@ class HttpAppFramework : public trantor::NonCopyable
|
|||
*/
|
||||
virtual HttpAppFramework &enableRunAsDaemon() = 0;
|
||||
|
||||
/// Disable the handling of SIGTERM signal.
|
||||
/**
|
||||
* Enabled by default.
|
||||
*
|
||||
* @note
|
||||
* This operation can be performed by an option in the configuration file.
|
||||
* When disabled setTermSignalHandler() is useless
|
||||
*/
|
||||
virtual HttpAppFramework &disableSigtermHandling() = 0;
|
||||
|
||||
/// Make the application restart after crashing.
|
||||
/**
|
||||
* Disabled by default.
|
||||
|
|
|
@ -393,6 +393,12 @@ static void loadApp(const Json::Value &app)
|
|||
{
|
||||
drogon::app().enableRunAsDaemon();
|
||||
}
|
||||
// handle SIGTERM
|
||||
auto handleSigterm = app.get("handle_sig_term", true).asBool();
|
||||
if (!handleSigterm)
|
||||
{
|
||||
drogon::app().disableSigtermHandling();
|
||||
}
|
||||
// relaunch
|
||||
auto relaunch = app.get("relaunch_on_error", false).asBool();
|
||||
if (relaunch)
|
||||
|
|
|
@ -463,7 +463,10 @@ void HttpAppFrameworkImpl::run()
|
|||
getLoop()->resetAfterFork();
|
||||
#endif
|
||||
}
|
||||
signal(SIGTERM, TERMFunction);
|
||||
if (handleSigterm_)
|
||||
{
|
||||
signal(SIGTERM, TERMFunction);
|
||||
}
|
||||
// set logger
|
||||
if (!logPath_.empty())
|
||||
{
|
||||
|
|
|
@ -256,6 +256,11 @@ class HttpAppFrameworkImpl : public HttpAppFramework
|
|||
runAsDaemon_ = true;
|
||||
return *this;
|
||||
}
|
||||
virtual HttpAppFramework &disableSigtermHandling() override
|
||||
{
|
||||
handleSigterm_ = false;
|
||||
return *this;
|
||||
}
|
||||
virtual HttpAppFramework &enableRelaunchOnError() override
|
||||
{
|
||||
relaunchOnError_ = true;
|
||||
|
@ -583,6 +588,7 @@ class HttpAppFrameworkImpl : public HttpAppFramework
|
|||
std::atomic<int64_t> connectionNum_{0};
|
||||
|
||||
bool runAsDaemon_{false};
|
||||
bool handleSigterm_{true};
|
||||
bool relaunchOnError_{false};
|
||||
std::string logPath_{""};
|
||||
std::string logfileBaseName_{""};
|
||||
|
|
Loading…
Reference in New Issue