diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index 6734790cc..da292da02 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -388,6 +388,16 @@ or modify the contents of this directory, use _/etc/maxscale.cnf.d/_ instead. persistdir=/var/lib/maxscale/maxscale.cnf.d/ ``` +#### `module_configdir` + +Configure the directory where module configurations are stored. Path arguments +are resolved relative to this directory. This directory should be used to store +module specific configurations e.g. dbfwfilter rule files. + +``` +module_configdir=/var/lib/maxscale/ +``` + #### `language` Set the folder where the errmsg.sys file is located in. MariaDB MaxScale will look for the errmsg.sys file installed with MariaDB MaxScale from this folder. diff --git a/include/maxscale/gwdirs.h.in b/include/maxscale/gwdirs.h.in index 6f9cb1046..3c9a0f452 100644 --- a/include/maxscale/gwdirs.h.in +++ b/include/maxscale/gwdirs.h.in @@ -30,6 +30,7 @@ MXS_BEGIN_DECLS #define MXS_DEFAULT_EXEC_SUBPATH "@DEFAULT_EXEC_SUBPATH@" #define MXS_DEFAULT_CONFIG_SUBPATH "@DEFAULT_CONFIG_SUBPATH@" #define MXS_DEFAULT_CONFIG_PERSIST_SUBPATH "@DEFAULT_CONFIG_PERSIST_SUBPATH@" +#define MXS_DEFAULT_MODULE_CONFIG_SUBPATH "@DEFAULT_MODULE_CONFIG_SUBPATH@" /** Default file locations, configured by CMake */ #define MXS_DEFAULT_CONFIGDIR "@DEFAULT_CONFIGDIR@" @@ -41,6 +42,7 @@ MXS_BEGIN_DECLS #define MXS_DEFAULT_LANGDIR "@DEFAULT_LANGDIR@" #define MXS_DEFAULT_EXECDIR "@DEFAULT_EXECDIR@" #define MXS_DEFAULT_CONFIG_PERSISTDIR "@DEFAULT_CONFIG_PERSISTDIR@" +#define MXS_DEFAULT_MODULE_CONFIGDIR "@DEFAULT_MODULE_CONFIGDIR@" static const char* default_cnf_fname = "maxscale.cnf"; static const char* default_configdir = MXS_DEFAULT_CONFIGDIR; @@ -56,9 +58,11 @@ static const char* default_cachedir = MXS_DEFAULT_CACHEDIR; static const char* default_langdir = MXS_DEFAULT_LANGDIR; static const char* default_execdir = MXS_DEFAULT_EXECDIR; static const char* default_config_persistdir = MXS_DEFAULT_CONFIG_PERSISTDIR; +static const char* default_module_configdir = MXS_DEFAULT_MODULE_CONFIGDIR; static char* configdir = NULL; /*< Where the config file is found e.g. /etc/ */ -static char* config_persistdir = NULL;/*< Persisted configs e.g. /var/lib/maxscale.cnf.d/ */ +static char* config_persistdir = NULL;/*< Persisted configs e.g. /var/lib/maxscale/maxscale.cnf.d/ */ +static char* module_configdir = NULL;/*< Module specific configs e.g. /var/lib/maxscale/ */ static char* logdir = NULL; static char* libdir = NULL; static char* cachedir = NULL; @@ -74,6 +78,7 @@ void set_process_datadir(char* param); void set_cachedir(char* param); void set_configdir(char* param); void set_config_persistdir(char* param); +void set_module_configdir(char* param); void set_logdir(char* param); void set_langdir(char* param); void set_piddir(char* param); @@ -84,6 +89,7 @@ char* get_process_datadir(); char* get_cachedir(); char* get_configdir(); char* get_config_persistdir(); +char* get_module_configdir(); char* get_piddir(); char* get_logdir(); char* get_langdir(); diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 01480e258..753181f74 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -123,6 +123,7 @@ static struct option long_options[] = {"datadir", required_argument, 0, 'D'}, {"execdir", required_argument, 0, 'E'}, {"persistdir", required_argument, 0, 'F'}, + {"module_configdir", required_argument, 0, 'M'}, {"language", required_argument, 0, 'N'}, {"piddir", required_argument, 0, 'P'}, {"basedir", required_argument, 0, 'R'}, @@ -912,6 +913,7 @@ static void usage(void) " stores internal MaxScale data\n" " -E, --execdir=PATH path to the maxscale and other executable files\n" " -F, --persistdir=PATH path to persisted configuration directory\n" + " -M, --module_configdir=PATH path to module configuration directory\n" " -N, --language=PATH path to errmsg.sys file\n" " -P, --piddir=PATH path to PID file directory\n" " -R, --basedir=PATH base path for all other paths\n" @@ -926,16 +928,17 @@ static void usage(void) " -?, --help show this help\n" "\n" "Defaults paths:\n" - " config file: %s/%s\n" - " configdir : %s\n" - " logdir : %s\n" - " cachedir : %s\n" - " libdir : %s\n" - " datadir : %s\n" - " execdir : %s\n" - " language : %s\n" - " piddir : %s\n" - " persistdir : %s\n" + " config file : %s/%s\n" + " configdir : %s\n" + " logdir : %s\n" + " cachedir : %s\n" + " libdir : %s\n" + " datadir : %s\n" + " execdir : %s\n" + " language : %s\n" + " piddir : %s\n" + " persistdir : %s\n" + " module configdir : %s\n" "\n" "If '--basedir' is provided then all other paths, including the default\n" "configuration file path, are defined relative to that. As an example,\n" @@ -947,7 +950,7 @@ static void usage(void) get_configdir(), default_cnf_fname, get_configdir(), get_logdir(), get_cachedir(), get_libdir(), get_datadir(), get_execdir(), get_langdir(), get_piddir(), - get_config_persistdir()); + get_config_persistdir(), get_module_configdir()); } @@ -1196,6 +1199,11 @@ bool set_dirs(const char *basedir) set_configdir(path); } + if (rv && (rv = handle_path_arg(&path, basedir, MXS_DEFAULT_MODULE_CONFIG_SUBPATH, true, false))) + { + set_module_configdir(path); + } + if (rv && (rv = handle_path_arg(&path, basedir, "var/" MXS_DEFAULT_DATA_SUBPATH, true, false))) { set_datadir(path); @@ -1311,7 +1319,7 @@ int main(int argc, char **argv) } } - while ((opt = getopt_long(argc, argv, "dcf:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:", + while ((opt = getopt_long(argc, argv, "dcf:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:M:", long_options, &option_index)) != -1) { bool succp = true; @@ -1473,6 +1481,18 @@ int main(int argc, char **argv) succp = false; } break; + + case 'M': + if (handle_path_arg(&tmp_path, optarg, NULL, true, true)) + { + set_module_configdir(tmp_path); + } + else + { + succp = false; + } + break; + case 'R': if (handle_path_arg(&tmp_path, optarg, NULL, true, false)) { @@ -2485,6 +2505,20 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons } } } + else if (strcmp(name, "module_configdir") == 0) + { + if (strcmp(get_module_configdir(), default_module_configdir) == 0) + { + if (handle_path_arg((char**)&tmp, (char*)value, NULL, true, false)) + { + set_module_configdir(tmp); + } + else + { + return 0; + } + } + } else if (strcmp(name, "syslog") == 0) { if (!syslog_configured) diff --git a/server/core/gwdirs.c b/server/core/gwdirs.c index 22de96bc6..8a0576baf 100644 --- a/server/core/gwdirs.c +++ b/server/core/gwdirs.c @@ -26,6 +26,17 @@ void set_configdir(char* str) configdir = str; } +/** + * Set the module configuration file directory + * @param str Path to directory + */ +void set_module_configdir(char* str) +{ + MXS_FREE(module_configdir); + clean_up_pathname(str); + module_configdir = str; +} + /** * Set the configuration parts file directory * @param str Path to directory @@ -171,6 +182,15 @@ char* get_configdir() return configdir ? configdir : (char*) default_configdir; } +/** + * Get the module configuration file directory + * @return The path to the module configuration file directory + */ +char* get_module_configdir() +{ + return module_configdir ? module_configdir : (char*) default_module_configdir; +} + /** * Get the configuration file directory * @return The path to the configuration file directory