Added configurable executable file directory

This allows MaxScale to launch processes from the directory where
the `maxscale` executable is located.
This commit is contained in:
Markus Makela
2016-02-15 11:12:54 +02:00
parent 477197ff5b
commit a628fdcb17
7 changed files with 71 additions and 40 deletions

View File

@ -281,6 +281,14 @@ Configure the directory for the PID file for MaxScale. This file contains the Pr
piddir=/tmp/maxscale_cache/
```
#### `execdir`
Configure the directory where the executable files reside. All internal processes which are launched will use this directory to look for executable files.
```
execdir=/usr/local/bin/
```
#### `language`
Set the folder where the errmsg.sys file is located in. MaxScale will look for the errmsg.sys file installed with MaxScale from this folder.

View File

@ -27,26 +27,7 @@ or
```
It is also possible to start MaxScale by executing the maxscale command itself. Running the executable /usr/bin/maxscale will result in MaxScale running as a daemon process, unattached to the terminal in which it was started and using configuration files that it finds in the /etc directory.
Options may be passed to the MaxScale binary that alter this default behavior, this options are documented in the table below.
Switch|Long Option|Description
------|-----------|-----------
`-d`|`--nodaemon`|enable running in terminal process (default:disabled)
`-f FILE`|`--config=FILE`|relative or absolute pathname of MaxScale configuration file (default:/etc/maxscale.cnf)
`-l[file shm]`|`--log=[file shm]`|log to file or shared memory (default: file)
`-L PATH`|`--logdir=PATH`|path to log file directory (default: /var/log/maxscale)
`-D PATH`|`--datadir=PATH`|path to data directory, stored embedded mysql tables (default: /var/cache/maxscale)
`-C PATH`|`--configdir=PATH`|path to configuration file directory (default: /etc/)
`-B PATH`|`--libdir=PATH`|path to module directory (default: /usr/lib64/maxscale)
`-A PATH`|`--cachedir=PATH`|path to cache directory (default: /var/cache/maxscale)
`P PATH`|`--piddir=PATH`|PID file directory
`-U USER`|`--user=USER`|run MaxScale as another user. The user ID and group ID of this user are used to run MaxScale.
`-s [yes no]`|`--syslog=[yes no]`|log messages to syslog (default:yes)
`-S [yes no]`|`--maxlog=[yes no]`|log messages to MaxScale log (default: yes)
`-G [0 1]`|`--log_augmentation=[0 1]`|augment messages with the name of the function where the message was logged (default: 0). Primarily for development purposes.
`-v`|`--version`|print version info and exit
`-V`|`--version-full`|print version info and the commit ID the binary was built from
`-?`|`--help`|show this help
Options may be passed to the MaxScale binary that alter this default behavior. For a full list of all parameters, refer to the MaxScale help output by executing `maxscale --help`.
Additional command line arguments can be passed to MaxScale with a configuration file placed at `/etc/sysconfig/maxscale` on RPM installations and `/etc/default/maxscale` file on DEB installations. Set the arguments in a variable called `MAXSCALE_OPTIONS` and remember to surround the arguments with quotes. The file should only contain environment variable declarations.

View File

@ -44,6 +44,9 @@ Path to cache directory. This is where MaxScale stores cached authentication dat
.BR -P " \fIPATH\fB, --piddir=\fIPATH\fB"
Location of MaxScale's PID file.
.TP
.BR -E " \fIPATH\fB, --execdir=\fIPATH\fB"
Location of the executable files. When internal processes are launched from within MaxScale the binaries are assumed to be in this directory. If you have a custom location for binary executable files you need to add this parameter.
.TP
.BR -U " \fIUSER\fB, --user=\fIUSER\fB"
Run MaxScale as another user. The user ID and group ID of this user are used to run MaxScale.
.TP

View File

