From 6d7e419ed40aa07f93ef0bef9f9e921d05ba1111 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sat, 3 Dec 2016 16:54:44 +0200 Subject: [PATCH] Improve `--config-check` mode The configuration checking now detects bad router options. This allows for better coverage of the configuration with only the --config-check flag. --- include/maxscale/config.h | 1 + server/core/config.c | 1 + server/core/gateway.cc | 44 ++++++++++++++++++++++----------------- server/core/service.c | 10 ++++++++- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/include/maxscale/config.h b/include/maxscale/config.h index afb1a0029..da440953a 100644 --- a/include/maxscale/config.h +++ b/include/maxscale/config.h @@ -110,6 +110,7 @@ typedef struct config_context */ typedef struct { + bool config_check; /**< Only check config */ int n_threads; /**< Number of polling threads */ char *version_string; /**< The version string of embedded db library */ char release_string[_RELEASE_STR_LENGTH]; /**< The release name string of the system */ diff --git a/server/core/config.c b/server/core/config.c index 5ef1b9ca9..84434519b 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -1561,6 +1561,7 @@ global_defaults() { uint8_t mac_addr[6] = ""; struct utsname uname_data; + gateway.config_check = false; gateway.n_threads = DEFAULT_NTHREADS; gateway.n_nbpoll = DEFAULT_NBPOLLS; gateway.pollsleep = DEFAULT_POLLSLEEP; diff --git a/server/core/gateway.cc b/server/core/gateway.cc index f2808c328..1d9f34d44 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -1865,12 +1865,7 @@ int main(int argc, char **argv) goto return_main; } - if (config_check) - { - MXS_NOTICE("Configuration was successfully verified."); - rc = MAXSCALE_SHUTDOWN; - goto return_main; - } + cnf->config_check = config_check; if (mysql_library_init(0, NULL, NULL)) { @@ -1918,21 +1913,24 @@ int main(int argc, char **argv) } libmysql_initialized = TRUE; - /** Check if a MaxScale process is already running */ - if (pid_file_exists()) + if (!config_check) { - /** There is a process with the PID of the maxscale.pid file running. - * Assuming that this is an already running MaxScale process, we - * should exit with an error code. */ - rc = MAXSCALE_ALREADYRUNNING; - goto return_main; - } + /** Check if a MaxScale process is already running */ + if (pid_file_exists()) + { + /** There is a process with the PID of the maxscale.pid file running. + * Assuming that this is an already running MaxScale process, we + * should exit with an error code. */ + rc = MAXSCALE_ALREADYRUNNING; + goto return_main; + } - /* Write process pid into MaxScale pidfile */ - if (write_pid_file() != 0) - { - rc = MAXSCALE_ALREADYRUNNING; - goto return_main; + /* Write process pid into MaxScale pidfile */ + if (write_pid_file() != 0) + { + rc = MAXSCALE_ALREADYRUNNING; + goto return_main; + } } /** Initialize statistics */ @@ -1961,6 +1959,14 @@ int main(int argc, char **argv) rc = MAXSCALE_NOSERVICES; goto return_main; } + + if (config_check) + { + MXS_NOTICE("Configuration was successfully verified."); + rc = MAXSCALE_SHUTDOWN; + goto return_main; + } + /*< * Start periodic log flusher thread. */ diff --git a/server/core/service.c b/server/core/service.c index e34efc7c0..452b597ec 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -478,7 +478,15 @@ int serviceInitialize(SERVICE *service) if ((service->router_instance = service->router->createInstance(service, router_options))) { - listeners = serviceStartAllPorts(service); + if (!config_get_global_options()->config_check) + { + listeners = serviceStartAllPorts(service); + } + else + { + /** We're only checking that the configuration is valid */ + listeners++; + } } else {