Add --basedir flag
If maxscale is invoked with '--basedir=PATH', all directory paths and the configuration file to be defined relative to that path.
This commit is contained in:
parent
60c61157cc
commit
a87a9c75e5
@ -13,6 +13,28 @@ report at [Jira](https://jira.mariadb.org).
|
||||
|
||||
## Updated Features
|
||||
|
||||
### Starting MariaDB MaxScale
|
||||
|
||||
There is now a new command line parameter `--basedir=PATH` that will
|
||||
cause all directory paths and the location of the configuration file
|
||||
to be defined relative to that path.
|
||||
|
||||
For instance, invoking MariaDB MaxScale like
|
||||
|
||||
$ maxscale --basedir=/path/maxscale
|
||||
|
||||
has the same effect as invoking MariaDB MaxScale like
|
||||
|
||||
$ maxscale --config=/path/maxscale/etc/maxscale.cnf
|
||||
--configdir=/path/maxscale/etc
|
||||
--logdir=/path/maxscale/var/log/maxscale
|
||||
--cachhedir=/path/maxscale/var/cache/maxscale
|
||||
--libdir=/path/maxscale/lib/maxscale
|
||||
--datadir=/path/maxscale/var/lib/maxscale
|
||||
--execdir=/path/maxscale/bin
|
||||
--language=/path/maxscale/var/lib/maxscale
|
||||
--piddir=/path/maxscale/var/run/maxscale
|
||||
|
||||
### Password parameter
|
||||
|
||||
In the configuration entry for a _service_ or _monitor_, the value of
|
||||
|
@ -135,6 +135,7 @@ static struct option long_options[] =
|
||||
{"execdir", required_argument, 0, 'E'},
|
||||
{"language", required_argument, 0, 'N'},
|
||||
{"piddir", required_argument, 0, 'P'},
|
||||
{"basedir", required_argument, 0, 'R'},
|
||||
{"user", required_argument, 0, 'U'},
|
||||
{"syslog", required_argument, 0, 's'},
|
||||
{"maxlog", required_argument, 0, 'S'},
|
||||
@ -162,7 +163,7 @@ static void write_footer(void);
|
||||
static int ntfw_cb(const char*, const struct stat*, int, struct FTW*);
|
||||
static bool file_is_readable(const char* absolute_pathname);
|
||||
static bool file_is_writable(const char* absolute_pathname);
|
||||
bool handle_path_arg(char** dest, char* path, char* arg, bool rd, bool wr);
|
||||
bool handle_path_arg(char** dest, const char* path, char* arg, bool rd, bool wr);
|
||||
static void set_log_augmentation(const char* value);
|
||||
static void usage(void);
|
||||
static char* get_expanded_pathname(
|
||||
@ -875,42 +876,52 @@ static void usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"\nUsage : %s [OPTION]...\n\n"
|
||||
" -c, --config-check Validate configuration file and exit\n"
|
||||
" -d, --nodaemon enable running in terminal process (default:disabled)\n"
|
||||
" -f, --config=FILE relative or absolute pathname of MaxScale configuration file\n"
|
||||
" (default:/etc/maxscale.cnf)\n"
|
||||
" -l, --log=[file|shm|stdout] log to file, shared memory or stdout (default: file)\n"
|
||||
" -c, --config-check validate configuration file and exit\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"
|
||||
" (default: file)\n"
|
||||
" -L, --logdir=PATH path to log file directory\n"
|
||||
" -A, --cachedir=PATH path to cache directory\n"
|
||||
" -B, --libdir=PATH path to module directory\n"
|
||||
" -C, --configdir=PATH path to configuration file directory\n"
|
||||
" -D, --datadir=PATH path to data directory, stored embedded mysql tables\n"
|
||||
" -D, --datadir=PATH path to data directory,\n"
|
||||
" stored embedded mysql tables\n"
|
||||
" -E, --execdir=PATH path to the maxscale and other executable files\n"
|
||||
" -N, --language=PATH path to errmsg.sys file\n"
|
||||
" -P, --piddir=PATH path to PID file directory\n"
|
||||
" -U, --user=USER run MaxScale as another user.\n"
|
||||
" The user ID and group ID of this user are used to run MaxScale.\n"
|
||||
" -R, --basedir=PATH base path for all other paths\n"
|
||||
" -U, --user=USER user ID and group ID of specified user are used to\n"
|
||||
" run MaxScale\n"
|
||||
" -s, --syslog=[yes|no] log messages to syslog (default:yes)\n"
|
||||
" -S, --maxlog=[yes|no] log messages to MaxScale log (default: yes)\n"
|
||||
" -G, --log_augmentation=0|1 augment messages with the name of the function where\n"
|
||||
" the message was logged (default: 0). Primarily for \n"
|
||||
" development purposes.\n"
|
||||
" -G, --log_augmentation=0|1 augment messages with the name of the function\n"
|
||||
" where the message was logged (default: 0)\n"
|
||||
" -v, --version print version info and exit\n"
|
||||
" -V, --version-full print full version info and exit\n"
|
||||
" -?, --help show this help\n"
|
||||
"\n"
|
||||
"Defaults:\n"
|
||||
" logdir : %s\n"
|
||||
" cachedir : %s\n"
|
||||
" libdir : %s\n"
|
||||
" configdir: %s\n"
|
||||
" datadir : %s\n"
|
||||
" execdir : %s\n"
|
||||
" language : %s\n"
|
||||
" piddir : %s\n"
|
||||
, progname
|
||||
, get_logdir(), get_cachedir(), get_libdir(), get_configdir()
|
||||
, get_datadir(), get_execdir(), get_langdir(), get_piddir());
|
||||
"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"
|
||||
"\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"
|
||||
"if '--basedir /path/maxscale' is specified, then, for instance, the log\n"
|
||||
"dir will be '/path/maxscale/var/log/maxscale', the config dir will be\n"
|
||||
"'/path/maxscale/etc' and the default config file will be\n"
|
||||
"'/path/maxscale/etc/maxscale.cnf'.\n",
|
||||
progname,
|
||||
get_configdir(), default_cnf_fname,
|
||||
get_configdir(), get_logdir(), get_cachedir(), get_libdir(),
|
||||
get_datadir(), get_execdir(), get_langdir(), get_piddir());
|
||||
}
|
||||
|
||||
|
||||
@ -1133,6 +1144,61 @@ bool configure_signals(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directories of MaxScale relative to a basedir
|
||||
*
|
||||
* @param basedir The base directory relative to which the other are set.
|
||||
*
|
||||
* @return True if the directories could be set, false otherwise.
|
||||
*/
|
||||
bool set_dirs(const char *basedir)
|
||||
{
|
||||
bool rv = true;
|
||||
char *path;
|
||||
|
||||
if (rv && (rv = handle_path_arg(&path, basedir, "var/" MXS_DEFAULT_LOG_SUBPATH, true, false)))
|
||||
{
|
||||
set_logdir(path);
|
||||
}
|
||||
|
||||
if (rv && (rv = handle_path_arg(&path, basedir, "var/" MXS_DEFAULT_CACHE_SUBPATH, true, true)))
|
||||
{
|
||||
set_cachedir(path);
|
||||
}
|
||||
|
||||
if (rv && (rv = handle_path_arg(&path, basedir, MXS_DEFAULT_LIB_SUBPATH, true, false)))
|
||||
{
|
||||
set_libdir(path);
|
||||
}
|
||||
|
||||
if (rv && (rv = handle_path_arg(&path, basedir, MXS_DEFAULT_CONFIG_SUBPATH, true, false)))
|
||||
{
|
||||
set_configdir(path);
|
||||
}
|
||||
|
||||
if (rv && (rv = handle_path_arg(&path, basedir, "var/" MXS_DEFAULT_DATA_SUBPATH, true, false)))
|
||||
{
|
||||
set_datadir(path);
|
||||
}
|
||||
|
||||
if (rv && (rv = handle_path_arg(&path, basedir, MXS_DEFAULT_EXEC_SUBPATH, true, false)))
|
||||
{
|
||||
set_execdir(path);
|
||||
}
|
||||
|
||||
if (rv && (rv = handle_path_arg(&path, basedir, "var/" MXS_DEFAULT_LANG_SUBPATH, true, false)))
|
||||
{
|
||||
set_langdir(path);
|
||||
}
|
||||
|
||||
if (rv && (rv = handle_path_arg(&path, basedir, "var/" MXS_DEFAULT_PID_SUBPATH, true, true)))
|
||||
{
|
||||
set_piddir(path);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mainpage
|
||||
* The main entry point into MaxScale
|
||||
@ -1302,7 +1368,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
|
||||
if (handle_path_arg(&tmp_path, optarg, NULL, true, false))
|
||||
{
|
||||
set_logdir(tmp_path);
|
||||
@ -1379,6 +1444,17 @@ int main(int argc, char **argv)
|
||||
succp = false;
|
||||
}
|
||||
break;
|
||||
case 'R':
|
||||
if (handle_path_arg(&tmp_path, optarg, NULL, true, false))
|
||||
{
|
||||
succp = set_dirs(tmp_path);
|
||||
free(tmp_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
succp = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
{
|
||||
@ -2252,7 +2328,7 @@ static int write_pid_file()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool handle_path_arg(char** dest, char* path, char* arg, bool rd, bool wr)
|
||||
bool handle_path_arg(char** dest, const char* path, char* arg, bool rd, bool wr)
|
||||
{
|
||||
char pathbuffer[PATH_MAX + 2];
|
||||
char* errstr;
|
||||
|
@ -21,19 +21,28 @@
|
||||
|
||||
EXTERN_C_BLOCK_BEGIN
|
||||
|
||||
#define MXS_DEFAULT_PID_SUBPATH "run/maxscale"
|
||||
#define MXS_DEFAULT_LOG_SUBPATH "log/maxscale"
|
||||
#define MXS_DEFAULT_DATA_SUBPATH "lib/maxscale"
|
||||
#define MXS_DEFAULT_LIB_SUBPATH "@MAXSCALE_LIBDIR@"
|
||||
#define MXS_DEFAULT_CACHE_SUBPATH "cache/maxscale"
|
||||
#define MXS_DEFAULT_LANG_SUBPATH "lib/maxscale"
|
||||
#define MXS_DEFAULT_EXEC_SUBPATH "@MAXSCALE_BINDIR@"
|
||||
#define MXS_DEFAULT_CONFIG_SUBPATH "etc"
|
||||
|
||||
/** Default file locations, configured by CMake */
|
||||
static const char* default_cnf_fname = "maxscale.cnf";
|
||||
static const char* default_configdir = "/etc";
|
||||
static const char* default_configdir = "/" MXS_DEFAULT_CONFIG_SUBPATH;
|
||||
/*< This should be changed to just /run eventually,
|
||||
* the /var/run folder is an old standard and the newer FSH 3.0
|
||||
* uses /run for PID files.*/
|
||||
static const char* default_piddir = "@MAXSCALE_VARDIR@/run/maxscale";
|
||||
static const char* default_logdir = "@MAXSCALE_VARDIR@/log/maxscale";
|
||||
static const char* default_datadir = "@MAXSCALE_VARDIR@/lib/maxscale";
|
||||
static const char* default_libdir = "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@";
|
||||
static const char* default_cachedir = "@MAXSCALE_VARDIR@/cache/maxscale";
|
||||
static const char* default_langdir = "@MAXSCALE_VARDIR@/lib/maxscale";
|
||||
static const char* default_execdir = "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@";
|
||||
static const char* default_piddir = "@MAXSCALE_VARDIR@/" MXS_DEFAULT_PID_SUBPATH;
|
||||
static const char* default_logdir = "@MAXSCALE_VARDIR@/" MXS_DEFAULT_LOG_SUBPATH;
|
||||
static const char* default_datadir = "@MAXSCALE_VARDIR@/" MXS_DEFAULT_DATA_SUBPATH;
|
||||
static const char* default_libdir = "@CMAKE_INSTALL_PREFIX@/" MXS_DEFAULT_LIB_SUBPATH;
|
||||
static const char* default_cachedir = "@MAXSCALE_VARDIR@/" MXS_DEFAULT_CACHE_SUBPATH;
|
||||
static const char* default_langdir = "@MAXSCALE_VARDIR@/" MXS_DEFAULT_LANG_SUBPATH;
|
||||
static const char* default_execdir = "@CMAKE_INSTALL_PREFIX@/" MXS_DEFAULT_EXEC_SUBPATH;
|
||||
|
||||
static char* configdir = NULL;
|
||||
static char* logdir = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user