MXS-1914: Move maxscale_shutdown() into the core
The core library now contains the maxscale_shutdown() command. This makes it possible to resolve all symbols at link time even for administrative modules.
This commit is contained in:
@ -96,6 +96,18 @@ typedef struct mxs_log_throttling
|
|||||||
bool mxs_log_init(const char* ident, const char* logdir, mxs_log_target_t target);
|
bool mxs_log_init(const char* ident, const char* logdir, mxs_log_target_t target);
|
||||||
void mxs_log_finish(void);
|
void mxs_log_finish(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start log flushing thread
|
||||||
|
*
|
||||||
|
* @return True if log flusher thread was started
|
||||||
|
*/
|
||||||
|
bool mxs_log_start_flush_thr();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop log flushing thread
|
||||||
|
*/
|
||||||
|
void mxs_log_stop_flush_thr();
|
||||||
|
|
||||||
int mxs_log_flush();
|
int mxs_log_flush();
|
||||||
int mxs_log_flush_sync();
|
int mxs_log_flush_sync();
|
||||||
int mxs_log_rotate();
|
int mxs_log_rotate();
|
||||||
|
@ -90,11 +90,6 @@ static bool datadir_defined = false; /*< If the datadir was already set */
|
|||||||
static char pidfile[PATH_MAX + 1] = "";
|
static char pidfile[PATH_MAX + 1] = "";
|
||||||
static int pidfd = PIDFD_CLOSED;
|
static int pidfd = PIDFD_CLOSED;
|
||||||
|
|
||||||
/**
|
|
||||||
* exit flag for log flusher.
|
|
||||||
*/
|
|
||||||
static bool do_exit = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If MaxScale is started to run in daemon process the value is true.
|
* If MaxScale is started to run in daemon process the value is true.
|
||||||
*/
|
*/
|
||||||
@ -146,8 +141,6 @@ static bool unload_modules_at_exit = true;
|
|||||||
static std::string redirect_output_to;
|
static std::string redirect_output_to;
|
||||||
|
|
||||||
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 void log_flush_shutdown(void);
|
|
||||||
static void log_flush_cb(void* arg);
|
|
||||||
static int write_pid_file(); /* write MaxScale pidfile */
|
static int write_pid_file(); /* write MaxScale pidfile */
|
||||||
static void unlink_pidfile(void); /* remove pidfile */
|
static void unlink_pidfile(void); /* remove pidfile */
|
||||||
static void unlock_pidfile();
|
static void unlock_pidfile();
|
||||||
@ -1420,7 +1413,6 @@ int main(int argc, char **argv)
|
|||||||
int child_status;
|
int child_status;
|
||||||
char* cnf_file_path = NULL; /*< conf file, to be freed */
|
char* cnf_file_path = NULL; /*< conf file, to be freed */
|
||||||
char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */
|
char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */
|
||||||
THREAD log_flush_thr;
|
|
||||||
char* tmp_path;
|
char* tmp_path;
|
||||||
int option_index;
|
int option_index;
|
||||||
MXS_CONFIG* cnf = config_get_global_options();
|
MXS_CONFIG* cnf = config_get_global_options();
|
||||||
@ -1428,7 +1420,6 @@ int main(int argc, char **argv)
|
|||||||
int *syslog_enabled = &cnf->syslog; /** Log to syslog */
|
int *syslog_enabled = &cnf->syslog; /** Log to syslog */
|
||||||
int *maxlog_enabled = &cnf->maxlog; /** Log with MaxScale */
|
int *maxlog_enabled = &cnf->maxlog; /** Log with MaxScale */
|
||||||
int *log_to_shm = &cnf->log_to_shm; /** Log to shared memory */
|
int *log_to_shm = &cnf->log_to_shm; /** Log to shared memory */
|
||||||
ssize_t log_flush_timeout_ms = 0;
|
|
||||||
sigset_t sigpipe_mask;
|
sigset_t sigpipe_mask;
|
||||||
sigset_t saved_mask;
|
sigset_t saved_mask;
|
||||||
bool to_stdout = false;
|
bool to_stdout = false;
|
||||||
@ -2185,12 +2176,7 @@ int main(int argc, char **argv)
|
|||||||
goto return_main;
|
goto return_main;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*<
|
if (!mxs_log_start_flush_thr())
|
||||||
* Start periodic log flusher thread.
|
|
||||||
*/
|
|
||||||
log_flush_timeout_ms = 1000;
|
|
||||||
|
|
||||||
if (thread_start(&log_flush_thr, log_flush_cb, (void *) &log_flush_timeout_ms, 0) == NULL)
|
|
||||||
{
|
{
|
||||||
const char* logerr = "Failed to start log flushing thread.";
|
const char* logerr = "Failed to start log flushing thread.";
|
||||||
print_log_n_stderr(true, true, logerr, logerr, 0);
|
print_log_n_stderr(true, true, logerr, logerr, 0);
|
||||||
@ -2283,10 +2269,7 @@ int main(int argc, char **argv)
|
|||||||
Worker::finish();
|
Worker::finish();
|
||||||
MessageQueue::finish();
|
MessageQueue::finish();
|
||||||
|
|
||||||
/*<
|
mxs_log_stop_flush_thr();
|
||||||
* Wait the flush thread.
|
|
||||||
*/
|
|
||||||
thread_wait(log_flush_thr);
|
|
||||||
|
|
||||||
/*< Call finish on all modules. */
|
/*< Call finish on all modules. */
|
||||||
modules_process_finish();
|
modules_process_finish();
|
||||||
@ -2336,57 +2319,6 @@ return_main:
|
|||||||
return rc;
|
return rc;
|
||||||
} /*< End of main */
|
} /*< End of main */
|
||||||
|
|
||||||
/*<
|
|
||||||
* Shutdown MaxScale server
|
|
||||||
*/
|
|
||||||
int maxscale_shutdown()
|
|
||||||
{
|
|
||||||
static int n_shutdowns = 0;
|
|
||||||
|
|
||||||
int n = atomic_add(&n_shutdowns, 1);
|
|
||||||
|
|
||||||
if (n == 0)
|
|
||||||
{
|
|
||||||
service_shutdown();
|
|
||||||
Worker::shutdown_all();
|
|
||||||
log_flush_shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
return n + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void log_flush_shutdown(void)
|
|
||||||
{
|
|
||||||
do_exit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Periodic log flusher to ensure that log buffers are
|
|
||||||
* written to log even if block buffer used for temporarily
|
|
||||||
* storing log contents are not full.
|
|
||||||
*
|
|
||||||
* @param arg - Flush frequency in milliseconds
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static void log_flush_cb(void* arg)
|
|
||||||
{
|
|
||||||
ssize_t timeout_ms = *(ssize_t *)arg;
|
|
||||||
struct timespec ts1;
|
|
||||||
|
|
||||||
ts1.tv_sec = timeout_ms / 1000;
|
|
||||||
ts1.tv_nsec = (timeout_ms % 1000) * 1000000;
|
|
||||||
|
|
||||||
MXS_NOTICE("Started MaxScale log flusher.");
|
|
||||||
while (!do_exit)
|
|
||||||
{
|
|
||||||
mxs_log_flush();
|
|
||||||
nanosleep(&ts1, NULL);
|
|
||||||
}
|
|
||||||
MXS_NOTICE("Finished MaxScale log flusher.");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void unlock_pidfile()
|
static void unlock_pidfile()
|
||||||
{
|
{
|
||||||
if (pidfd != PIDFD_CLOSED)
|
if (pidfd != PIDFD_CLOSED)
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include <maxscale/alloc.h>
|
#include <maxscale/alloc.h>
|
||||||
#include <maxscale/atomic.h>
|
#include <maxscale/atomic.h>
|
||||||
@ -34,6 +35,7 @@
|
|||||||
#include <maxscale/platform.h>
|
#include <maxscale/platform.h>
|
||||||
#include <maxscale/session.h>
|
#include <maxscale/session.h>
|
||||||
#include <maxscale/spinlock.hh>
|
#include <maxscale/spinlock.hh>
|
||||||
|
#include <maxscale/thread.h>
|
||||||
#include <maxscale/utils.h>
|
#include <maxscale/utils.h>
|
||||||
#include "internal/mlist.h"
|
#include "internal/mlist.h"
|
||||||
|
|
||||||
@ -821,6 +823,32 @@ void mxs_log_finish(void)
|
|||||||
spinlock_release(&lmlock);
|
spinlock_release(&lmlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct
|
||||||
|
{
|
||||||
|
THREAD thr;
|
||||||
|
std::atomic<bool> running{true};
|
||||||
|
} log_flusher;
|
||||||
|
|
||||||
|
static void log_flush_cb(void* arg)
|
||||||
|
{
|
||||||
|
while (log_flusher.running)
|
||||||
|
{
|
||||||
|
mxs_log_flush();
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mxs_log_start_flush_thr()
|
||||||
|
{
|
||||||
|
return thread_start(&log_flusher.thr, log_flush_cb, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mxs_log_stop_flush_thr()
|
||||||
|
{
|
||||||
|
log_flusher.running = false;
|
||||||
|
thread_wait(log_flusher.thr);
|
||||||
|
}
|
||||||
|
|
||||||
static logfile_t* logmanager_get_logfile(logmanager_t* lmgr)
|
static logfile_t* logmanager_get_logfile(logmanager_t* lmgr)
|
||||||
{
|
{
|
||||||
logfile_t* lf;
|
logfile_t* lf;
|
||||||
|
@ -14,7 +14,11 @@
|
|||||||
#include <maxscale/maxscale.h>
|
#include <maxscale/maxscale.h>
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <maxscale/worker.hh>
|
||||||
|
|
||||||
#include "internal/maxscale.h"
|
#include "internal/maxscale.h"
|
||||||
|
#include "internal/service.h"
|
||||||
|
|
||||||
static time_t started;
|
static time_t started;
|
||||||
|
|
||||||
@ -32,3 +36,18 @@ int maxscale_uptime()
|
|||||||
{
|
{
|
||||||
return time(0) - started;
|
return time(0) - started;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int maxscale_shutdown()
|
||||||
|
{
|
||||||
|
static int n_shutdowns = 0;
|
||||||
|
|
||||||
|
int n = atomic_add(&n_shutdowns, 1);
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
service_shutdown();
|
||||||
|
mxs::Worker::shutdown_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
return n + 1;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user