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.
This commit is contained in:
Markus Makela
2016-12-03 16:54:44 +02:00
parent a64825c866
commit 6d7e419ed4
4 changed files with 36 additions and 20 deletions

View File

@ -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 */

View File

@ -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;

View File

@ -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,6 +1913,8 @@ int main(int argc, char **argv)
}
libmysql_initialized = TRUE;
if (!config_check)
{
/** Check if a MaxScale process is already running */
if (pid_file_exists())
{
@ -1934,6 +1931,7 @@ int main(int argc, char **argv)
rc = MAXSCALE_ALREADYRUNNING;
goto return_main;
}
}
/** Initialize statistics */
ts_stats_init();
@ -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.
*/

View File

@ -477,10 +477,18 @@ int serviceInitialize(SERVICE *service)
char **router_options = copy_string_array(service->routerOptions);
if ((service->router_instance = service->router->createInstance(service, router_options)))
{
if (!config_get_global_options()->config_check)
{
listeners = serviceStartAllPorts(service);
}
else
{
/** We're only checking that the configuration is valid */
listeners++;
}
}
else
{
MXS_ERROR("%s: Failed to create router instance. Service not started.", service->name);
service->state = SERVICE_STATE_FAILED;