@ -22,11 +22,11 @@
*
*/
#include <sys/auxv.h>
#include <elf.h>
#include <log_manager.h>
#include <modules.h>
#include <query_classifier.h>
#include <gwdirs.h>
//#define QC_TRACE_ENABLED
#undef QC_TRACE_ENABLED
@ -88,28 +88,14 @@ static void end_and_unload_classifier(QUERY_CLASSIFIER* classifier, const char*
static bool resolve_pp_path(char* path, int size)
{
bool success = false;
const char* exe_path = (const char*) getauxval(AT_EXECFN);
const char* exe_path = (const char*) get_execdir();
size_t len = strlen(exe_path);
if (len < size)
{
/** get_execdir will always return a cleaned up version of
* the executable path */
strcpy(path, exe_path);
char* s = path + len;
// Find the last '/'.
while ((*s != '/') && (s != path))
{
--s;
--len;
}
if (*s == '/')
{
++s;
++len;
}
*s = 0;
int required_size = len + sizeof(MAXPP) + 1;

View File

@ -939,6 +939,8 @@ static void usage(void)
" -C, --configdir=PATH path to configuration file directory (default: /etc/)\n"
" -D, --datadir=PATH path to data directory, stored embedded mysql tables\n"
" (default: /var/cache/maxscale)\n"
" -E, --execdir=PATH path to the maxscale and other executable files\n"
" (default: /usr/bin)\n"
" -N, --language=PATH path to errmsg.sys file (default: /var/lib/maxscale)\n"
" -P, --piddir=PATH path to PID file directory (default: /var/run/maxscale)\n"
" -U, --user=USER run MaxScale as another user.\n"
@ -1271,7 +1273,7 @@ int main(int argc, char **argv)
}
}
while ((opt = getopt_long(argc, argv, "dc:f:l:vVs:S:?L:D:C:B:U:A:P:G:N:",
while ((opt = getopt_long(argc, argv, "dc:f:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:",
long_options, &option_index)) != -1)
{
bool succp = true;
@ -1404,6 +1406,18 @@ int main(int argc, char **argv)
succp = false;
}
break;
case 'E':
if (handle_path_arg(&tmp_path, optarg, NULL, true, false))
{
set_execdir(tmp_path);
}
else
{
succp = false;
}
break;
case 'S':
{
char* tok = strstr(optarg, "=");
@ -2294,7 +2308,7 @@ void set_log_augmentation(const char* value)
}
/**
* Pre-parse the MaxScale.cnf for config, log and module directories.
* Pre-parse the configuration file for various directory paths.
* @param data Parameter passed by inih
* @param section Section name
* @param name Parameter name
@ -2396,6 +2410,20 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
}
}
}
else if (strcmp(name, "execdir") == 0)
{
if (strcmp(get_execdir(), default_execdir) == 0)
{
if (handle_path_arg((char**)&tmp, (char*)value, NULL, true, false))
{
set_execdir(tmp);
}
else
{
return 0;
}
}
}
else if (strcmp(name, "syslog") == 0)
{
if (!syslog_configured)

View File

@ -96,6 +96,18 @@ void set_libdir(char* param)
libdir = param;
}
/**
* Set the executable directory. Internal processes will look for executables
* from here.
* @param str Path to directory
*/
void set_execdir(char* param)
{
free(execdir);
clean_up_pathname(param);
execdir = param;
}
/**
* Get the directory with all the modules.
* @return The module directory
@ -158,3 +170,12 @@ char* get_langdir()
{
return langdir ? langdir : (char*) default_langdir;
}
/**
* Get the directory with the executables.
* @return The executables directory
*/
char* get_execdir()
{
return execdir ? execdir : (char*) default_execdir;
}

View File

@ -39,6 +39,7 @@ static const char* default_datadir = "@MAXSCALE_VARDIR@/lib/maxscale/data";
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 char* configdir = NULL;
static char* logdir = NULL;
@ -47,6 +48,7 @@ static char* cachedir = NULL;
static char* maxscaledatadir = NULL;
static char* langdir = NULL;
static char* piddir = NULL;
static char* execdir = NULL;
void set_libdir(char* param);
void set_datadir(char* param);
@ -55,6 +57,7 @@ void set_configdir(char* param);
void set_logdir(char* param);
void set_langdir(char* param);
void set_piddir(char* param);
void set_execdir(char* param);
char* get_libdir();
char* get_datadir();
char* get_cachedir();
@ -62,6 +65,7 @@ char* get_configdir();
char* get_piddir();
char* get_logdir();
char* get_langdir();
char* get_execdir();
EXTERN_C_BLOCK_END