MXS-2218 Centralize worker shutdown handling
This commit is contained in:
@ -36,7 +36,16 @@ public:
|
|||||||
~MainWorker();
|
~MainWorker();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the main worker.
|
* Does the main worker exist. It is only at startup and shutdown that this
|
||||||
|
* function may return false. When MaxScale is running normally, it will
|
||||||
|
* always return true.
|
||||||
|
*
|
||||||
|
* @return True, if the main worker has been created, false otherwise.
|
||||||
|
*/
|
||||||
|
static bool created();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the main worker.
|
||||||
*
|
*
|
||||||
* @return The main worker.
|
* @return The main worker.
|
||||||
*/
|
*/
|
||||||
|
@ -151,7 +151,6 @@ static bool log_to_shm_configured = false;
|
|||||||
static volatile sig_atomic_t last_signal = 0;
|
static volatile sig_atomic_t last_signal = 0;
|
||||||
static bool unload_modules_at_exit = true;
|
static bool unload_modules_at_exit = true;
|
||||||
static std::string redirect_output_to;
|
static std::string redirect_output_to;
|
||||||
static maxscale::MainWorker* main_worker = nullptr;
|
|
||||||
|
|
||||||
static int cnf_preparser(void* data, const char* section, const char* name, const char* value);
|
static int cnf_preparser(void* data, const char* section, const char* name, const char* value);
|
||||||
static int write_pid_file(); /* write MaxScale pidfile */
|
static int write_pid_file(); /* write MaxScale pidfile */
|
||||||
@ -353,11 +352,6 @@ static void sigterm_handler(int i)
|
|||||||
|
|
||||||
if (n_shutdowns == 1)
|
if (n_shutdowns == 1)
|
||||||
{
|
{
|
||||||
if (main_worker)
|
|
||||||
{
|
|
||||||
main_worker->shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!daemon_mode)
|
if (!daemon_mode)
|
||||||
{
|
{
|
||||||
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
|
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
|
||||||
@ -379,11 +373,6 @@ static void sigint_handler(int i)
|
|||||||
|
|
||||||
if (n_shutdowns == 1)
|
if (n_shutdowns == 1)
|
||||||
{
|
{
|
||||||
if (main_worker)
|
|
||||||
{
|
|
||||||
main_worker->shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!daemon_mode)
|
if (!daemon_mode)
|
||||||
{
|
{
|
||||||
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
|
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
|
||||||
@ -1422,6 +1411,7 @@ int main(int argc, char** argv)
|
|||||||
mxb::Worker* worker;
|
mxb::Worker* worker;
|
||||||
const char* specified_user = NULL;
|
const char* specified_user = NULL;
|
||||||
char export_cnf[PATH_MAX + 1] = "";
|
char export_cnf[PATH_MAX + 1] = "";
|
||||||
|
maxscale::MainWorker* main_worker = nullptr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The following lambda function is executed as the first event on the main worker. This is what starts
|
* The following lambda function is executed as the first event on the main worker. This is what starts
|
||||||
@ -1441,9 +1431,7 @@ int main(int argc, char** argv)
|
|||||||
const char* logerr = "Failed to start all MaxScale services. Exiting.";
|
const char* logerr = "Failed to start all MaxScale services. Exiting.";
|
||||||
print_log_n_stderr(true, true, logerr, logerr, 0);
|
print_log_n_stderr(true, true, logerr, logerr, 0);
|
||||||
rc = MAXSCALE_NOSERVICES;
|
rc = MAXSCALE_NOSERVICES;
|
||||||
RoutingWorker::shutdown_all();
|
maxscale_shutdown();
|
||||||
mxb_assert(main_worker);
|
|
||||||
main_worker->shutdown();
|
|
||||||
}
|
}
|
||||||
else if (daemon_mode)
|
else if (daemon_mode)
|
||||||
{
|
{
|
||||||
|
@ -45,6 +45,12 @@ MainWorker::~MainWorker()
|
|||||||
this_unit.pCurrent_main = nullptr;
|
this_unit.pCurrent_main = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//static
|
||||||
|
bool MainWorker::created()
|
||||||
|
{
|
||||||
|
return this_unit.pCurrent_main ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
//static
|
//static
|
||||||
MainWorker& MainWorker::get()
|
MainWorker& MainWorker::get()
|
||||||
{
|
{
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <maxscale/mainworker.hh>
|
||||||
#include <maxscale/routingworker.hh>
|
#include <maxscale/routingworker.hh>
|
||||||
|
|
||||||
#include "internal/maxscale.hh"
|
#include "internal/maxscale.hh"
|
||||||
@ -50,6 +51,11 @@ int maxscale_shutdown()
|
|||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
{
|
{
|
||||||
|
if (mxs::MainWorker::created())
|
||||||
|
{
|
||||||
|
mxs::MainWorker::get().shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
mxs::RoutingWorker::shutdown_all();
|
mxs::RoutingWorker::shutdown_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user