Add configuration exporting

The runtime configuration of a MaxScale can now be exported to a single
file. This allows modifications made via runtime configuration commands to
be "committed" for later use.
This commit is contained in:
Markus Mäkelä
2018-07-06 10:50:55 +03:00
parent 4a215b9ca2
commit 2df5763b6c
3 changed files with 145 additions and 24 deletions

View File

@ -109,6 +109,7 @@ const char *progname = NULL;
static struct option long_options[] =
{
{"config-check", no_argument, 0, 'c'},
{"export-config", required_argument, 0, 'e'},
{"daemon", no_argument, 0, 'n'},
{"nodaemon", no_argument, 0, 'd'},
{"config", required_argument, 0, 'f'},
@ -1060,6 +1061,7 @@ static void usage(void)
fprintf(stderr,
"\nUsage : %s [OPTION]...\n\n"
" -c, --config-check validate configuration file and exit\n"
" -e, --export-config=FILE export configuration to a single file\n"
" -d, --nodaemon enable running in terminal process\n"
" -f, --config=FILE relative or absolute pathname of config file\n"
" -l, --log=[file|shm|stdout] log to file, shared memory or stdout\n"
@ -1439,7 +1441,9 @@ int main(int argc, char **argv)
bool pid_file_created = false;
Worker* worker;
const char* specified_user = NULL;
char export_cnf[PATH_MAX + 1] = "";
config_init();
config_set_global_defaults();
ss_dassert(cnf);
@ -1453,7 +1457,7 @@ int main(int argc, char **argv)
file_write_header(stderr);
// Option string for getopt
const char accepted_opts[] = "dncf:g:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:M:H:p";
const char accepted_opts[] = "dnce:f:g:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:M:H:p";
/*<
* Register functions which are called at exit.
@ -1747,6 +1751,11 @@ int main(int argc, char **argv)
cnf->config_check = true;
break;
case 'e':
cnf->config_check = true;
strcpy(export_cnf, optarg);
break;
case 'p':
cnf->passive = true;
break;
@ -2164,6 +2173,12 @@ int main(int argc, char **argv)
if (cnf->config_check)
{
MXS_NOTICE("Configuration was successfully verified.");
if (*export_cnf && export_config_file(export_cnf))
{
MXS_NOTICE("Configuration exported to '%s'", export_cnf);
}
rc = MAXSCALE_SHUTDOWN;
goto return_main;
}
@ -2345,6 +2360,8 @@ return_main:
MXS_FREE(cnf_file_path);
}
config_finish();
return rc;
} /*< End of main */