From eec053924c0fd1085023458ade00098c7110fb39 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Fri, 24 Apr 2015 22:11:49 +0300 Subject: [PATCH 01/34] Updated various MaxScale command line and configuration options to allow custom log, module, data, cache and language directories. --- CMakeLists.txt | 30 ++++-- server/core/gateway.c | 226 +++++++++++++++++++++++++++------------ server/core/load_utils.c | 9 +- server/include/gw.h | 1 + 4 files changed, 185 insertions(+), 81 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94842ebaa..e654e766e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,19 +137,29 @@ ${CMAKE_SOURCE_DIR}/Documentation/Release-Notes/MaxScale-1.1-Release-Notes.md execute_process(COMMAND perl ${CMAKE_SOURCE_DIR}/Documentation/format.pl ${CMAKE_SOURCE_DIR}/Documentation/Upgrading-To-MaxScale-1.1.0.md ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt) -install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION .) -install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION .) -install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION .) message(STATUS "Installing MaxScale to: ${CMAKE_INSTALL_PREFIX}/") -install(FILES server/MaxScale_template.cnf DESTINATION etc) -install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION etc) -install(FILES ${ERRMSG} DESTINATION mysql) -install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION .) -install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION .) -install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION .) - +if(PACKAGE) + install(FILES server/MaxScale_template.cnf DESTINATION /etc) + install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION /etc) + install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION /usr/share/maxscale) + install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION /usr/share/maxscale) + install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/maxscale) + install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION /usr/share/maxscale) + install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION /usr/share/maxscale) + install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION /usr/share/maxscale) +else() + install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION .) + install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION .) + install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION .) + install(FILES server/MaxScale_template.cnf DESTINATION etc) + install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION etc) + install(FILES ${ERRMSG} DESTINATION mysql) + install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION .) + install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION .) + install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION .) +endif() # Install startup scripts and ldconfig files if(WITH_SCRIPTS) configure_file(${CMAKE_SOURCE_DIR}/maxscale.conf.in ${CMAKE_BINARY_DIR}/maxscale.conf @ONLY) diff --git a/server/core/gateway.c b/server/core/gateway.c index ed69d3e3e..c06b9f309 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -113,12 +113,15 @@ static char* server_options[] = { const int num_elements = (sizeof(server_options) / sizeof(char *)) - 1; -const char* default_cnf_fname = "etc/MaxScale.cnf"; +const char* default_cnf_fname = "MaxScale.cnf"; const char* default_configdir = "/etc/"; const char* default_logdir = "/var/log/maxscale/"; -const char* default_libdir = "/lib64/maxscale/lib/"; -const char* default_moddir = "/lib64/maxscale/modules/"; +const char* default_datadir = "/var/lib/maxscale/"; +const char* default_moduledir = "/lib64/maxscale/modules/"; +const char* default_cachedir = "/var/cache/maxscale/"; +const char* default_langdir = "/usr/share/mysql/english/"; +const char* default_piddir = "/var/run/maxscale/"; static char* server_groups[] = { "embedded", @@ -132,14 +135,15 @@ static char* server_groups[] = { /* The data directory we created for this gateway instance */ static char datadir[PATH_MAX+1] = ""; - +static bool datadir_defined = false; /*< If the datadir was already set */ /* The data directory we created for this gateway instance */ static char pidfile[PATH_MAX+1] = ""; static char* configdir = NULL; static char* logdir = NULL; -static char* libdir = NULL; -static char* moddir = NULL; +static char* moduledir = NULL; +static char* cachedir = NULL; +static char* langdir = NULL; /** * exit flag for log flusher. */ @@ -161,9 +165,14 @@ static struct option long_options[] = { {"config", required_argument, 0, 'f'}, {"nodaemon", no_argument, 0, 'd'}, {"log", required_argument, 0, 'l'}, - {"logdir", required_argument, 0, 'L'}, + {"logdir", required_argument, 0, 'L'}, + {"datadir", required_argument, 0, 'D'}, + {"configdir",required_argument, 0, 'C'}, + {"moduledir",required_argument, 0, 'B'}, + {"cachedir",required_argument, 0, 'A'}, + {"language",required_argument, 0, 'N'}, {"syslog", required_argument, 0, 's'}, - {"maxscalelog", required_argument, 0, 'S'}, + {"maxscalelog",required_argument,0,'S'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, '?'}, {0, 0, 0, 0} @@ -201,6 +210,14 @@ static bool resolve_maxscale_homedir( static char* check_dir_access(char* dirname,bool,bool); +/** + * Get the directory with all the modules. + * @return The module directory + */ +char* get_moduledir() +{ + return moduledir; +} /** * Handler for SIGHUP signal. Reload the configuration for the * gateway. @@ -369,11 +386,10 @@ void datadir_cleanup() { int depth = 1; int flags = FTW_CHDIR|FTW_DEPTH|FTW_MOUNT; - int rc; if (datadir[0] != 0 && access(datadir, F_OK) == 0) { - rc = nftw(datadir, ntfw_cb, depth, flags); + nftw(datadir, ntfw_cb, depth, flags); } } @@ -394,14 +410,13 @@ static bool file_write_footer( FILE* outfile) { bool succp = false; - size_t wbytes1; size_t len1; const char* header_buf1; header_buf1 = "------------------------------------------------------" "\n\n"; len1 = strlen(header_buf1); - wbytes1=fwrite((void*)header_buf1, len1, 1, outfile); + fwrite((void*)header_buf1, len1, 1, outfile); succp = true; @@ -412,9 +427,6 @@ static bool file_write_header( FILE* outfile) { bool succp = false; - size_t wbytes1; - size_t wbytes2; - size_t wbytes3; size_t len1; size_t len2; size_t len3; @@ -458,9 +470,9 @@ static bool file_write_header( #if defined(LAPTOP_TEST) nanosleep(&ts1, NULL); #else - wbytes1=fwrite((void*)header_buf1, len1, 1, outfile); - wbytes2=fwrite((void*)header_buf2, len2, 1, outfile); - wbytes3=fwrite((void*)header_buf3, len3, 1, outfile); + fwrite((void*)header_buf1, len1, 1, outfile); + fwrite((void*)header_buf2, len2, 1, outfile); + fwrite((void*)header_buf3, len3, 1, outfile); #endif succp = true; @@ -1015,20 +1027,28 @@ static void usage(void) { fprintf(stderr, "\nUsage : %s [-h] | [-d] [-c ] [-f ]\n\n" - " -d|--nodaemon enable running in terminal process (default:disabled)\n" - " -c|--homedir=... relative|absolute MaxScale home directory\n" - " -f|--config=... relative|absolute pathname of MaxScale configuration file\n" - " (default: $MAXSCALE_HOME/etc/MaxScale.cnf)\n" - " -l|--log=... log to file or shared memory\n" - " -lfile or -lshm - defaults to shared memory\n" - " -L|--logdir=... path to log file directory\n" - " (default: /var/log/maxscale)\n" - " -s|--syslog= log messages to syslog." - " True or false - defaults to true\n" - " -S|--maxscalelog= log messages to MaxScale log." - " True or false - defaults to true\n" - " -v|--version print version info and exit\n" - " -?|--help show this help\n" + " -d|--nodaemon enable running in terminal process (default:disabled)\n" + " -c|--homedir=... relative|absolute MaxScale home directory\n" + " -f|--config=... relative|absolute pathname of MaxScale configuration file\n" + " (default: $MAXSCALE_HOME/etc/MaxScale.cnf)\n" + " -l|--log=... log to file or shared memory\n" + " -lfile or -lshm - defaults to shared memory\n" + " -L|--logdir=... path to log file directory\n" + " (default: /var/log/maxscale)\n" + " -D|--datadir=... path to data directory\n" + " (default: /var/lib/maxscale)\n" + " -C|--configdir=... path to configuration file directory\n" + " (default: /etc/)\n" + " -B|--moduledir=... path to module directory\n" + " (default: /var/lib/maxscale)\n" + " -A|--cachedir=... path to cache directory\n" + " (default: /var/cache/maxscale)\n" + " -s|--syslog= log messages to syslog.\n" + " True or false - defaults to true\n" + " -S|--maxscalelog= log messages to MaxScale log.\n" + " True or false - defaults to true\n" + " -v|--version print version info and exit\n" + " -?|--help show this help\n" , progname); } @@ -1103,9 +1123,8 @@ int main(int argc, char **argv) NULL}; sigemptyset(&sigpipe_mask); sigaddset(&sigpipe_mask, SIGPIPE); - progname = *argv; - + sprintf(datadir, "%s", default_datadir); #if defined(FAKE_CODE) memset(conn_open, 0, sizeof(bool)*10240); memset(dcb_fake_write_errno, 0, sizeof(unsigned char)*10240); @@ -1133,7 +1152,7 @@ int main(int argc, char **argv) } } - while ((opt = getopt_long(argc, argv, "dc:f:l:vs:S:?L:", + while ((opt = getopt_long(argc, argv, "dc:f:l:vs:S:?L:D:C:B:", long_options, &option_index)) != -1) { bool succp = true; @@ -1245,6 +1264,33 @@ int main(int argc, char **argv) logdir = tmp_path; } + break; + case 'N': + if(handle_path_arg(&tmp_path,optarg,NULL,true,false)) + { + langdir = tmp_path; + } + break; + case 'D': + sprintf(datadir,"%s",optarg); + datadir_defined = true; + break; + case 'C': + if(handle_path_arg(&tmp_path,optarg,NULL,true,false)) + { + configdir = tmp_path; + } + break; + case 'B': + if(handle_path_arg(&tmp_path,optarg,NULL,true,false)) + { + moduledir = tmp_path; + } + case 'A': + if(handle_path_arg(&tmp_path,optarg,NULL,true,true)) + { + cachedir = tmp_path; + } break; case 'S': if(strstr(optarg,"=")) @@ -1547,11 +1593,17 @@ int main(int argc, char **argv) goto return_main; } - /*< + /** Use the cache dir for the mysql folder of the embedded library */ + sprintf(mysql_home, "%s/mysql", cachedir); + setenv("MYSQL_HOME", mysql_home, 1); + + /*< * If MaxScale home directory wasn't set by command-line argument. * Next, resolve it from environment variable and further on, * try to use default. */ +/* + if (home_dir == NULL) { if (!resolve_maxscale_homedir(&home_dir)) @@ -1560,8 +1612,7 @@ int main(int argc, char **argv) rc = MAXSCALE_HOMELESS; goto return_main; } - sprintf(mysql_home, "%s/mysql", home_dir); - setenv("MYSQL_HOME", mysql_home, 1); + } else { @@ -1601,13 +1652,28 @@ int main(int argc, char **argv) } free(log_context); } +*/ - char pbuf[PATH_MAX]; + /** + * Resolve the full pathname for configuration file and check for + * read accessibility. + */ + char pathbuf[PATH_MAX+1]; + snprintf(pathbuf,PATH_MAX,"%s",configdir ? configdir:default_configdir); + if(pathbuf[strlen(pathbuf)-1] != '/') + strcat(pathbuf,"/"); - sprintf(pbuf,"%s/etc/MaxScale.cnf",home_dir); + if (!resolve_maxscale_conf_fname(&cnf_file_path, pathbuf, cnf_file_arg)) + { + ss_dassert(cnf_file_path == NULL); + rc = MAXSCALE_BADCONFIG; + goto return_main; + } - ini_parse(pbuf,cnf_preparser,NULL); + ini_parse(cnf_file_path,cnf_preparser,NULL); + if(!datadir_defined) + sprintf(datadir,"%s",default_datadir); /** * Init Log Manager for MaxScale. * If $MAXSCALE_HOME is set then write the logs into $MAXSCALE_HOME/log. @@ -1678,25 +1744,25 @@ int main(int argc, char **argv) goto return_main; } } - /** - * Resolve the full pathname for configuration file and check for - * read accessibility. - */ - if (!resolve_maxscale_conf_fname(&cnf_file_path, home_dir, cnf_file_arg)) - { - ss_dassert(cnf_file_path == NULL); - rc = MAXSCALE_BADCONFIG; - goto return_main; - } - /*< + + + if(cachedir == NULL) + cachedir = strdup(default_cachedir); + + if(langdir == NULL) + langdir = strdup(default_langdir); + + /** * Set a data directory for the mysqld library, we use * a unique directory name to avoid clauses if multiple * instances of the gateway are beign run on the same * machine. */ - sprintf(datadir, "%s/data", home_dir); + if(datadir[strlen(datadir)-1] != '/') + strcat(datadir,"/"); + strcat(datadir,"data"); if(mkdir(datadir, 0777) != 0){ if(errno != EEXIST){ @@ -1706,7 +1772,7 @@ int main(int argc, char **argv) } } - sprintf(datadir, "%s/data/data%d", home_dir, getpid()); + sprintf(datadir, "%s/data%d", datadir, getpid()); if(mkdir(datadir, 0777) != 0){ @@ -1720,27 +1786,29 @@ int main(int argc, char **argv) if (!daemon_mode) { fprintf(stderr, - "Home directory : %s" - "\nConfiguration file : %s" + //"Home directory : %s" + "Configuration file : %s" "\nLog directory : %s" "\nData directory : %s\n\n", - home_dir, + //home_dir, cnf_file_path, logdir, datadir); } +/* LOGIF(LM, (skygw_log_write_flush( LOGFILE_MESSAGE, "Home directory : %s", home_dir))); +*/ LOGIF(LM, (skygw_log_write_flush( LOGFILE_MESSAGE, "Data directory : %s", datadir))); LOGIF(LM, (skygw_log_write_flush( LOGFILE_MESSAGE, - "Log directory : %s/log", - home_dir))); + "Log directory : %s/", + logdir))); LOGIF(LM, (skygw_log_write_flush( LOGFILE_MESSAGE, "Configuration file : %s", @@ -1758,8 +1826,8 @@ int main(int argc, char **argv) { snprintf(language_arg, 11+PATH_MAX+1, - "--language=%s/mysql", - home_dir); + "--language=%s", + langdir); server_options[i] = language_arg; } } @@ -1815,6 +1883,9 @@ int main(int argc, char **argv) } libmysqld_started = TRUE; + if(moduledir == NULL) + moduledir = strdup(default_moduledir); + if (!config_load(cnf_file_path)) { char* fprerr = "Failed to load MaxScale configuration " @@ -2015,7 +2086,7 @@ static int write_pid_file(char *home_dir) { int fd = -1; - snprintf(pidfile, PATH_MAX, "%s/data/maxscale.pid", home_dir); + snprintf(pidfile, PATH_MAX, "%smaxscale.pid",default_piddir); fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd == -1) { @@ -2100,21 +2171,42 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons char pathbuffer[PATH_MAX]; char* errstr; + /** These are read from the configuration file. These will not override + * command line parameters but will override default values. */ if(strcasecmp(section,"maxscale") == 0) { if(strcmp(name, "logdir") == 0) { - /** logdir is only NULL if no command line parameter was given */ if(logdir == NULL) handle_path_arg(&logdir,(char*)value,NULL,true,true); } - else if(strcmp(name, "moddir") == 0) + else if(strcmp(name, "moduledir") == 0) { - handle_path_arg(&moddir,(char*)value,NULL,true,false); + if(moduledir == NULL) + handle_path_arg(&moduledir,(char*)value,NULL,true,false); } - else if(strcmp(name, "libdir") == 0) + else if(strcmp(name, "datadir") == 0) { - handle_path_arg(&libdir,(char*)value,NULL,true,false); + if(!datadir_defined) + { + char* tmp; + if(handle_path_arg(&tmp,(char*)value,NULL,true,false)) + { + sprintf(datadir,"%s",tmp); + datadir_defined = true; + free(tmp); + } + } + } + else if(strcmp(name, "cachedir") == 0) + { + if(cachedir == NULL) + handle_path_arg((char**)&datadir,(char*)value,NULL,true,false); + } + else if(strcmp(name, "language") == 0) + { + if(langdir == NULL) + handle_path_arg((char**)&langdir,(char*)value,NULL,true,false); } } diff --git a/server/core/load_utils.c b/server/core/load_utils.c index 172f24ad0..c2716befa 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -48,6 +48,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -146,16 +147,16 @@ MODULE_INFO *mod_info = NULL; if (access(fname, F_OK) == -1) { - home = get_maxscale_home (); - snprintf(fname, MAXPATHLEN+1,"%s/modules/lib%s.so", home, module); + //home = get_maxscale_home (); + snprintf(fname, MAXPATHLEN+1,"%s/lib%s.so", get_moduledir(), module); if (access(fname, F_OK) == -1) { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : Unable to find library for " - "module: %s.", - module))); + "module: %s. Module dir: %s", + module, get_moduledir()))); return NULL; } } diff --git a/server/include/gw.h b/server/include/gw.h index 9c8507210..e2c69aa7c 100644 --- a/server/include/gw.h +++ b/server/include/gw.h @@ -65,3 +65,4 @@ int gw_write(DCB *dcb, const void *buf, size_t nbytes); int gw_getsockerrno(int fd); int parse_bindconfig(char *, unsigned short, struct sockaddr_in *); int setipaddress(struct in_addr *, char *); +char* get_moduledir(); \ No newline at end of file From df9bc65430c8f786fd71b52dbd0f22dcba911cc1 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sat, 25 Apr 2015 06:53:59 +0300 Subject: [PATCH 02/34] Added variables that are used when installing instead of relative paths. --- CMakeLists.txt | 35 ++++------ client/CMakeLists.txt | 2 +- log_manager/CMakeLists.txt | 4 +- macros.cmake | 28 ++++++++ query_classifier/CMakeLists.txt | 2 +- server/core/CMakeLists.txt | 6 +- server/core/gateway.c | 65 +++++++++---------- server/core/load_utils.c | 1 - server/include/gw.h | 17 ++++- server/modules/filter/CMakeLists.txt | 18 ++--- server/modules/filter/hint/CMakeLists.txt | 2 +- server/modules/monitor/CMakeLists.txt | 8 +-- server/modules/protocol/CMakeLists.txt | 12 ++-- server/modules/routing/CMakeLists.txt | 12 ++-- server/modules/routing/binlog/CMakeLists.txt | 4 +- server/modules/routing/maxinfo/CMakeLists.txt | 4 +- .../routing/readwritesplit/CMakeLists.txt | 2 +- 17 files changed, 122 insertions(+), 100 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e654e766e..48bf38e8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ if(NOT CURL_FOUND) message(FATAL_ERROR "Failed to locate dependency: libcurl") endif() -set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/modules) # Make sure the release notes for this release are present if it is a stable one if(${MAXSCALE_VERSION} MATCHES "-stable") @@ -47,6 +46,7 @@ if(${MAXSCALE_VERSION} MATCHES "-stable") message(FATAL_ERROR "Could not find the release notes for this stable release: ${MAXSCALE_VERSION_NUMERIC}") endif() endif() +set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/${MAXSCALE_MODULE_INSTALL}:${CMAKE_INSTALL_PREFIX}/${MAXSCALE_LIBRARY_INSTALL}) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/server/include) configure_file(${CMAKE_SOURCE_DIR}/server/include/version.h.in ${CMAKE_BINARY_DIR}/server/include/version.h) @@ -127,7 +127,7 @@ if(NOT WITHOUT_MAXADMIN) add_subdirectory(client) endif() - +# Generate text versions of some documents execute_process(COMMAND perl ${CMAKE_SOURCE_DIR}/Documentation/format.pl ${CMAKE_SOURCE_DIR}/Documentation/Changelog.md ${CMAKE_BINARY_DIR}/Changelog.txt) @@ -138,28 +138,17 @@ execute_process(COMMAND perl ${CMAKE_SOURCE_DIR}/Documentation/format.pl ${CMAKE_SOURCE_DIR}/Documentation/Upgrading-To-MaxScale-1.1.0.md ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt) -message(STATUS "Installing MaxScale to: ${CMAKE_INSTALL_PREFIX}/") -if(PACKAGE) - install(FILES server/MaxScale_template.cnf DESTINATION /etc) - install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION /etc) - install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION /usr/share/maxscale) - install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION /usr/share/maxscale) - install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/maxscale) - install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION /usr/share/maxscale) - install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION /usr/share/maxscale) - install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION /usr/share/maxscale) -else() - install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION .) - install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION .) - install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION .) - install(FILES server/MaxScale_template.cnf DESTINATION etc) - install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION etc) - install(FILES ${ERRMSG} DESTINATION mysql) - install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION .) - install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION .) - install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION .) -endif() +install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION ${MAXSCALE_SHARE_DIR}) +install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION ${MAXSCALE_SHARE_DIR}) +install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION ${MAXSCALE_SHARE_DIR}) +install(FILES server/MaxScale_template.cnf DESTINATION ${MAXSCALE_CONFIG_DIR}) +install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION ${MAXSCALE_CONFIG_DIR}) +install(FILES ${ERRMSG} DESTINATION ${MAXSCALE_LANG_DIR}) +install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION ${MAXSCALE_SHARE_DIR}) +install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION ${MAXSCALE_SHARE_DIR}) +install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${MAXSCALE_SHARE_DIR}) + # Install startup scripts and ldconfig files if(WITH_SCRIPTS) configure_file(${CMAKE_SOURCE_DIR}/maxscale.conf.in ${CMAKE_BINARY_DIR}/maxscale.conf @ONLY) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 755f2eac8..9b679aae0 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -7,4 +7,4 @@ if(HIST) else() message(STATUS "Could not find editline library. MaxAdmin will be built without it.") endif() -install(TARGETS maxadmin DESTINATION bin) +install(TARGETS maxadmin DESTINATION ${MAXSCALE_EXECUTABLE_INSTALL}) diff --git a/log_manager/CMakeLists.txt b/log_manager/CMakeLists.txt index fdef33f6c..607341d9a 100644 --- a/log_manager/CMakeLists.txt +++ b/log_manager/CMakeLists.txt @@ -3,7 +3,7 @@ if(LOG_DEBUG) endif() add_library(log_manager SHARED log_manager.cc) target_link_libraries(log_manager pthread aio stdc++) -install(TARGETS log_manager DESTINATION lib) +install(TARGETS log_manager DESTINATION ${MAXSCALE_LIBRARY_INSTALL}) if(BUILD_TESTS) add_subdirectory(test) -endif() \ No newline at end of file +endif() diff --git a/macros.cmake b/macros.cmake index 440c3fed5..d80202534 100644 --- a/macros.cmake +++ b/macros.cmake @@ -74,6 +74,34 @@ macro(set_variables) # Build extra tools set(BUILD_TOOLS FALSE CACHE BOOL "Build extra utility tools") + # Change installation directories to standard locations for packages + if(PACKAGE) + set(MAXSCALE_MODULE_INSTALL /lib64/maxscale CACHE PATH "Module installation path") + set(MAXSCALE_LIBRARY_INSTALL /lib64/maxscale CACHE PATH "Library installation path") + message(STATUS "Installing MaxScale modules to: ${MAXSCALE_MODULE_INSTALL}/") + set(MAXSCALE_EXECUTABLE_INSTALL /bin CACHE PATH "Executable installation path") + message(STATUS "Installing MaxScale binaries to: ${MAXSCALE_EXECUTABLE_INSTALL}/") + set(MAXSCALE_CONFIG_DIR /etc CACHE PATH "Configuration file installation path") + set(MAXSCALE_DOC_DIR /usr/share/maxscale/doc CACHE PATH "Documentation installation path") + set(MAXSCALE_LOG_DIR /var/log/maxscale CACHE PATH "Log file directory") + message(STATUS "MaxScale log directory: ${MAXSCALE_LOG_DIR}/") + set(MAXSCALE_CACHE_DIR /var/cache/maxscale CACHE PATH "Service cache file directory") + set(MAXSCALE_LANG_DIR /var/cache/maxscale CACHE PATH "Language file directory(errmsg.sys)") + set(MAXSCALE_SHARE_DIR /usr/share/maxscale CACHE PATH "Share file installation path") + set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_MODULE_DIR}:${MAXSCALE_LIBRARY_DIR}) + else() + message(STATUS "Installing MaxScale to: ${CMAKE_INSTALL_PREFIX}/") + set(MAXSCALE_MODULE_INSTALL lib64/maxscale CACHE PATH "Module installation path") + set(MAXSCALE_LIBRARY_INSTALL lib64/maxscale CACHE PATH "Library installation path") + set(MAXSCALE_EXECUTABLE_INSTALL bin CACHE PATH "Executable installation path") + set(MAXSCALE_CONFIG_DIR etc CACHE PATH "Configuration file installation path") + set(MAXSCALE_DOC_DIR doc CACHE PATH "Documentation installation path") + set(MAXSCALE_LOG_DIR log CACHE PATH "Log file directory") + set(MAXSCALE_CACHE_DIR cache CACHE PATH "Service cache file directory") + set(MAXSCALE_LANG_DIR cache CACHE PATH "Log file directory") + set(MAXSCALE_SHARE_DIR . CACHE PATH "Share file installation path") + endif() + endmacro() macro(check_deps) diff --git a/query_classifier/CMakeLists.txt b/query_classifier/CMakeLists.txt index 42270cd2c..7fb36d6c6 100644 --- a/query_classifier/CMakeLists.txt +++ b/query_classifier/CMakeLists.txt @@ -1,5 +1,5 @@ add_library(query_classifier SHARED query_classifier.cc) -install(TARGETS query_classifier DESTINATION lib) +install(TARGETS query_classifier COMPONENT lib DESTINATION ${MAXSCALE_LIBRARY_INSTALL}) if(BUILD_TESTS) add_subdirectory(test) endif() diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 630d4c034..ee01396d8 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -18,15 +18,15 @@ if(WITH_TCMALLOC) endif() target_link_libraries(maxscale ${EMBEDDED_LIB} ${PCRE_LINK_FLAGS} ${CURL_LIBRARIES} log_manager utils ssl aio pthread crypt dl crypto inih z rt m stdc++) -install(TARGETS maxscale DESTINATION bin) +install(TARGETS maxscale DESTINATION ${MAXSCALE_EXECUTABLE_INSTALL}) add_executable(maxkeys maxkeys.c secrets.c utils.c) target_link_libraries(maxkeys log_manager utils pthread crypt crypto) -install(TARGETS maxkeys DESTINATION bin) +install(TARGETS maxkeys DESTINATION ${MAXSCALE_EXECUTABLE_INSTALL}) add_executable(maxpasswd maxpasswd.c secrets.c utils.c) target_link_libraries(maxpasswd log_manager utils pthread crypt crypto) -install(TARGETS maxpasswd DESTINATION bin) +install(TARGETS maxpasswd DESTINATION ${MAXSCALE_EXECUTABLE_INSTALL}) if(BUILD_TESTS) add_subdirectory(test) diff --git a/server/core/gateway.c b/server/core/gateway.c index c06b9f309..d2bcd13a9 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -113,16 +113,6 @@ static char* server_options[] = { const int num_elements = (sizeof(server_options) / sizeof(char *)) - 1; -const char* default_cnf_fname = "MaxScale.cnf"; - -const char* default_configdir = "/etc/"; -const char* default_logdir = "/var/log/maxscale/"; -const char* default_datadir = "/var/lib/maxscale/"; -const char* default_moduledir = "/lib64/maxscale/modules/"; -const char* default_cachedir = "/var/cache/maxscale/"; -const char* default_langdir = "/usr/share/mysql/english/"; -const char* default_piddir = "/var/run/maxscale/"; - static char* server_groups[] = { "embedded", "server", @@ -1752,7 +1742,8 @@ int main(int argc, char **argv) if(langdir == NULL) langdir = strdup(default_langdir); - + if(moduledir == NULL) + moduledir = strdup(default_moduledir); /** * Set a data directory for the mysqld library, we use * a unique directory name to avoid clauses if multiple @@ -1786,33 +1777,35 @@ int main(int argc, char **argv) if (!daemon_mode) { fprintf(stderr, - //"Home directory : %s" - "Configuration file : %s" - "\nLog directory : %s" - "\nData directory : %s\n\n", - //home_dir, + "Configuration file : %s\n" + "Log directory : %s\n" + "Data directory : %s\n" + "Module directory : %s\n\n", cnf_file_path, logdir, - datadir); + datadir, + moduledir); } -/* - LOGIF(LM, (skygw_log_write_flush( - LOGFILE_MESSAGE, - "Home directory : %s", - home_dir))); -*/ - LOGIF(LM, (skygw_log_write_flush( - LOGFILE_MESSAGE, - "Data directory : %s", - datadir))); - LOGIF(LM, (skygw_log_write_flush( - LOGFILE_MESSAGE, - "Log directory : %s/", - logdir))); - LOGIF(LM, (skygw_log_write_flush( - LOGFILE_MESSAGE, - "Configuration file : %s", - cnf_file_path))); + + LOGIF(LM, + (skygw_log_write_flush( + LOGFILE_MESSAGE, + "Configuration file: %s", + cnf_file_path))); + LOGIF(LM, + (skygw_log_write_flush( + LOGFILE_MESSAGE, + "Log directory: %s/", + logdir))); + LOGIF(LM, + (skygw_log_write_flush( + LOGFILE_MESSAGE, + "Data directory: %s", + datadir))); + LOGIF(LM, + (skygw_log_write_flush(LOGFILE_MESSAGE, + "Module directory: %s", + moduledir))); /*< Update the server options */ for (i = 0; server_options[i]; i++) @@ -2211,4 +2204,4 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons } return 1; -} \ No newline at end of file +} diff --git a/server/core/load_utils.c b/server/core/load_utils.c index c2716befa..c1ae57a3e 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -147,7 +147,6 @@ MODULE_INFO *mod_info = NULL; if (access(fname, F_OK) == -1) { - //home = get_maxscale_home (); snprintf(fname, MAXPATHLEN+1,"%s/lib%s.so", get_moduledir(), module); if (access(fname, F_OK) == -1) diff --git a/server/include/gw.h b/server/include/gw.h index e2c69aa7c..64db00204 100644 --- a/server/include/gw.h +++ b/server/include/gw.h @@ -1,3 +1,5 @@ +#ifndef _GW_HG +#define _GW_HG #include #include #include @@ -16,9 +18,19 @@ #include #include #include - #include +/** Default file locations */ +static const char* default_cnf_fname = "MaxScale.cnf"; +static const char* default_configdir = "/etc/"; +static const char* default_logdir = "/var/log/maxscale/"; +static const char* default_datadir = "/var/cache/maxscale/"; +static const char* default_moduledir = "/lib64/maxscale/"; +static const char* default_cachedir = "/var/cache/maxscale/"; +static const char* default_langdir = "/usr/share/mysql/english/"; /*< This is where the MariaDB + * server installs errmsg.sys */ +static const char* default_piddir = "/var/run/maxscale/"; + #define EXIT_FAILURE 1 // network buffer is 32K @@ -65,4 +77,5 @@ int gw_write(DCB *dcb, const void *buf, size_t nbytes); int gw_getsockerrno(int fd); int parse_bindconfig(char *, unsigned short, struct sockaddr_in *); int setipaddress(struct in_addr *, char *); -char* get_moduledir(); \ No newline at end of file +char* get_moduledir(); +#endif diff --git a/server/modules/filter/CMakeLists.txt b/server/modules/filter/CMakeLists.txt index 0af1ea566..77ebc7d0c 100644 --- a/server/modules/filter/CMakeLists.txt +++ b/server/modules/filter/CMakeLists.txt @@ -3,41 +3,41 @@ if(BUILD_RABBITMQ) include_directories(${RABBITMQ_HEADERS}) add_library(mqfilter SHARED mqfilter.c) target_link_libraries(mqfilter query_classifier log_manager utils ${RABBITMQ_LIBRARIES}) - install(TARGETS mqfilter DESTINATION modules) + install(TARGETS mqfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) endif() add_library(regexfilter SHARED regexfilter.c) target_link_libraries(regexfilter log_manager utils) -install(TARGETS regexfilter DESTINATION modules) +install(TARGETS regexfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(testfilter SHARED testfilter.c) target_link_libraries(testfilter log_manager utils) -install(TARGETS testfilter DESTINATION modules) +install(TARGETS testfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(qlafilter SHARED qlafilter.c) target_link_libraries(qlafilter log_manager utils) -install(TARGETS qlafilter DESTINATION modules) +install(TARGETS qlafilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(tee SHARED tee.c) target_link_libraries(tee log_manager utils) -install(TARGETS tee DESTINATION modules) +install(TARGETS tee DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(topfilter SHARED topfilter.c) target_link_libraries(topfilter log_manager utils) -install(TARGETS topfilter DESTINATION modules) +install(TARGETS topfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(dbfwfilter SHARED dbfwfilter.c) target_link_libraries(dbfwfilter log_manager utils query_classifier) -install(TARGETS dbfwfilter DESTINATION modules) +install(TARGETS dbfwfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(namedserverfilter SHARED namedserverfilter.c) target_link_libraries(namedserverfilter log_manager utils) -install(TARGETS namedserverfilter DESTINATION modules) +install(TARGETS namedserverfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) if(BUILD_SLAVELAG) add_library(slavelag SHARED slavelag.c) target_link_libraries(slavelag log_manager utils query_classifier) - install(TARGETS slavelag DESTINATION modules) + install(TARGETS slavelag DESTINATION ${MAXSCALE_MODULE_INSTALL}) endif() if(BUILD_TOOLS) diff --git a/server/modules/filter/hint/CMakeLists.txt b/server/modules/filter/hint/CMakeLists.txt index f47cb637e..ecc3cbb85 100644 --- a/server/modules/filter/hint/CMakeLists.txt +++ b/server/modules/filter/hint/CMakeLists.txt @@ -1,4 +1,4 @@ add_library(hintfilter SHARED hintfilter.c hintparser.c) set_target_properties(hintfilter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib) target_link_libraries(hintfilter ssl log_manager utils) -install(TARGETS hintfilter DESTINATION modules) \ No newline at end of file +install(TARGETS hintfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) diff --git a/server/modules/monitor/CMakeLists.txt b/server/modules/monitor/CMakeLists.txt index a99a66142..74a6f2870 100644 --- a/server/modules/monitor/CMakeLists.txt +++ b/server/modules/monitor/CMakeLists.txt @@ -1,16 +1,16 @@ add_library(mysqlmon SHARED mysql_mon.c) target_link_libraries(mysqlmon log_manager utils) -install(TARGETS mysqlmon DESTINATION modules) +install(TARGETS mysqlmon DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(galeramon SHARED galera_mon.c) target_link_libraries(galeramon log_manager utils) -install(TARGETS galeramon DESTINATION modules) +install(TARGETS galeramon DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(ndbclustermon SHARED ndbcluster_mon.c) target_link_libraries(ndbclustermon log_manager utils) -install(TARGETS ndbclustermon DESTINATION modules) +install(TARGETS ndbclustermon DESTINATION ${MAXSCALE_MODULE_INSTALL}) if(BUILD_MMMON) add_library(mmmon SHARED mm_mon.c) target_link_libraries(mmmon log_manager utils) - install(TARGETS mmmon DESTINATION modules) + install(TARGETS mmmon DESTINATION ${MAXSCALE_MODULE_INSTALL}) endif() diff --git a/server/modules/protocol/CMakeLists.txt b/server/modules/protocol/CMakeLists.txt index fa1c2ab34..488f2e4b6 100644 --- a/server/modules/protocol/CMakeLists.txt +++ b/server/modules/protocol/CMakeLists.txt @@ -1,27 +1,27 @@ add_library(MySQLClient SHARED mysql_client.c mysql_common.c) target_link_libraries(MySQLClient log_manager utils) -install(TARGETS MySQLClient DESTINATION modules) +install(TARGETS MySQLClient DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(MySQLBackend SHARED mysql_backend.c mysql_common.c) target_link_libraries(MySQLBackend log_manager utils) -install(TARGETS MySQLBackend DESTINATION modules) +install(TARGETS MySQLBackend DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(telnetd SHARED telnetd.c) target_link_libraries(telnetd log_manager utils) -install(TARGETS telnetd DESTINATION modules) +install(TARGETS telnetd DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(HTTPD SHARED httpd.c) target_link_libraries(HTTPD log_manager utils) -install(TARGETS HTTPD DESTINATION modules) +install(TARGETS HTTPD DESTINATION ${MAXSCALE_MODULE_INSTALL}) if(BUILD_TESTS) add_library(testprotocol SHARED testprotocol.c) - install(TARGETS testprotocol DESTINATION modules) + install(TARGETS testprotocol DESTINATION ${MAXSCALE_MODULE_INSTALL}) endif() add_library(maxscaled SHARED maxscaled.c) target_link_libraries(maxscaled log_manager utils) -install(TARGETS maxscaled DESTINATION modules) +install(TARGETS maxscaled DESTINATION ${MAXSCALE_MODULE_INSTALL}) diff --git a/server/modules/routing/CMakeLists.txt b/server/modules/routing/CMakeLists.txt index 77abe6cd1..b73edfa8c 100644 --- a/server/modules/routing/CMakeLists.txt +++ b/server/modules/routing/CMakeLists.txt @@ -2,28 +2,28 @@ if(BUILD_TESTS) add_subdirectory(test) add_library(testroute SHARED testroute.c) target_link_libraries(testroute log_manager utils) - install(TARGETS testroute DESTINATION modules) + install(TARGETS testroute DESTINATION ${MAXSCALE_MODULE_INSTALL}) endif() add_library(schemarouter SHARED schemarouter/schemarouter.c) target_link_libraries(schemarouter log_manager utils query_classifier) -install(TARGETS schemarouter DESTINATION modules) +install(TARGETS schemarouter DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(shardrouter SHARED schemarouter/shardrouter.c) target_link_libraries(shardrouter log_manager utils query_classifier) -install(TARGETS shardrouter DESTINATION modules) +install(TARGETS shardrouter DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(readconnroute SHARED readconnroute.c) target_link_libraries(readconnroute log_manager utils) -install(TARGETS readconnroute DESTINATION modules) +install(TARGETS readconnroute DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(debugcli SHARED debugcli.c debugcmd.c) target_link_libraries(debugcli log_manager utils) -install(TARGETS debugcli DESTINATION modules) +install(TARGETS debugcli DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_library(cli SHARED cli.c debugcmd.c) target_link_libraries(cli log_manager utils) -install(TARGETS cli DESTINATION modules) +install(TARGETS cli DESTINATION ${MAXSCALE_MODULE_INSTALL}) add_subdirectory(readwritesplit) add_subdirectory(schemarouter/test) diff --git a/server/modules/routing/binlog/CMakeLists.txt b/server/modules/routing/binlog/CMakeLists.txt index 4de2a35b4..9fcd8536e 100644 --- a/server/modules/routing/binlog/CMakeLists.txt +++ b/server/modules/routing/binlog/CMakeLists.txt @@ -1,4 +1,4 @@ add_library(binlogrouter SHARED blr.c blr_master.c blr_cache.c blr_slave.c blr_file.c) -set_target_properties(binlogrouter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib) +set_target_properties(binlogrouter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_MODULE_INSTALL}:${MAXSCALE_LIBRARY_INSTALL}) target_link_libraries(binlogrouter ssl pthread log_manager) -install(TARGETS binlogrouter DESTINATION modules) +install(TARGETS binlogrouter DESTINATION ${MAXSCALE_MODULE_INSTALL}) diff --git a/server/modules/routing/maxinfo/CMakeLists.txt b/server/modules/routing/maxinfo/CMakeLists.txt index 898df9b73..2585f2a2a 100644 --- a/server/modules/routing/maxinfo/CMakeLists.txt +++ b/server/modules/routing/maxinfo/CMakeLists.txt @@ -1,4 +1,4 @@ add_library(maxinfo SHARED maxinfo.c maxinfo_parse.c maxinfo_error.c maxinfo_exec.c) -set_target_properties(maxinfo PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib) +set_target_properties(maxinfo PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_MODULE_INSTALL}:MAXSCALE_LIBRARY_INSTALL) target_link_libraries(maxinfo pthread log_manager) -install(TARGETS maxinfo DESTINATION modules) +install(TARGETS maxinfo DESTINATION ${MAXSCALE_MODULE_INSTALL}) diff --git a/server/modules/routing/readwritesplit/CMakeLists.txt b/server/modules/routing/readwritesplit/CMakeLists.txt index 6960d4c8d..fe56582dc 100644 --- a/server/modules/routing/readwritesplit/CMakeLists.txt +++ b/server/modules/routing/readwritesplit/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(readwritesplit SHARED readwritesplit.c) target_link_libraries(readwritesplit ssl pthread log_manager utils query_classifier) -install(TARGETS readwritesplit DESTINATION modules) +install(TARGETS readwritesplit DESTINATION ${MAXSCALE_MODULE_INSTALL}) if(BUILD_TESTS) add_subdirectory(test) endif() From ed426ca30da5c61b9aaf7805bdd5c0166c2d0cd1 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 26 Apr 2015 06:21:28 +0300 Subject: [PATCH 03/34] Updated packaging install layout, moved some cmake files around. --- CMakeLists.txt | 14 +++++++++----- cmake/install_layout.cmake | 29 +++++++++++++++++++++++++++++ macros.cmake => cmake/macros.cmake | 28 ---------------------------- etc/postinst.in | 3 +++ plugins/CMakeLists.txt | 10 +++++----- server/core/gateway.c | 14 ++++++++++---- server/core/service.c | 8 +++++--- 7 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 cmake/install_layout.cmake rename macros.cmake => cmake/macros.cmake (83%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48bf38e8e..bf7e135e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,13 +6,16 @@ endif() message(STATUS "CMake version: ${CMAKE_VERSION}") -include(macros.cmake) - +include(${CMAKE_SOURCE_DIR}/cmake/macros.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/install_layout.cmake) enable_testing() set_variables() set_maxscale_version() -set(CMAKE_INSTALL_PREFIX "/usr/local/mariadb-maxscale" CACHE PATH "Prefix prepended to install directories.") + +set(INSTALL_LAYOUT "STANDALONE" CACHE STRING "Install layout, options are: STANDALONE, RPM, DEB") +set_install_layout(${INSTALL_LAYOUT}) + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") @@ -37,6 +40,7 @@ if(NOT CURL_FOUND) message(FATAL_ERROR "Failed to locate dependency: libcurl") endif() +set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_MODULE_DIR}:${MAXSCALE_LIBRARY_DIR}) # Make sure the release notes for this release are present if it is a stable one if(${MAXSCALE_VERSION} MATCHES "-stable") @@ -144,7 +148,7 @@ install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION ${MAXSCALE_SHARE_ install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION ${MAXSCALE_SHARE_DIR}) install(FILES server/MaxScale_template.cnf DESTINATION ${MAXSCALE_CONFIG_DIR}) install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION ${MAXSCALE_CONFIG_DIR}) -install(FILES ${ERRMSG} DESTINATION ${MAXSCALE_LANG_DIR}) +install(FILES ${ERRMSG} DESTINATION ${MAXSCALE_SHARE_DIR}) install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION ${MAXSCALE_SHARE_DIR}) install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION ${MAXSCALE_SHARE_DIR}) install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${MAXSCALE_SHARE_DIR}) @@ -225,7 +229,7 @@ if(PACKAGE) endif() endif() -add_custom_target(buildtests +add_custom_target(buildtestsx COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DWITH_SCRIPTS=N ${CMAKE_SOURCE_DIR} COMMAND make COMMENT "Building test suite..." VERBATIM diff --git a/cmake/install_layout.cmake b/cmake/install_layout.cmake new file mode 100644 index 000000000..0d594188f --- /dev/null +++ b/cmake/install_layout.cmake @@ -0,0 +1,29 @@ +# Set the install layout +# Possible values: +# STANDALONE - Installs to /usr/local/mariadb-maxscale +# RPM - Installs to /usr +# DEB - Installs to /usr +function(set_install_layout TYPE) + + if(${TYPE} MATCHES "STANDALONE") + + set(CMAKE_INSTALL_PREFIX "/usr/local/mariadb-maxscale" CACHE PATH "Prefix prepended to install directories.") + +# RPM and DEB are the same until differences are found + elseif(${TYPE} MATCHES "RPM") + + set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Prefix prepended to install directories.") + + elseif(${TYPE} MATCHES "DEB") + + set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Prefix prepended to install directories.") + + endif() + + set(MAXSCALE_MODULE_INSTALL lib64/maxscale CACHE PATH "Module installation path") + set(MAXSCALE_LIBRARY_INSTALL lib64/maxscale CACHE PATH "Library installation path") + set(MAXSCALE_EXECUTABLE_INSTALL bin CACHE PATH "Executable installation path") + set(MAXSCALE_SHARE_DIR share/maxscale CACHE PATH "Share file installation path, includes licence and readme files") + set(MAXSCALE_DOC_DIR ${MAXSCALE_SHARE_DIR}/doc CACHE PATH "Documentation installation path, text versions only") + set(MAXSCALE_CONFIG_DIR ${MAXSCALE_SHARE_DIR}/etc CACHE PATH "Configuration file installation path, example configurations will be placed here") +endfunction() diff --git a/macros.cmake b/cmake/macros.cmake similarity index 83% rename from macros.cmake rename to cmake/macros.cmake index d80202534..440c3fed5 100644 --- a/macros.cmake +++ b/cmake/macros.cmake @@ -74,34 +74,6 @@ macro(set_variables) # Build extra tools set(BUILD_TOOLS FALSE CACHE BOOL "Build extra utility tools") - # Change installation directories to standard locations for packages - if(PACKAGE) - set(MAXSCALE_MODULE_INSTALL /lib64/maxscale CACHE PATH "Module installation path") - set(MAXSCALE_LIBRARY_INSTALL /lib64/maxscale CACHE PATH "Library installation path") - message(STATUS "Installing MaxScale modules to: ${MAXSCALE_MODULE_INSTALL}/") - set(MAXSCALE_EXECUTABLE_INSTALL /bin CACHE PATH "Executable installation path") - message(STATUS "Installing MaxScale binaries to: ${MAXSCALE_EXECUTABLE_INSTALL}/") - set(MAXSCALE_CONFIG_DIR /etc CACHE PATH "Configuration file installation path") - set(MAXSCALE_DOC_DIR /usr/share/maxscale/doc CACHE PATH "Documentation installation path") - set(MAXSCALE_LOG_DIR /var/log/maxscale CACHE PATH "Log file directory") - message(STATUS "MaxScale log directory: ${MAXSCALE_LOG_DIR}/") - set(MAXSCALE_CACHE_DIR /var/cache/maxscale CACHE PATH "Service cache file directory") - set(MAXSCALE_LANG_DIR /var/cache/maxscale CACHE PATH "Language file directory(errmsg.sys)") - set(MAXSCALE_SHARE_DIR /usr/share/maxscale CACHE PATH "Share file installation path") - set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_MODULE_DIR}:${MAXSCALE_LIBRARY_DIR}) - else() - message(STATUS "Installing MaxScale to: ${CMAKE_INSTALL_PREFIX}/") - set(MAXSCALE_MODULE_INSTALL lib64/maxscale CACHE PATH "Module installation path") - set(MAXSCALE_LIBRARY_INSTALL lib64/maxscale CACHE PATH "Library installation path") - set(MAXSCALE_EXECUTABLE_INSTALL bin CACHE PATH "Executable installation path") - set(MAXSCALE_CONFIG_DIR etc CACHE PATH "Configuration file installation path") - set(MAXSCALE_DOC_DIR doc CACHE PATH "Documentation installation path") - set(MAXSCALE_LOG_DIR log CACHE PATH "Log file directory") - set(MAXSCALE_CACHE_DIR cache CACHE PATH "Service cache file directory") - set(MAXSCALE_LANG_DIR cache CACHE PATH "Log file directory") - set(MAXSCALE_SHARE_DIR . CACHE PATH "Share file installation path") - endif() - endmacro() macro(check_deps) diff --git a/etc/postinst.in b/etc/postinst.in index 4bd193958..46772ca16 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -1,5 +1,8 @@ #!/bin/sh +mkdir -p /var/log/maxscale +mkdir -p /var/cache/maxscale +mkdir -p /var/run/maxscale cp @CMAKE_INSTALL_PREFIX@/maxscale /etc/init.d/ cp @CMAKE_INSTALL_PREFIX@/maxscale.conf /etc/ld.so.conf.d/ /sbin/ldconfig diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 3ea1eb028..1936ebe84 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,5 +1,5 @@ -install(FILES nagios/check_maxscale_monitors.pl DESTINATION plugins/nagios) -install(FILES nagios/check_maxscale_resources.pl DESTINATION plugins/nagios) -install(FILES nagios/check_maxscale_threads.pl DESTINATION plugins/nagios) -install(FILES nagios/maxscale_commands.cfg DESTINATION plugins/nagios) -install(FILES nagios/server1.cfg DESTINATION plugins/nagios) +install(FILES nagios/check_maxscale_monitors.pl DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) +install(FILES nagios/check_maxscale_resources.pl DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) +install(FILES nagios/check_maxscale_threads.pl DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) +install(FILES nagios/maxscale_commands.cfg DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) +install(FILES nagios/server1.cfg DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) diff --git a/server/core/gateway.c b/server/core/gateway.c index d2bcd13a9..6b55b2661 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -1276,6 +1276,7 @@ int main(int argc, char **argv) { moduledir = tmp_path; } + break; case 'A': if(handle_path_arg(&tmp_path,optarg,NULL,true,true)) { @@ -1739,7 +1740,6 @@ int main(int argc, char **argv) if(cachedir == NULL) cachedir = strdup(default_cachedir); - if(langdir == NULL) langdir = strdup(default_langdir); if(moduledir == NULL) @@ -1780,11 +1780,13 @@ int main(int argc, char **argv) "Configuration file : %s\n" "Log directory : %s\n" "Data directory : %s\n" - "Module directory : %s\n\n", + "Module directory : %s\n" + "Service cache : %s\n\n", cnf_file_path, logdir, datadir, - moduledir); + moduledir, + cachedir); } LOGIF(LM, @@ -1806,6 +1808,10 @@ int main(int argc, char **argv) (skygw_log_write_flush(LOGFILE_MESSAGE, "Module directory: %s", moduledir))); + LOGIF(LM, + (skygw_log_write_flush(LOGFILE_MESSAGE, + "Service cache: %s", + cachedir))); /*< Update the server options */ for (i = 0; server_options[i]; i++) @@ -1882,7 +1888,7 @@ int main(int argc, char **argv) if (!config_load(cnf_file_path)) { char* fprerr = "Failed to load MaxScale configuration " - "file. Exiting."; + "file. Exiting. See the error log for details."; print_log_n_stderr(false, !daemon_mode, fprerr, fprerr, 0); LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, diff --git a/server/core/service.c b/server/core/service.c index 4584ded24..9455921b7 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -61,6 +61,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -112,7 +113,7 @@ SERVICE *service; return NULL; if ((service->router = load_module(router, MODULE_ROUTER)) == NULL) { - char* home = get_maxscale_home(); + char* home = get_moduledir(); char* ldpath = getenv("LD_LIBRARY_PATH"); LOGIF(LE, (skygw_log_write_flush( @@ -120,12 +121,13 @@ SERVICE *service; "Error : Unable to load %s module \"%s\".\n\t\t\t" " Ensure that lib%s.so exists in one of the " "following directories :\n\t\t\t " - "- %s/modules\n\t\t\t - %s", + "- %s/modules\n%s%s", MODULE_ROUTER, router, router, home, - ldpath))); + ldpath?"\t\t\t - ":"", + ldpath?ldpath:""))); free(service); return NULL; } From 10e9203b5be2cc2cb7d5bfade09259fb6a12e667 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 26 Apr 2015 11:39:00 +0300 Subject: [PATCH 04/34] Updated postinst script --- CMakeLists.txt | 9 +++++---- etc/postinst.in | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf7e135e7..78d205936 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,13 +175,14 @@ if(WITH_SCRIPTS) endif() if(PACKAGE) - install(FILES ${CMAKE_BINARY_DIR}/maxscale DESTINATION . + # Install the files copied by the postinst script into the share folder + install(FILES ${CMAKE_BINARY_DIR}/maxscale DESTINATION ${MAXSCALE_SHARE_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - install(FILES ${CMAKE_BINARY_DIR}/maxscale.conf DESTINATION . + install(FILES ${CMAKE_BINARY_DIR}/maxscale.conf DESTINATION ${MAXSCALE_SHARE_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - install(FILES ${CMAKE_BINARY_DIR}/postinst DESTINATION . + install(FILES ${CMAKE_BINARY_DIR}/postinst DESTINATION ${MAXSCALE_SHARE_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - install(FILES ${CMAKE_BINARY_DIR}/postrm DESTINATION . + install(FILES ${CMAKE_BINARY_DIR}/postrm DESTINATION ${MAXSCALE_SHARE_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) if(${CMAKE_VERSION} VERSION_LESS 2.8.12) message(WARNING "CMake version is ${CMAKE_VERSION}. Building of packages requires version 2.8.12 or greater.") diff --git a/etc/postinst.in b/etc/postinst.in index 46772ca16..c04850019 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -3,6 +3,6 @@ mkdir -p /var/log/maxscale mkdir -p /var/cache/maxscale mkdir -p /var/run/maxscale -cp @CMAKE_INSTALL_PREFIX@/maxscale /etc/init.d/ -cp @CMAKE_INSTALL_PREFIX@/maxscale.conf /etc/ld.so.conf.d/ +cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/maxscale /etc/init.d/ +cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/maxscale.conf /etc/ld.so.conf.d/ /sbin/ldconfig From 17a7b2addbebc2ac8d19b897e195014830b87431 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 26 Apr 2015 20:08:27 +0300 Subject: [PATCH 05/34] Updated more variables. --- CMakeLists.txt | 39 ++++++++++--------- client/CMakeLists.txt | 2 +- cmake/install_layout.cmake | 31 ++++++--------- log_manager/CMakeLists.txt | 2 +- plugins/CMakeLists.txt | 10 ++--- query_classifier/CMakeLists.txt | 2 +- server/core/CMakeLists.txt | 6 +-- server/core/gateway.c | 30 +++++++------- server/core/load_utils.c | 4 +- server/core/service.c | 2 +- server/include/gw.h | 4 +- server/modules/filter/CMakeLists.txt | 20 +++++----- server/modules/filter/hint/CMakeLists.txt | 4 +- server/modules/monitor/CMakeLists.txt | 8 ++-- server/modules/protocol/CMakeLists.txt | 12 +++--- server/modules/routing/CMakeLists.txt | 12 +++--- server/modules/routing/binlog/CMakeLists.txt | 4 +- server/modules/routing/maxinfo/CMakeLists.txt | 4 +- .../routing/readwritesplit/CMakeLists.txt | 2 +- 19 files changed, 95 insertions(+), 103 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78d205936..ba669131c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,23 +6,24 @@ endif() message(STATUS "CMake version: ${CMAKE_VERSION}") + include(${CMAKE_SOURCE_DIR}/cmake/macros.cmake) + +# Set the installation layout +set(INSTALL_LAYOUT "STANDALONE" CACHE STRING "Install layout, options are: STANDALONE, RPM, DEB") include(${CMAKE_SOURCE_DIR}/cmake/install_layout.cmake) + enable_testing() set_variables() set_maxscale_version() - -set(INSTALL_LAYOUT "STANDALONE" CACHE STRING "Install layout, options are: STANDALONE, RPM, DEB") -set_install_layout(${INSTALL_LAYOUT}) - set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") project(MaxScale) -#Disabled for now pending evaluation +#Do the platform check include(cmake/CheckPlatform.cmake) check_deps() @@ -40,7 +41,7 @@ if(NOT CURL_FOUND) message(FATAL_ERROR "Failed to locate dependency: libcurl") endif() -set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_MODULE_DIR}:${MAXSCALE_LIBRARY_DIR}) +set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/${MAXSCALE_LIBDIR}) # Make sure the release notes for this release are present if it is a stable one if(${MAXSCALE_VERSION} MATCHES "-stable") @@ -143,15 +144,15 @@ ${CMAKE_SOURCE_DIR}/Documentation/Upgrading-To-MaxScale-1.1.0.md ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt) -install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION ${MAXSCALE_SHARE_DIR}) -install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION ${MAXSCALE_SHARE_DIR}) -install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION ${MAXSCALE_SHARE_DIR}) -install(FILES server/MaxScale_template.cnf DESTINATION ${MAXSCALE_CONFIG_DIR}) -install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION ${MAXSCALE_CONFIG_DIR}) -install(FILES ${ERRMSG} DESTINATION ${MAXSCALE_SHARE_DIR}) -install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION ${MAXSCALE_SHARE_DIR}) -install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION ${MAXSCALE_SHARE_DIR}) -install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${MAXSCALE_SHARE_DIR}) +install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES server/MaxScale_template.cnf DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES ${ERRMSG} DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${MAXSCALE_SHAREDIR}) # Install startup scripts and ldconfig files if(WITH_SCRIPTS) @@ -176,13 +177,13 @@ endif() if(PACKAGE) # Install the files copied by the postinst script into the share folder - install(FILES ${CMAKE_BINARY_DIR}/maxscale DESTINATION ${MAXSCALE_SHARE_DIR} + install(FILES ${CMAKE_BINARY_DIR}/maxscale DESTINATION ${MAXSCALE_SHAREDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - install(FILES ${CMAKE_BINARY_DIR}/maxscale.conf DESTINATION ${MAXSCALE_SHARE_DIR} + install(FILES ${CMAKE_BINARY_DIR}/maxscale.conf DESTINATION ${MAXSCALE_SHAREDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - install(FILES ${CMAKE_BINARY_DIR}/postinst DESTINATION ${MAXSCALE_SHARE_DIR} + install(FILES ${CMAKE_BINARY_DIR}/postinst DESTINATION ${MAXSCALE_SHAREDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - install(FILES ${CMAKE_BINARY_DIR}/postrm DESTINATION ${MAXSCALE_SHARE_DIR} + install(FILES ${CMAKE_BINARY_DIR}/postrm DESTINATION ${MAXSCALE_SHAREDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) if(${CMAKE_VERSION} VERSION_LESS 2.8.12) message(WARNING "CMake version is ${CMAKE_VERSION}. Building of packages requires version 2.8.12 or greater.") diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 9b679aae0..32ab702ea 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -7,4 +7,4 @@ if(HIST) else() message(STATUS "Could not find editline library. MaxAdmin will be built without it.") endif() -install(TARGETS maxadmin DESTINATION ${MAXSCALE_EXECUTABLE_INSTALL}) +install(TARGETS maxadmin DESTINATION ${MAXSCALE_BINDIR}) diff --git a/cmake/install_layout.cmake b/cmake/install_layout.cmake index 0d594188f..821b2c474 100644 --- a/cmake/install_layout.cmake +++ b/cmake/install_layout.cmake @@ -3,27 +3,18 @@ # STANDALONE - Installs to /usr/local/mariadb-maxscale # RPM - Installs to /usr # DEB - Installs to /usr -function(set_install_layout TYPE) +if(${TYPE} MATCHES "STANDALONE") - if(${TYPE} MATCHES "STANDALONE") + set(CMAKE_INSTALL_PREFIX "/usr/local/mariadb-maxscale" CACHE PATH "Prefix prepended to install directories.") - set(CMAKE_INSTALL_PREFIX "/usr/local/mariadb-maxscale" CACHE PATH "Prefix prepended to install directories.") + # RPM and DEB are the same until differences are found +else() + set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Prefix prepended to install directories.") +endif() -# RPM and DEB are the same until differences are found - elseif(${TYPE} MATCHES "RPM") +set(MAXSCALE_LIBDIR lib64/maxscale CACHE PATH "Library installation path") +set(MAXSCALE_BINDIR bin CACHE PATH "Executable installation path") +set(MAXSCALE_SHAREDIR share/maxscale CACHE PATH "Share file installation path, includes licence and readme files") +set(MAXSCALE_DOCDIR share/doc/maxscale CACHE PATH "Documentation installation path, text versions only") +set(MAXSCALE_CONFDIR etc CACHE PATH "Configuration file installation path, this is not usually needed") - set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Prefix prepended to install directories.") - - elseif(${TYPE} MATCHES "DEB") - - set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Prefix prepended to install directories.") - - endif() - - set(MAXSCALE_MODULE_INSTALL lib64/maxscale CACHE PATH "Module installation path") - set(MAXSCALE_LIBRARY_INSTALL lib64/maxscale CACHE PATH "Library installation path") - set(MAXSCALE_EXECUTABLE_INSTALL bin CACHE PATH "Executable installation path") - set(MAXSCALE_SHARE_DIR share/maxscale CACHE PATH "Share file installation path, includes licence and readme files") - set(MAXSCALE_DOC_DIR ${MAXSCALE_SHARE_DIR}/doc CACHE PATH "Documentation installation path, text versions only") - set(MAXSCALE_CONFIG_DIR ${MAXSCALE_SHARE_DIR}/etc CACHE PATH "Configuration file installation path, example configurations will be placed here") -endfunction() diff --git a/log_manager/CMakeLists.txt b/log_manager/CMakeLists.txt index 607341d9a..3dfd883de 100644 --- a/log_manager/CMakeLists.txt +++ b/log_manager/CMakeLists.txt @@ -3,7 +3,7 @@ if(LOG_DEBUG) endif() add_library(log_manager SHARED log_manager.cc) target_link_libraries(log_manager pthread aio stdc++) -install(TARGETS log_manager DESTINATION ${MAXSCALE_LIBRARY_INSTALL}) +install(TARGETS log_manager DESTINATION ${MAXSCALE_LIBDIR}) if(BUILD_TESTS) add_subdirectory(test) endif() diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 1936ebe84..fc18cc602 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,5 +1,5 @@ -install(FILES nagios/check_maxscale_monitors.pl DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) -install(FILES nagios/check_maxscale_resources.pl DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) -install(FILES nagios/check_maxscale_threads.pl DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) -install(FILES nagios/maxscale_commands.cfg DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) -install(FILES nagios/server1.cfg DESTINATION ${MAXSCALE_SHARE_DIR}/plugins/nagios) +install(FILES nagios/check_maxscale_monitors.pl DESTINATION ${MAXSCALE_SHAREDIR}/plugins/nagios) +install(FILES nagios/check_maxscale_resources.pl DESTINATION ${MAXSCALE_SHAREDIR}/plugins/nagios) +install(FILES nagios/check_maxscale_threads.pl DESTINATION ${MAXSCALE_SHAREDIR}/plugins/nagios) +install(FILES nagios/maxscale_commands.cfg DESTINATION ${MAXSCALE_SHAREDIR}/plugins/nagios) +install(FILES nagios/server1.cfg DESTINATION ${MAXSCALE_SHAREDIR}/plugins/nagios) diff --git a/query_classifier/CMakeLists.txt b/query_classifier/CMakeLists.txt index 7fb36d6c6..19820ccdd 100644 --- a/query_classifier/CMakeLists.txt +++ b/query_classifier/CMakeLists.txt @@ -1,5 +1,5 @@ add_library(query_classifier SHARED query_classifier.cc) -install(TARGETS query_classifier COMPONENT lib DESTINATION ${MAXSCALE_LIBRARY_INSTALL}) +install(TARGETS query_classifier COMPONENT lib DESTINATION ${MAXSCALE_LIBDIR}) if(BUILD_TESTS) add_subdirectory(test) endif() diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index ee01396d8..ead8560d3 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -18,15 +18,15 @@ if(WITH_TCMALLOC) endif() target_link_libraries(maxscale ${EMBEDDED_LIB} ${PCRE_LINK_FLAGS} ${CURL_LIBRARIES} log_manager utils ssl aio pthread crypt dl crypto inih z rt m stdc++) -install(TARGETS maxscale DESTINATION ${MAXSCALE_EXECUTABLE_INSTALL}) +install(TARGETS maxscale DESTINATION ${MAXSCALE_BINDIR}) add_executable(maxkeys maxkeys.c secrets.c utils.c) target_link_libraries(maxkeys log_manager utils pthread crypt crypto) -install(TARGETS maxkeys DESTINATION ${MAXSCALE_EXECUTABLE_INSTALL}) +install(TARGETS maxkeys DESTINATION ${MAXSCALE_BINDIR}) add_executable(maxpasswd maxpasswd.c secrets.c utils.c) target_link_libraries(maxpasswd log_manager utils pthread crypt crypto) -install(TARGETS maxpasswd DESTINATION ${MAXSCALE_EXECUTABLE_INSTALL}) +install(TARGETS maxpasswd DESTINATION ${MAXSCALE_BINDIR}) if(BUILD_TESTS) add_subdirectory(test) diff --git a/server/core/gateway.c b/server/core/gateway.c index 6b55b2661..a4901ec23 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -131,7 +131,7 @@ static char pidfile[PATH_MAX+1] = ""; static char* configdir = NULL; static char* logdir = NULL; -static char* moduledir = NULL; +static char* libdir = NULL; static char* cachedir = NULL; static char* langdir = NULL; /** @@ -158,7 +158,7 @@ static struct option long_options[] = { {"logdir", required_argument, 0, 'L'}, {"datadir", required_argument, 0, 'D'}, {"configdir",required_argument, 0, 'C'}, - {"moduledir",required_argument, 0, 'B'}, + {"libdir",required_argument, 0, 'B'}, {"cachedir",required_argument, 0, 'A'}, {"language",required_argument, 0, 'N'}, {"syslog", required_argument, 0, 's'}, @@ -204,9 +204,9 @@ static char* check_dir_access(char* dirname,bool,bool); * Get the directory with all the modules. * @return The module directory */ -char* get_moduledir() +char* get_libdir() { - return moduledir; + return libdir; } /** * Handler for SIGHUP signal. Reload the configuration for the @@ -1029,7 +1029,7 @@ static void usage(void) " (default: /var/lib/maxscale)\n" " -C|--configdir=... path to configuration file directory\n" " (default: /etc/)\n" - " -B|--moduledir=... path to module directory\n" + " -B|--libdir=... path to module directory\n" " (default: /var/lib/maxscale)\n" " -A|--cachedir=... path to cache directory\n" " (default: /var/cache/maxscale)\n" @@ -1274,7 +1274,7 @@ int main(int argc, char **argv) case 'B': if(handle_path_arg(&tmp_path,optarg,NULL,true,false)) { - moduledir = tmp_path; + libdir = tmp_path; } break; case 'A': @@ -1742,8 +1742,8 @@ int main(int argc, char **argv) cachedir = strdup(default_cachedir); if(langdir == NULL) langdir = strdup(default_langdir); - if(moduledir == NULL) - moduledir = strdup(default_moduledir); + if(libdir == NULL) + libdir = strdup(default_libdir); /** * Set a data directory for the mysqld library, we use * a unique directory name to avoid clauses if multiple @@ -1785,7 +1785,7 @@ int main(int argc, char **argv) cnf_file_path, logdir, datadir, - moduledir, + libdir, cachedir); } @@ -1807,7 +1807,7 @@ int main(int argc, char **argv) LOGIF(LM, (skygw_log_write_flush(LOGFILE_MESSAGE, "Module directory: %s", - moduledir))); + libdir))); LOGIF(LM, (skygw_log_write_flush(LOGFILE_MESSAGE, "Service cache: %s", @@ -1882,8 +1882,8 @@ int main(int argc, char **argv) } libmysqld_started = TRUE; - if(moduledir == NULL) - moduledir = strdup(default_moduledir); + if(libdir == NULL) + libdir = strdup(default_libdir); if (!config_load(cnf_file_path)) { @@ -2179,10 +2179,10 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons if(logdir == NULL) handle_path_arg(&logdir,(char*)value,NULL,true,true); } - else if(strcmp(name, "moduledir") == 0) + else if(strcmp(name, "libdir") == 0) { - if(moduledir == NULL) - handle_path_arg(&moduledir,(char*)value,NULL,true,false); + if(libdir == NULL) + handle_path_arg(&libdir,(char*)value,NULL,true,false); } else if(strcmp(name, "datadir") == 0) { diff --git a/server/core/load_utils.c b/server/core/load_utils.c index c1ae57a3e..9451f6838 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -147,7 +147,7 @@ MODULE_INFO *mod_info = NULL; if (access(fname, F_OK) == -1) { - snprintf(fname, MAXPATHLEN+1,"%s/lib%s.so", get_moduledir(), module); + snprintf(fname, MAXPATHLEN+1,"%s/lib%s.so", get_libdir(), module); if (access(fname, F_OK) == -1) { @@ -155,7 +155,7 @@ MODULE_INFO *mod_info = NULL; LOGFILE_ERROR, "Error : Unable to find library for " "module: %s. Module dir: %s", - module, get_moduledir()))); + module, get_libdir()))); return NULL; } } diff --git a/server/core/service.c b/server/core/service.c index 9455921b7..bd22117ec 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -113,7 +113,7 @@ SERVICE *service; return NULL; if ((service->router = load_module(router, MODULE_ROUTER)) == NULL) { - char* home = get_moduledir(); + char* home = get_libdir(); char* ldpath = getenv("LD_LIBRARY_PATH"); LOGIF(LE, (skygw_log_write_flush( diff --git a/server/include/gw.h b/server/include/gw.h index 64db00204..e210fcfa2 100644 --- a/server/include/gw.h +++ b/server/include/gw.h @@ -25,7 +25,7 @@ static const char* default_cnf_fname = "MaxScale.cnf"; static const char* default_configdir = "/etc/"; static const char* default_logdir = "/var/log/maxscale/"; static const char* default_datadir = "/var/cache/maxscale/"; -static const char* default_moduledir = "/lib64/maxscale/"; +static const char* default_libdir = "/lib64/maxscale/"; static const char* default_cachedir = "/var/cache/maxscale/"; static const char* default_langdir = "/usr/share/mysql/english/"; /*< This is where the MariaDB * server installs errmsg.sys */ @@ -77,5 +77,5 @@ int gw_write(DCB *dcb, const void *buf, size_t nbytes); int gw_getsockerrno(int fd); int parse_bindconfig(char *, unsigned short, struct sockaddr_in *); int setipaddress(struct in_addr *, char *); -char* get_moduledir(); +char* get_libdir(); #endif diff --git a/server/modules/filter/CMakeLists.txt b/server/modules/filter/CMakeLists.txt index 77ebc7d0c..6bf6a5daa 100644 --- a/server/modules/filter/CMakeLists.txt +++ b/server/modules/filter/CMakeLists.txt @@ -3,48 +3,48 @@ if(BUILD_RABBITMQ) include_directories(${RABBITMQ_HEADERS}) add_library(mqfilter SHARED mqfilter.c) target_link_libraries(mqfilter query_classifier log_manager utils ${RABBITMQ_LIBRARIES}) - install(TARGETS mqfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) + install(TARGETS mqfilter DESTINATION ${MAXSCALE_LIBDIR}) endif() add_library(regexfilter SHARED regexfilter.c) target_link_libraries(regexfilter log_manager utils) -install(TARGETS regexfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS regexfilter DESTINATION ${MAXSCALE_LIBDIR}) add_library(testfilter SHARED testfilter.c) target_link_libraries(testfilter log_manager utils) -install(TARGETS testfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS testfilter DESTINATION ${MAXSCALE_LIBDIR}) add_library(qlafilter SHARED qlafilter.c) target_link_libraries(qlafilter log_manager utils) -install(TARGETS qlafilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS qlafilter DESTINATION ${MAXSCALE_LIBDIR}) add_library(tee SHARED tee.c) target_link_libraries(tee log_manager utils) -install(TARGETS tee DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS tee DESTINATION ${MAXSCALE_LIBDIR}) add_library(topfilter SHARED topfilter.c) target_link_libraries(topfilter log_manager utils) -install(TARGETS topfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS topfilter DESTINATION ${MAXSCALE_LIBDIR}) add_library(dbfwfilter SHARED dbfwfilter.c) target_link_libraries(dbfwfilter log_manager utils query_classifier) -install(TARGETS dbfwfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS dbfwfilter DESTINATION ${MAXSCALE_LIBDIR}) add_library(namedserverfilter SHARED namedserverfilter.c) target_link_libraries(namedserverfilter log_manager utils) -install(TARGETS namedserverfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS namedserverfilter DESTINATION ${MAXSCALE_LIBDIR}) if(BUILD_SLAVELAG) add_library(slavelag SHARED slavelag.c) target_link_libraries(slavelag log_manager utils query_classifier) - install(TARGETS slavelag DESTINATION ${MAXSCALE_MODULE_INSTALL}) + install(TARGETS slavelag DESTINATION ${MAXSCALE_LIBDIR}) endif() if(BUILD_TOOLS) add_executable(ruleparser dbfwfilter.c) target_compile_definitions(ruleparser PUBLIC "BUILD_RULE_PARSER") target_link_libraries(ruleparser ${EMBEDDED_LIB} log_manager utils query_classifier fullcore) - install(TARGETS ruleparser DESTINATION tools) + install(TARGETS ruleparser DESTINATION ${MAXSCALE_BINDIR}) endif() add_subdirectory(hint) diff --git a/server/modules/filter/hint/CMakeLists.txt b/server/modules/filter/hint/CMakeLists.txt index ecc3cbb85..c2d5e9ea1 100644 --- a/server/modules/filter/hint/CMakeLists.txt +++ b/server/modules/filter/hint/CMakeLists.txt @@ -1,4 +1,4 @@ add_library(hintfilter SHARED hintfilter.c hintparser.c) -set_target_properties(hintfilter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib) +set_target_properties(hintfilter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_LIBDIR}) target_link_libraries(hintfilter ssl log_manager utils) -install(TARGETS hintfilter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS hintfilter DESTINATION ${MAXSCALE_LIBDIR}) diff --git a/server/modules/monitor/CMakeLists.txt b/server/modules/monitor/CMakeLists.txt index 74a6f2870..b4d641934 100644 --- a/server/modules/monitor/CMakeLists.txt +++ b/server/modules/monitor/CMakeLists.txt @@ -1,16 +1,16 @@ add_library(mysqlmon SHARED mysql_mon.c) target_link_libraries(mysqlmon log_manager utils) -install(TARGETS mysqlmon DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS mysqlmon DESTINATION ${MAXSCALE_LIBDIR}) add_library(galeramon SHARED galera_mon.c) target_link_libraries(galeramon log_manager utils) -install(TARGETS galeramon DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS galeramon DESTINATION ${MAXSCALE_LIBDIR}) add_library(ndbclustermon SHARED ndbcluster_mon.c) target_link_libraries(ndbclustermon log_manager utils) -install(TARGETS ndbclustermon DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS ndbclustermon DESTINATION ${MAXSCALE_LIBDIR}) if(BUILD_MMMON) add_library(mmmon SHARED mm_mon.c) target_link_libraries(mmmon log_manager utils) - install(TARGETS mmmon DESTINATION ${MAXSCALE_MODULE_INSTALL}) + install(TARGETS mmmon DESTINATION ${MAXSCALE_LIBDIR}) endif() diff --git a/server/modules/protocol/CMakeLists.txt b/server/modules/protocol/CMakeLists.txt index 488f2e4b6..4ae3b8f2c 100644 --- a/server/modules/protocol/CMakeLists.txt +++ b/server/modules/protocol/CMakeLists.txt @@ -1,27 +1,27 @@ add_library(MySQLClient SHARED mysql_client.c mysql_common.c) target_link_libraries(MySQLClient log_manager utils) -install(TARGETS MySQLClient DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS MySQLClient DESTINATION ${MAXSCALE_LIBDIR}) add_library(MySQLBackend SHARED mysql_backend.c mysql_common.c) target_link_libraries(MySQLBackend log_manager utils) -install(TARGETS MySQLBackend DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS MySQLBackend DESTINATION ${MAXSCALE_LIBDIR}) add_library(telnetd SHARED telnetd.c) target_link_libraries(telnetd log_manager utils) -install(TARGETS telnetd DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS telnetd DESTINATION ${MAXSCALE_LIBDIR}) add_library(HTTPD SHARED httpd.c) target_link_libraries(HTTPD log_manager utils) -install(TARGETS HTTPD DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS HTTPD DESTINATION ${MAXSCALE_LIBDIR}) if(BUILD_TESTS) add_library(testprotocol SHARED testprotocol.c) - install(TARGETS testprotocol DESTINATION ${MAXSCALE_MODULE_INSTALL}) + install(TARGETS testprotocol DESTINATION ${MAXSCALE_LIBDIR}) endif() add_library(maxscaled SHARED maxscaled.c) target_link_libraries(maxscaled log_manager utils) -install(TARGETS maxscaled DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS maxscaled DESTINATION ${MAXSCALE_LIBDIR}) diff --git a/server/modules/routing/CMakeLists.txt b/server/modules/routing/CMakeLists.txt index b73edfa8c..2933e5ec8 100644 --- a/server/modules/routing/CMakeLists.txt +++ b/server/modules/routing/CMakeLists.txt @@ -2,28 +2,28 @@ if(BUILD_TESTS) add_subdirectory(test) add_library(testroute SHARED testroute.c) target_link_libraries(testroute log_manager utils) - install(TARGETS testroute DESTINATION ${MAXSCALE_MODULE_INSTALL}) + install(TARGETS testroute DESTINATION ${MAXSCALE_LIBDIR}) endif() add_library(schemarouter SHARED schemarouter/schemarouter.c) target_link_libraries(schemarouter log_manager utils query_classifier) -install(TARGETS schemarouter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS schemarouter DESTINATION ${MAXSCALE_LIBDIR}) add_library(shardrouter SHARED schemarouter/shardrouter.c) target_link_libraries(shardrouter log_manager utils query_classifier) -install(TARGETS shardrouter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS shardrouter DESTINATION ${MAXSCALE_LIBDIR}) add_library(readconnroute SHARED readconnroute.c) target_link_libraries(readconnroute log_manager utils) -install(TARGETS readconnroute DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS readconnroute DESTINATION ${MAXSCALE_LIBDIR}) add_library(debugcli SHARED debugcli.c debugcmd.c) target_link_libraries(debugcli log_manager utils) -install(TARGETS debugcli DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS debugcli DESTINATION ${MAXSCALE_LIBDIR}) add_library(cli SHARED cli.c debugcmd.c) target_link_libraries(cli log_manager utils) -install(TARGETS cli DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS cli DESTINATION ${MAXSCALE_LIBDIR}) add_subdirectory(readwritesplit) add_subdirectory(schemarouter/test) diff --git a/server/modules/routing/binlog/CMakeLists.txt b/server/modules/routing/binlog/CMakeLists.txt index 9fcd8536e..9a0c245de 100644 --- a/server/modules/routing/binlog/CMakeLists.txt +++ b/server/modules/routing/binlog/CMakeLists.txt @@ -1,4 +1,4 @@ add_library(binlogrouter SHARED blr.c blr_master.c blr_cache.c blr_slave.c blr_file.c) -set_target_properties(binlogrouter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_MODULE_INSTALL}:${MAXSCALE_LIBRARY_INSTALL}) +set_target_properties(binlogrouter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_LIBDIR}) target_link_libraries(binlogrouter ssl pthread log_manager) -install(TARGETS binlogrouter DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS binlogrouter DESTINATION ${MAXSCALE_LIBDIR}) diff --git a/server/modules/routing/maxinfo/CMakeLists.txt b/server/modules/routing/maxinfo/CMakeLists.txt index 2585f2a2a..8e07a34a7 100644 --- a/server/modules/routing/maxinfo/CMakeLists.txt +++ b/server/modules/routing/maxinfo/CMakeLists.txt @@ -1,4 +1,4 @@ add_library(maxinfo SHARED maxinfo.c maxinfo_parse.c maxinfo_error.c maxinfo_exec.c) -set_target_properties(maxinfo PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_MODULE_INSTALL}:MAXSCALE_LIBRARY_INSTALL) +set_target_properties(maxinfo PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${MAXSCALE_LIBDIR}) target_link_libraries(maxinfo pthread log_manager) -install(TARGETS maxinfo DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS maxinfo DESTINATION ${MAXSCALE_LIBDIR}) diff --git a/server/modules/routing/readwritesplit/CMakeLists.txt b/server/modules/routing/readwritesplit/CMakeLists.txt index fe56582dc..c7e387290 100644 --- a/server/modules/routing/readwritesplit/CMakeLists.txt +++ b/server/modules/routing/readwritesplit/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(readwritesplit SHARED readwritesplit.c) target_link_libraries(readwritesplit ssl pthread log_manager utils query_classifier) -install(TARGETS readwritesplit DESTINATION ${MAXSCALE_MODULE_INSTALL}) +install(TARGETS readwritesplit DESTINATION ${MAXSCALE_LIBDIR}) if(BUILD_TESTS) add_subdirectory(test) endif() From c500d23d04b2566d6acecc4b6ee777540752b1f0 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 04:48:50 +0300 Subject: [PATCH 06/34] Moved default file search paths to gwdirs.h which is configured by CMake from gwdirs.h.in. --- CMakeLists.txt | 21 +-- Documentation/About/SETUP.md | 32 ++--- .../Getting-Started/Configuration-Guide.md | 8 +- .../Getting-Started-With-MaxScale.md | 6 +- .../Tutorials/Administration-Tutorial.md | 4 +- ...era-Cluster-Connection-Routing-Tutorial.md | 2 +- ...a-Cluster-Read-Write-Splitting-Tutorial.md | 2 +- .../Tutorials/MaxScale-Information-Schema.md | 53 +++++++- ...Replication-Connection-Routing-Tutorial.md | 121 +++++++----------- ...plication-Read-Write-Splitting-Tutorial.md | 2 +- ...eplication-Proxy-Binlog-Router-Tutorial.md | 2 +- Documentation/filters/Query-Log-All-Filter.md | 2 +- Documentation/filters/RabbitMQ-Filter.md | 2 +- Documentation/filters/Regex-Filter.md | 2 +- Documentation/filters/Tee-Filter.md | 2 +- Documentation/filters/Top-N-Filter.md | 2 +- cmake/install_layout.cmake | 20 +-- server/core/gateway.c | 71 +--------- server/include/gw.h | 32 +++-- server/include/gwdirs.h.in | 33 +++++ 20 files changed, 198 insertions(+), 221 deletions(-) create mode 100644 server/include/gwdirs.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ba669131c..564cb43a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,23 +6,28 @@ endif() message(STATUS "CMake version: ${CMAKE_VERSION}") - include(${CMAKE_SOURCE_DIR}/cmake/macros.cmake) - -# Set the installation layout -set(INSTALL_LAYOUT "STANDALONE" CACHE STRING "Install layout, options are: STANDALONE, RPM, DEB") -include(${CMAKE_SOURCE_DIR}/cmake/install_layout.cmake) - enable_testing() + +set(INSTALL_LAYOUT "STANDALONE" CACHE STRING "Install layout, options are: STANDALONE, RPM, DEB") +if(${INSTALL_LAYOUT} MATCHES "STANDALONE") + set(CMAKE_INSTALL_PREFIX "/usr/local/mariadb-maxscale" CACHE PATH "Prefix prepended to install directories.") +else() + set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Prefix prepended to install directories.") +endif() + +# Set default values for cache entries and set the MaxScale version set_variables() set_maxscale_version() set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") project(MaxScale) +# Set the installation layout +include(${CMAKE_SOURCE_DIR}/cmake/install_layout.cmake) + #Do the platform check include(cmake/CheckPlatform.cmake) @@ -51,10 +56,10 @@ if(${MAXSCALE_VERSION} MATCHES "-stable") message(FATAL_ERROR "Could not find the release notes for this stable release: ${MAXSCALE_VERSION_NUMERIC}") endif() endif() -set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/${MAXSCALE_MODULE_INSTALL}:${CMAKE_INSTALL_PREFIX}/${MAXSCALE_LIBRARY_INSTALL}) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/server/include) configure_file(${CMAKE_SOURCE_DIR}/server/include/version.h.in ${CMAKE_BINARY_DIR}/server/include/version.h) +configure_file(${CMAKE_SOURCE_DIR}/server/include/gwdirs.h.in ${CMAKE_BINARY_DIR}/server/include/gwdirs.h) configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.h.in ${CMAKE_BINARY_DIR}/server/include/maxscale_test.h) configure_file(${CMAKE_SOURCE_DIR}/etc/postinst.in ${CMAKE_BINARY_DIR}/postinst) configure_file(${CMAKE_SOURCE_DIR}/etc/postrm.in ${CMAKE_BINARY_DIR}/postrm) diff --git a/Documentation/About/SETUP.md b/Documentation/About/SETUP.md index 2be316a4d..9cb5dd11b 100644 --- a/Documentation/About/SETUP.md +++ b/Documentation/About/SETUP.md @@ -1,37 +1,25 @@ Installation and startup Untar the binary distribution in the desired location, -e.g. /usr/local/mariadb +e.g. /usr/local/mariadb-maxscale Alternatively build from the source code using the instructions -in the README file and execute make install. +in the [Building MaxScale from Source Code](../Getting-Started/Building-MaxScale-from-Source-Code.md) document. -Simply set the environment variable MAXSCALE_HOME to point to the -MaxScale directory, found inside the path into which the files have been copied, -e.g. MAXSCALE_HOME=/usr/local/mariadb-maxscale - -Also you will need to optionally set LD_LIBRARY_PATH to include the 'lib' folder, -found inside the path into which the files have been copied, -e.g. LD_LIBRARY_PATH=/usr/local/mariadb-maxscale/lib - -Because we need the libmysqld library for parsing we must create a -valid my.cnf file to enable the library to be used. Copy the my.cnf -to $MAXSCALE_HOME/mysql/my.cnf. - -To start MaxScale execute the command 'maxscale' from the bin folder, -e.g. /usr/local/mariadb-maxscale/bin/maxscale +You can start MaxScale using `service maxscale start` or `systemctl start maxscale` if you installed the init.d scripts +or by manually starting the process from the bin folder of the installation directory. Configuration -You need to edit the file MaxScale.cnf in $MAXSCALE_HOME/etc, you should -define the set of server definitions you require, with the addresses -and ports of those servers. Also define the listening ports for your -various services. +You need to create or edit the MaxScale.cnf file in the /etc folder. +Define the services you wish to provide, the set of server definitions +you require, with the addresses and ports of those servers and also +define the listening ports for your various services. -In order to view the internal activity of the gateway you can telnet to +In order to view the internal activity of MaxScale you can either use +the maxadmin client interface with the cli routing module or telnet to the port defined for the telnet listener. Initially you may login with the user name of "admin" and the password "mariadb". Once connected type help for an overview of the commands and help for the more detailed help on commands. Use the add user command to add a new user, this will also remove the admin/mariadb user. - diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index 5ce081a82..81d3c90e2 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -27,11 +27,9 @@ connection failover| When a connection currently being used between MaxScale and The MaxScale configuration is read from a file which can be located in a number of placing, MaxScale will search for the configuration file in a number of locations. -1. If the environment variable `MAXSCALE_HOME` is set then MaxScale will look for a configuration file called `MaxScale.cnf` in the directory `$MAXSCALE_HOME/etc`. +1. Location given with the --configdir= command line argument -2. If `MAXSCALE_HOME` is not set or the configuration file is not in the location above MaxScale will look for a file in `/etc/MaxScale.cnf`. - -Alternatively MaxScale can be started with the `-c` flag and the path of the MaxScale home directory tree. +2. MaxScale will look for a configuration file called `MaxScale.cnf` in the directory `/etc/MaxScale.cnf` An explicit path to a configuration file can be passed by using the `-f` option to MaxScale. @@ -524,7 +522,7 @@ Default value is `2`. Write Timeout is the timeout in seconds for each attempt t ## Protocol Modules -The protocols supported by MaxScale are implemented as external modules that are loaded dynamically into the MaxScale core. These modules reside in the directory `$MAXSCALE_HOME/modules`, if the environment variable `$MAXSCALE_HOME` is not set it defaults to `/usr/local/mariadb-maxscale`. It may also be set by passing the `-c` option on the MaxScale command line. +The protocols supported by MaxScale are implemented as external modules that are loaded dynamically into the MaxScale core. These modules reside in the directory `/usr/lib64/maxscale`. The location can be overridden with the `libdir=PATH` parameter under the `[maxscale]` section. It may also be set by passing the `-B PATH` or `--libdir=PATH` option on the MaxScale command line. ### MySQLClient diff --git a/Documentation/Getting-Started/Getting-Started-With-MaxScale.md b/Documentation/Getting-Started/Getting-Started-With-MaxScale.md index 24ee54b22..6b84d8d58 100644 --- a/Documentation/Getting-Started/Getting-Started-With-MaxScale.md +++ b/Documentation/Getting-Started/Getting-Started-With-MaxScale.md @@ -62,11 +62,9 @@ shared objects that are loaded on demand. In order for MaxScale to find these modules it will search using a predescribed search path. The rules are: 1. Look in the current directory for the module - 2. Look in $MAXSCALE_HOME/modules - 3. Look in /usr/local/mariadb-maxscale/modules - -Configuration is read by default from the file $MAXSCALE_HOME/etc/MaxScale.cnf, /etc/MaxScale.cnf. An example file is included in in the installation and can be found in the etc/ folder within the MaxScale installation. The default value of MAXSCALE_HOME can be overridden by using the -c flag on the command line. This should be immediately followed by the path to the MaxScale home directory. The -f flag can be used on the command line to set the name and the location of the configuration file. Without path expression the file is read from \$MAXSCALE_HOME/etc directory. + 2. Look in /usr/lib64/maxscale +Configuration is read by default from the file /etc/MaxScale.cnf. An example file is included in in the installation and can be found in the /usr/share/maxscale folder within the MaxScale installation. The -f flag can be used on the command line to set the name and the location of the configuration file. Without path expression the file is read from the /etc directory. ## Administration Of MaxScale diff --git a/Documentation/Tutorials/Administration-Tutorial.md b/Documentation/Tutorials/Administration-Tutorial.md index 929850eb5..894f89f94 100644 --- a/Documentation/Tutorials/Administration-Tutorial.md +++ b/Documentation/Tutorials/Administration-Tutorial.md @@ -45,7 +45,7 @@ Options may be passed to the MaxScale binary that alter this default behavior, t -f --config= - Use the filename passed as an argument instead of looking in $MAXSCALE_HOME/etc/MaxScale.cnf + Use the filename passed as an argument instead of looking in /etc/MaxScale.cnf -l| @@ -79,7 +79,7 @@ or MaxScale will also stop gracefully if it received a hangup signal, to find the process id of the MaxScale server use the ps command or read the contents of the maxscale.pid file located in the same directory as the logs. - $ kill -HUP `cat $MAXSCALE_HOME/log/maxscale.pid` + $ kill -HUP `cat /log/maxscale.pid` In order to shutdown MaxScale using the maxadmin command you may either connect with maxadmin in interactive mode or pass the "shutdown maxscale" command you wish to execute as an argument to maxadmin. diff --git a/Documentation/Tutorials/Galera-Cluster-Connection-Routing-Tutorial.md b/Documentation/Tutorials/Galera-Cluster-Connection-Routing-Tutorial.md index d75c6162a..d58ebc32c 100644 --- a/Documentation/Tutorials/Galera-Cluster-Connection-Routing-Tutorial.md +++ b/Documentation/Tutorials/Galera-Cluster-Connection-Routing-Tutorial.md @@ -60,7 +60,7 @@ If you wish to use two different usernames for the two different roles of monito ### Creating Your MaxScale Configuration -MaxScale configuration is held in an ini file that is located in the file MaxScale.cnf in the directory $MAXSCALE_HOME/etc, if you have installed in the default location then this file is available in /usr/local/mariadb-maxscale/etc/MaxScale.cnf. This is not created as part of the installation process and must be manually created. A template file does exist within this directory that may be use as a basis for your configuration. +MaxScale configuration is held in an ini file that is located in the file MaxScale.cnf in the directory /etc, if you have installed in the default location then this file is available in /usr/local/mariadb-maxscale/etc/MaxScale.cnf. This is not created as part of the installation process and must be manually created. A template file does exist within this directory that may be use as a basis for your configuration. A global, maxscale, section is included within every MaxScale configuration file; this is used to set the values of various MaxScale wide parameters, perhaps the most important of these is the number of threads that MaxScale will use to execute the code that forwards requests and handles responses for clients. diff --git a/Documentation/Tutorials/Galera-Cluster-Read-Write-Splitting-Tutorial.md b/Documentation/Tutorials/Galera-Cluster-Read-Write-Splitting-Tutorial.md index df57e9390..8717591d8 100644 --- a/Documentation/Tutorials/Galera-Cluster-Read-Write-Splitting-Tutorial.md +++ b/Documentation/Tutorials/Galera-Cluster-Read-Write-Splitting-Tutorial.md @@ -62,7 +62,7 @@ If you wish to use two different usernames for the two different roles of monito ### Creating Your MaxScale Configuration -MaxScale configuration is held in an ini file that is located in the file MaxScale.cnf in the directory $MAXSCALE_HOME/etc, if you have installed in the default location then this file is available in /usr/local/mariadb-maxscale/etc/MaxScale.cnf. This is not created as part of the installation process and must be manually created. A template file does exist within this directory that may be use as a basis for your configuration. +MaxScale configuration is held in an ini file that is located in the file MaxScale.cnf in the directory /etc, if you have installed in the default location then this file is available in /usr/local/mariadb-maxscale/etc/MaxScale.cnf. This is not created as part of the installation process and must be manually created. A template file does exist within this directory that may be use as a basis for your configuration. A global, maxscale, section is included within every MaxScale configuration file; this is used to set the values of various MaxScale wide parameters, perhaps the most important of these is the number of threads that MaxScale will use to execute the code that forwards requests and handles responses for clients. diff --git a/Documentation/Tutorials/MaxScale-Information-Schema.md b/Documentation/Tutorials/MaxScale-Information-Schema.md index c8ce5c08a..9872556b3 100644 --- a/Documentation/Tutorials/MaxScale-Information-Schema.md +++ b/Documentation/Tutorials/MaxScale-Information-Schema.md @@ -11,48 +11,59 @@ The service entry needs to define the service name, the type as service and the The specified user, with the password (plain or encrypted via maxpassword utility) is allowed to connect via MySQL protocol. Currently the user can connect to maxinfo from any remote IP and to localhost as well. +``` [MaxInfo] type=service router=maxinfo user=monitor passwd=EBD2F49C3B375812A8CDEBA632ED8BBC +``` The listener section defines the protocol, port and other information needed to create a listener for the service. To listen on a port using the MySQL protocol a section as shown below should be added to the configuration file. +``` [MaxInfo Listener] type=listener service=MaxInfo protocol=MySQLClient port=9003 +``` To listen with the HTTP protocol and hence return JSON documents a section as should below is required. +``` [MaxInfo JSON Listener] type=listener service=MaxInfo protocol=HTTPD port=8003 +``` + If both the MySQL and JSON responses are required then a single service can be configured with both types of listener. As with any other listeners within MaxScale the listeners can be bound to a particular interface by use of the address= parameter. This allows the access to the maxinfo data to be limited to the localhost by adding an address=localhost parameter in the configuration file. +``` [MaxInfo Listener] type=listener service=MaxInfo protocol=MySQLClient address=localhost port=9003 +``` # MySQL Interface to maxinfo The maxinfo supports a small subset of SQL statements in addition to the MySQL status and ping requests. These may be used for simple monitoring of MaxScale. +``` % mysqladmin -hmaxscale.mariadb.com -P9003 -umonitor -pxyz ping mysqld is alive % mysqladmin -hmaxscale.mariadb.com -P9003 -umonitor -pxyz status Uptime: 72 Threads: 1 Sessions: 11 % +``` The SQL command used to interact with maxinfo is the show command, a variety of show commands are available and will be described in the following sections. @@ -60,6 +71,7 @@ The SQL command used to interact with maxinfo is the show command, a variety of The show variables command will display a set of name and value pairs for a number of MaxScale system variables. +``` mysql> show variables; +--------------------+-------------------------+ | Variable_name | Value | @@ -77,9 +89,11 @@ The show variables command will display a set of name and value pairs for a numb 9 rows in set (0.02 sec) mysql> +``` The show variables command can also accept a limited like clause. This like clause must either be a literal string to match, a pattern starting with a %, a pattern ending with a % or a string with a % at both the start and the end. +``` mysql> show variables like 'version'; +---------------+----------------+ | Variable_name | Value | @@ -116,11 +130,13 @@ The show variables command can also accept a limited like clause. This like clau 3 rows in set (0.02 sec) mysql> +``` ## Show status The show status command displays a set of status counters, as with show variables the show status command can be passed a simplified like clause to limit the values returned. +``` mysql> show status; +---------------------------+-------+ | Variable_name | Value | @@ -151,11 +167,13 @@ The show status command displays a set of status counters, as with show variable 22 rows in set (0.02 sec) mysql> +``` ## Show services The show services command will return a set of basic statistics regarding each of the configured services within MaxScale. +``` mysql> show services; +----------------+----------------+--------------+----------------+ | Service Name | Router Module | No. Sessions | Total Sessions | @@ -172,6 +190,7 @@ The show services command will return a set of basic statistics regarding each o 8 rows in set (0.02 sec) mysql> +``` The show services command does not accept a like clause and will ignore any like clause that is given. @@ -179,6 +198,7 @@ The show services command does not accept a like clause and will ignore any like The show listeners command will return a set of status information for every listener defined within the MaxScale configuration file. +``` mysql> show listeners; +----------------+-----------------+-----------+------+---------+ | Service Name | Protocol Module | Address | Port | State | @@ -196,6 +216,7 @@ The show listeners command will return a set of status information for every lis 9 rows in set (0.02 sec) mysql> +``` The show listeners command will ignore any like clause passed to it. @@ -203,6 +224,7 @@ The show listeners command will ignore any like clause passed to it. The show sessions command returns information on every active session within MaxScale. It will ignore any like clause passed to it. +``` mysql> show sessions; +-----------+---------------+----------------+---------------------------+ | Session | Client | Service | State | @@ -222,11 +244,13 @@ The show sessions command returns information on every active session within Max 11 rows in set (0.02 sec) mysql> +``` ## Show clients The show clients command reports a row for every client application connected to MaxScale. Like clauses are not available of the show clients command. +``` mysql> show clients; +-----------+---------------+---------+---------------------------+ | Session | Client | Service | State | @@ -237,11 +261,13 @@ The show clients command reports a row for every client application connected to 2 rows in set (0.02 sec) mysql> +``` ## Show servers The show servers command returns data for each backend server configured within the MaxScale configuration file. This data includes the current number of connections MaxScale has to that server and the state of that server as monitored by MaxScale. +``` mysql> show servers; +---------+-----------+------+-------------+---------+ | Server | Address | Port | Connections | Status | @@ -254,11 +280,13 @@ The show servers command returns data for each backend server configured within 4 rows in set (0.02 sec) mysql> +``` ## Show modules The show modules command reports the information on the modules currently loaded into MaxScale. This includes the name type and version of each module. It also includes the API version the module has been written against and the current release status of the module. +``` mysql> show modules; +----------------+-------------+---------+-------------+----------------+ | Module Name | Module Type | Version | API Version | Status | @@ -277,12 +305,13 @@ The show modules command reports the information on the modules currently loaded 10 rows in set (0.02 sec) mysql> - +``` ## Show monitors The show monitors command reports each monitor configured within the system and the state of that monitor. +``` mysql> show monitors; +---------------+---------+ | Monitor | Status | @@ -292,12 +321,13 @@ The show monitors command reports each monitor configured within the system and 1 row in set (0.02 sec) mysql> - +``` ## Show eventTimes The show eventTimes command returns a table of statistics that reflect the performance of the event queuing and execution portion of the MaxScale core. +``` mysql> show eventTimes; +---------------+-------------------+---------------------+ | Duration | No. Events Queued | No. Events Executed | @@ -336,6 +366,7 @@ The show eventTimes command returns a table of statistics that reflect the perfo 30 rows in set (0.02 sec) mysql> +``` Each row represents a time interval, in 100ms increments, with the counts representing the number of events that were in the event queue for the length of time that row represents and the number of events that were executing of the time indicated by the row. @@ -347,6 +378,7 @@ The simplified JSON interface takes the URL of the request made to maxinfo and m The /variables URL will return the MaxScale variables, these variables can not be filtered via this interface. +``` $ curl http://maxscale.mariadb.com:8003/variables [ { "Variable_name" : "version", "Value" : "1.0.6-unstable"}, { "Variable_name" : "version_comment", "Value" : "MariaDB MaxScale"}, @@ -358,11 +390,13 @@ The /variables URL will return the MaxScale variables, these variables can not b { "Variable_name" : "MAXSCALE_UPTIME", "Value" : 3948}, { "Variable_name" : "MAXSCALE_SESSIONS", "Value" : 12}] $ +``` ## Status Use of the /status URI will return the status information that would normally be returned by the show status command. No filtering of the status information is available via this interface +``` $ curl http://maxscale.mariadb.com:8003/status [ { "Variable_name" : "Uptime", "Value" : 3831}, { "Variable_name" : "Uptime_since_flush_status", "Value" : 3831}, @@ -387,11 +421,13 @@ Use of the /status URI will return the status information that would normally be { "Variable_name" : "Max_event_queue_time", "Value" : 0}, { "Variable_name" : "Max_event_execution_time", "Value" : 1}] $ +``` ## Services The /services URI returns the data regarding the services defined within the configuration of MaxScale. Two counters are returned, the current number of sessions attached to this service and the total number connected since the service started. +``` $ curl http://maxscale.mariadb.com:8003/services [ { "Service Name" : "Test Service", "Router Module" : "readconnroute", "No. Sessions" : 1, "Total Sessions" : 1}, { "Service Name" : "Split Service", "Router Module" : "readwritesplit", "No. Sessions" : 1, "Total Sessions" : 1}, @@ -402,11 +438,13 @@ The /services URI returns the data regarding the services defined within the con { "Service Name" : "CLI", "Router Module" : "cli", "No. Sessions" : 1, "Total Sessions" : 1}, { "Service Name" : "MaxInfo", "Router Module" : "maxinfo", "No. Sessions" : 5, "Total Sessions" : 20}] $ +``` ## Listeners The /listeners URI will return a JSON array with one entry per listener, each entry is a JSON object that describes the configuration and state of that listener. +``` $ curl http://maxscale.mariadb.com:8003/listeners [ { "Service Name" : "Test Service", "Protocol Module" : "MySQLClient", "Address" : "*", "Port" : 4006, "State" : "Running"}, { "Service Name" : "Split Service", "Protocol Module" : "MySQLClient", "Address" : "*", "Port" : 4007, "State" : "Running"}, @@ -418,11 +456,13 @@ The /listeners URI will return a JSON array with one entry per listener, each en { "Service Name" : "MaxInfo", "Protocol Module" : "MySQLClient", "Address" : "*", "Port" : 9003, "State" : "Running"}, { "Service Name" : "MaxInfo", "Protocol Module" : "HTTPD", "Address" : "*", "Port" : 8003, "State" : "Running"}] $ +``` ## Modules The /modules URI returns data for each plugin that has been loaded into MaxScale. The plugin name, type and version are returned as is the version of the plugin API that the plugin was built against and the release status of the plugin. +``` $ curl http://maxscale.mariadb.com:8003/modules [ { "Module Name" : "HTTPD", "Module Type" : "Protocol", "Version" : "V1.0.1", "API Version" : "1.0.0", "Status" : "In Development"}, { "Module Name" : "maxscaled", "Module Type" : "Protocol", "Version" : "V1.0.0", "API Version" : "1.0.0", "Status" : "GA"}, @@ -435,11 +475,13 @@ The /modules URI returns data for each plugin that has been loaded into MaxScale { "Module Name" : "cli", "Module Type" : "Router", "Version" : "V1.0.0", "API Version" : "1.0.0", "Status" : "GA"}, { "Module Name" : "maxinfo", "Module Type" : "Router", "Version" : "V1.0.0", "API Version" : "1.0.0", "Status" : "Alpha"}] $ +``` ## Sessions The /sessions URI returns a JSON array with an object for each active session within MaxScale. +``` $ curl http://maxscale.mariadb.com:8003/sessions [ { "Session" : "0x1a8e9a0", "Client" : "80.176.79.245", "Service" : "MaxInfo", "State" : "Session ready for routing"}, { "Session" : "0x1a8e6d0", "Client" : "80.240.130.35", "Service" : "MaxInfo", "State" : "Session ready for routing"}, @@ -453,32 +495,38 @@ The /sessions URI returns a JSON array with an object for each active session wi { "Session" : "0x1a5c530", "Client" : , "Service" : "Split Service", "State" : "Listener Session"}, { "Session" : "0x19ac1c0", "Client" : , "Service" : "Test Service", "State" : "Listener Session"}] $ +``` ## Clients The /clients URI is a limited version of the /sessions, in this case it only returns an entry for a session that represents a client connection. +``` $ curl http://maxscale.mariadb.com:8003/clients [ { "Session" : "0x1a90be0", "Client" : "80.176.79.245", "Service" : "MaxInfo", "State" : "Session ready for routing"}, { "Session" : "0x1a8e9a0", "Client" : "127.0.0.1", "Service" : "MaxInfo", "State" : "Session ready for routing"}, { "Session" : "0x1a8e6d0", "Client" : "80.240.130.35", "Service" : "MaxInfo", "State" : "Session ready for routing"}] $ +``` ## Servers The /servers URI is used to retrieve information for each of the servers defined within the MaxScale configuration. This information includes the connection count and the current status as monitored by MaxScale. The connection count is only those connections made by MaxScale to those servers. +``` $ curl http://maxscale.mariadb.com:8003/servers [ { "Server" : "server1", "Address" : "127.0.0.1", "Port" : 3306, "Connections" : 0, "Status" : "Running"}, { "Server" : "server2", "Address" : "127.0.0.1", "Port" : 3307, "Connections" : 0, "Status" : "Down"}, { "Server" : "server3", "Address" : "127.0.0.1", "Port" : 3308, "Connections" : 0, "Status" : "Down"}, { "Server" : "server4", "Address" : "127.0.0.1", "Port" : 3309, "Connections" : 0, "Status" : "Down"}] $ +``` ## Event Times The /event/times URI returns an array of statistics that reflect the performance of the event queuing and execution portion of the MaxScale core. Each element is an object that represents a time bucket, in 100ms increments, with the counts representing the number of events that were in the event queue for the length of time that row represents and the number of events that were executing of the time indicated by the object. +``` $ curl http://maxscale.mariadb.com:8003/event/times [ { "Duration" : "< 100ms", "No. Events Queued" : 64, "No. Events Executed" : 63}, { "Duration" : " 100 - 200ms", "No. Events Queued" : 0, "No. Events Executed" : 0}, @@ -510,3 +558,4 @@ The /event/times URI returns an array of statistics that reflect the performance { "Duration" : "2700 - 2800ms", "No. Events Queued" : 0, "No. Events Executed" : 0}, { "Duration" : "2800 - 2900ms", "No. Events Queued" : 0, "No. Events Executed" : 0}, { "Duration" : "> 3000ms", "No. Events Queued" : 0, "No. Events Executed" : 0}] +``` diff --git a/Documentation/Tutorials/MySQL-Replication-Connection-Routing-Tutorial.md b/Documentation/Tutorials/MySQL-Replication-Connection-Routing-Tutorial.md index aac084f7b..8158bfa76 100644 --- a/Documentation/Tutorials/MySQL-Replication-Connection-Routing-Tutorial.md +++ b/Documentation/Tutorials/MySQL-Replication-Connection-Routing-Tutorial.md @@ -36,6 +36,7 @@ The first user required must be able to select data from the table mysql.user, t 2. Create the user, substituting the username, password and host on which maxscale runs within your environment +``` MariaDB [(none)]> create user '*username*'@'*maxscalehost*' identified by '*password*'; **Query OK, 0 rows affected (0.00 sec)** @@ -45,9 +46,11 @@ MariaDB [(none)]> create user '*username*'@'*maxscalehost*' identified by '*pass MariaDB [(none)]> grant SELECT on mysql.user to '*username*'@'*maxscalehost*'; **Query OK, 0 rows affected (0.03 sec)** +``` Additionally, GRANT SELECT on the mysql.db table and SHOW DATABASES privileges are required in order to load databases name and grants suitable for database name authorization. +``` MariaDB [(none)]> GRANT SELECT ON mysql.db TO 'username'@'maxscalehost'; **Query OK, 0 rows affected (0.00 sec)** @@ -55,9 +58,11 @@ MariaDB [(none)]> GRANT SELECT ON mysql.db TO 'username'@'maxscalehost'; MariaDB [(none)]> GRANT SHOW DATABASES ON *.* TO 'username'@'maxscalehost'; **Query OK, 0 rows affected (0.00 sec)** +``` The second user is used to monitored the state of the cluster. This user, which may be the same username as the first, requires permissions to access the various sources of monitoring data. In order to monitor a replication cluster this user must be granted the roles REPLICATION SLAVE and REPLICATION CLIENT +``` MariaDB [(none)]> grant REPLICATION SLAVE on *.* to '*username*'@'*maxscalehost*'; **Query OK, 0 rows affected (0.00 sec)** @@ -65,220 +70,174 @@ MariaDB [(none)]> grant REPLICATION SLAVE on *.* to '*username*'@'*maxscalehost* MariaDB [(none)]> grant REPLICATION CLIENT on *.* to '*username*'@'*maxscalehost*'; **Query OK, 0 rows affected (0.00 sec)** +``` If you wish to use two different usernames for the two different roles of monitoring and collecting user information then create a different username using the first two steps from above. ## Creating Your MaxScale Configuration -MaxScale configuration is held in an ini file that is located in the file MaxScale.cnf in the directory $MAXSCALE_HOME/etc, if you have installed in the default location then this file is available in /usr/local/mariadb/maxscle/etc/MaxScale.cnf. This is not created as part of the installation process and must be manually created. A template file does exist within this directory that may be use as a basis for your configuration. +MaxScale configuration is held in an ini file that is located in the file MaxScale.cnf in the directory /etc. This is not created as part of the installation process and must be manually created. A template file does exist in the `/usr/share/maxscale` folder that can be use as a basis for your configuration. A global, maxscale, section is included within every MaxScale configuration file; this is used to set the values of various MaxScale wide parameters, perhaps the most important of these is the number of threads that MaxScale will use to execute the code that forwards requests and handles responses for clients. +``` [maxscale] - threads=4 +``` Since we are using MySQL Replication and connection routing we want two different ports to which the client application can connect; one that will be directed to the current master within the replication cluster and another that will load balance between the slaves. To achieve this within MaxScale we need to define two services in the ini file; one for the read/write operations that should be executed on the master server and another for connections to one of the slaves. Create a section for each in your MaxScale.ini file and set the type to service, the section names are the names of the services themselves and should be meaningful to the administrator. Names may contain whitespace. +``` [Write Service] - type=service [Read Service] - type=service +``` The router for these two sections is identical, the readconnroute module, also the services should be provided with the list of servers that will be part of the cluster. The server names given here are actually the names of server sections in the configuration file and not the physical hostnames or addresses of the servers. +``` [Write Service] - type=service - router=readconnroute - servers=dbserv1, dbserv2, dbserv3 [Read Service] - type=service - router=readconnroute - servers=dbserv1, dbserv2, dbserv3 +``` In order to instruct the router to which servers it should route we must add router options to the service. The router options are compared to the status that the monitor collects from the servers and used to restrict the eligible set of servers to which that service may route. In our case we use the two options master and slave for our two services. +``` [Write Service] - type=service - router=readconnroute - router_options=master - servers=dbserv1, dbserv2, dbserv3 [Read Service] - type=service - router=readconnroute - router_options=slave - servers=dbserv1, dbserv2, dbserv3 +``` The final step in the service sections is to add the username and password that will be used to populate the user data from the database cluster. There are two options for representing the password, either plain text or encrypted passwords may be used. In order to use encrypted passwords a set of keys must be generated that will be used by the encryption and decryption process. To generate the keys use the maxkeys command and pass the name of the secrets file in which the keys are stored. -% maxkeys /usr/local/mariadb-maxscale/etc/.secrets - -% +``` +maxkeys /usr/local/mariadb-maxscale/etc/.secrets +``` Once the keys have been created the maxpasswd command can be used to generate the encrypted password. -% maxpasswd plainpassword - +``` +maxpasswd plainpassword 96F99AA1315BDC3604B006F427DD9484 - -% +``` The username and password, either encrypted or plain text, are stored in the service section using the user and passwd parameters. +``` [Write Service] - type=service - router=readconnroute - router_options=master - servers=dbserv1, dbserv2, dbserv3 - user=maxscale - passwd=96F99AA1315BDC3604B006F427DD9484 [Read Service] - type=service - router=readconnroute - router_options=slave - servers=dbserv1, dbserv2, dbserv3 - user=maxscale - passwd=96F99AA1315BDC3604B006F427DD9484 +``` This completes the definitions required by the services, however listening ports must be associated with the services in order to allow network connections. This is done by creating a series of listener sections. These sections again are named for the convenience of the administrator and should be of type listener with an entry labeled service which contains the name of the service to associate the listener with. Each service may have multiple listeners. +``` [Write Listener] - type=listener - service=Write Service [Read Listener] - type=listener - service=Read Service +``` A listener must also define the protocol module it will use for the incoming network protocol, currently this should be the MySQLClient protocol for all database listeners. The listener may then supply a network port to listen on and/or a socket within the file system. +``` [Write Listener] - type=listener - service=Write Service - protocol=MySQLClient - port=4306 - socket=/tmp/ClusterMaster [Read Listener] - type=listener - service=Read Service - protocol=MySQLClient - port=4307 +``` An address parameter may be given if the listener is required to bind to a particular network address when using hosts with multiple network addresses. The default behavior is to listen on all network interfaces. The next stage is the configuration is to define the server information. This defines how to connect to each of the servers within the cluster, again a section is created for each server, with the type set to server, the network address and port to connect to and the protocol to use to connect to the server. Currently the protocol for all database connections in MySQLBackend. +``` [dbserv1] - type=server - address=192.168.2.1 - port=3306 - protocol=MySQLBackend [dbserv2] - type=server - address=192.168.2.2 - port=3306 - protocol=MySQLBackend [dbserv3] - type=server - address=192.168.2.3 - port=3306 - protocol=MySQLBackend +``` In order for MaxScale to monitor the servers using the correct monitoring mechanisms a section should be provided that defines the monitor to use and the servers to monitor. Once again a section is created with a symbolic name for the monitor, with the type set to monitor. Parameters are added for the module to use, the list of servers to monitor and the username and password to use when connecting to the the servers with the monitor. +``` [Replication Monitor] - type=monitor - module=mysqlmon - servers=dbserv1, dbserv2, dbserv3 - user=maxscale - passwd=96F99AA1315BDC3604B006F427DD9484 +``` As with the password definition in the server either plain text or encrypted passwords may be used. The final stage in the configuration is to add the option service which is used by the maxadmin command to connect to MaxScale for monitoring and administration purposes. This creates a service section and a listener section. +``` [CLI] - type=service - router=cli [CLI Listener] - type=listener - service=CLI - protocol=maxscaled - address=localhost - port=6603 +``` In the case of the example above it should be noted that an address parameter has been given to the listener, this limits connections to maxadmin commands that are executed on the same machine that hosts MaxScale. @@ -286,14 +245,19 @@ In the case of the example above it should be noted that an address parameter ha Upon completion of the configuration process MaxScale is ready to be started for the first time. This may either be done manually by running the maxscale command or via the service interface. -% maxscale +``` +maxscale +``` or -% service maxscale start +``` +service maxscale start +``` -Check the error log in /usr/local/mariadb-maxscale/log to see if any errors are detected in the configuration file and to confirm MaxScale has been started. Also the maxadmin command may be used to confirm that MaxScale is running and the services, listeners etc have been correctly configured. +Check the error log in /var/log/lomaxscale/ to see if any errors are detected in the configuration file and to confirm MaxScale has been started. Also the maxadmin command may be used to confirm that MaxScale is running and the services, listeners etc have been correctly configured. +``` % maxadmin -pmariadb list services Services. @@ -349,6 +313,7 @@ CLI | maxscaled | localhost | 6603 | Running ---------------------+--------------------+-----------------+-------+-------- % +``` -MaxScale is now ready to start accepting client connections and routing them to the master or slaves within your cluster. Other configuration options are available that can alter the criteria used for routing, these include monitoring the replication lag within the cluster and routing only to slaves that are within a predetermined delay from the current master or using weights to obtain unequal balancing operations. These options may be found in the MaxScale Configuration Guide. More detail on the use of maxadmin can be found in the document "MaxAdmin - The MaxScale Administration & Monitoring Client Application". +MaxScale is now ready to start accepting client connections and routing them to the master or slaves within your cluster. Other configuration options are available that can alter the criteria used for routing, these include monitoring the replication lag within the cluster and routing only to slaves that are within a predetermined delay from the current master or using weights to obtain unequal balancing operations. These options may be found in the MaxScale Configuration Guide. More detail on the use of maxadmin can be found in the document [MaxAdmin - The MaxScale Administration & Monitoring Client Application](Administration-Tutorial.md). diff --git a/Documentation/Tutorials/MySQL-Replication-Read-Write-Splitting-Tutorial.md b/Documentation/Tutorials/MySQL-Replication-Read-Write-Splitting-Tutorial.md index 54e5412be..b34fcf71e 100644 --- a/Documentation/Tutorials/MySQL-Replication-Read-Write-Splitting-Tutorial.md +++ b/Documentation/Tutorials/MySQL-Replication-Read-Write-Splitting-Tutorial.md @@ -70,7 +70,7 @@ If you wish to use two different usernames for the two different roles of monito ## Creating Your MaxScale Configuration -MaxScale configuration is held in an ini file that is located in the file MaxScale.cnf in the directory $MAXSCALE_HOME/etc, if you have installed in the default location then this file is available in /usr/local/mariadb-maxscale/etc/MaxScale.cnf. This is not created as part of the installation process and must be manually created. A template file does exist within this directory that may be use as a basis for your configuration. +MaxScale configuration is held in an ini file that is located in the file MaxScale.cnf in the directory /etc, if you have installed in the default location then this file is available in /usr/local/mariadb-maxscale/etc/MaxScale.cnf. This is not created as part of the installation process and must be manually created. A template file does exist within this directory that may be use as a basis for your configuration. A global, maxscale, section is included within every MaxScale configuration file; this is used to set the values of various MaxScale wide parameters, perhaps the most important of these is the number of threads that MaxScale will use to execute the code that forwards requests and handles responses for clients. diff --git a/Documentation/Tutorials/Replication-Proxy-Binlog-Router-Tutorial.md b/Documentation/Tutorials/Replication-Proxy-Binlog-Router-Tutorial.md index f07fd13a3..3f61638d1 100644 --- a/Documentation/Tutorials/Replication-Proxy-Binlog-Router-Tutorial.md +++ b/Documentation/Tutorials/Replication-Proxy-Binlog-Router-Tutorial.md @@ -84,7 +84,7 @@ This optional parameter allows for the administrator to define the number of the ### binlogdir -This parameter allows the location that MaxScale uses to store binlog files to be set. If this parameter is not set to a directory name then MaxScale will store the binlog files in the directory $MAXSCALE_HOME/. +This parameter allows the location that MaxScale uses to store binlog files to be set. If this parameter is not set to a directory name then MaxScale will store the binlog files in the directory /var/cache/maxscale/. ### heartbeat diff --git a/Documentation/filters/Query-Log-All-Filter.md b/Documentation/filters/Query-Log-All-Filter.md index e0c71e13f..87ea620c8 100644 --- a/Documentation/filters/Query-Log-All-Filter.md +++ b/Documentation/filters/Query-Log-All-Filter.md @@ -6,7 +6,7 @@ The Query Log All (QLA) filter is a filter module for MaxScale that is ## Configuration -The configuration block for the QLA filter requires the minimal filter options in it's section within the MaxScale.cnf file, stored in $MAXSCALE_HOME/etc/MaxScale.cnf. +The configuration block for the QLA filter requires the minimal filter options in it's section within the MaxScale.cnf file, stored in /etc/MaxScale.cnf. ``` [MyLogFilter] type=filter diff --git a/Documentation/filters/RabbitMQ-Filter.md b/Documentation/filters/RabbitMQ-Filter.md index f23313d0d..4068ceec5 100644 --- a/Documentation/filters/RabbitMQ-Filter.md +++ b/Documentation/filters/RabbitMQ-Filter.md @@ -5,7 +5,7 @@ This filter is designed to extract queries and transform them into a canonical f ## Configuration -The configuration block for the **mqfilter** filter requires the minimal filter options in it’s section within the MaxScale.cnf file, stored in $MAXSCALE_HOME/etc/MaxScale.cnf. Although the filter will start, it will use the default values which only work with a freshly installed RabbitMQ server and use its default values. This setup is mostly intended for testing the filter. +The configuration block for the **mqfilter** filter requires the minimal filter options in it’s section within the MaxScale.cnf file, stored in /etc/MaxScale.cnf. Although the filter will start, it will use the default values which only work with a freshly installed RabbitMQ server and use its default values. This setup is mostly intended for testing the filter. The following is an example of a mqfilter configuration in the MaxScale.cnf file used for actual logging of queries to a RabbitMQ broker on a different host. diff --git a/Documentation/filters/Regex-Filter.md b/Documentation/filters/Regex-Filter.md index 2d5ecd96d..e5a6744f2 100644 --- a/Documentation/filters/Regex-Filter.md +++ b/Documentation/filters/Regex-Filter.md @@ -6,7 +6,7 @@ The regex filter is a filter module for MaxScale that is able to rewrite query c # Configuration -The configuration block for the Regex filter requires the minimal filter options in it’s section within the MaxScale.cnf file, stored in $MAXSCALE_HOME/etc/MaxScale.cnf. +The configuration block for the Regex filter requires the minimal filter options in it’s section within the MaxScale.cnf file, stored in /etc/MaxScale.cnf. ``` [MyRegexFilter] diff --git a/Documentation/filters/Tee-Filter.md b/Documentation/filters/Tee-Filter.md index a8a95a5cc..868886ceb 100644 --- a/Documentation/filters/Tee-Filter.md +++ b/Documentation/filters/Tee-Filter.md @@ -6,7 +6,7 @@ The tee filter is a filter module for MaxScale is a "plumbing" fitting in the Ma # Configuration -The configuration block for the TEE filter requires the minimal filter parameters in it’s section within the MaxScale.cnf file, stored in $MAXSCALE_HOME/etc/MaxScale.cnf, that defines the filter to load and the service to send the duplicates to. Currently the tee filter does not support multi-statements. +The configuration block for the TEE filter requires the minimal filter parameters in it’s section within the MaxScale.cnf file, stored in /etc/MaxScale.cnf, that defines the filter to load and the service to send the duplicates to. Currently the tee filter does not support multi-statements. ``` [DataMartFilter] diff --git a/Documentation/filters/Top-N-Filter.md b/Documentation/filters/Top-N-Filter.md index d51ca43db..f52a6bedd 100644 --- a/Documentation/filters/Top-N-Filter.md +++ b/Documentation/filters/Top-N-Filter.md @@ -6,7 +6,7 @@ The top filter is a filter module for MaxScale that monitors every SQL statement # Configuration -The configuration block for the TOP filter requires the minimal filter options in it’s section within the MaxScale.cnf file, stored in $MAXSCALE_HOME/etc/MaxScale.cnf. +The configuration block for the TOP filter requires the minimal filter options in it’s section within the MaxScale.cnf file, stored in /etc/MaxScale.cnf. ``` [MyLogFilter] diff --git a/cmake/install_layout.cmake b/cmake/install_layout.cmake index 821b2c474..1425b4d49 100644 --- a/cmake/install_layout.cmake +++ b/cmake/install_layout.cmake @@ -3,18 +3,12 @@ # STANDALONE - Installs to /usr/local/mariadb-maxscale # RPM - Installs to /usr # DEB - Installs to /usr -if(${TYPE} MATCHES "STANDALONE") +include(GNUInstallDirs) - set(CMAKE_INSTALL_PREFIX "/usr/local/mariadb-maxscale" CACHE PATH "Prefix prepended to install directories.") - - # RPM and DEB are the same until differences are found -else() - set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Prefix prepended to install directories.") -endif() - -set(MAXSCALE_LIBDIR lib64/maxscale CACHE PATH "Library installation path") -set(MAXSCALE_BINDIR bin CACHE PATH "Executable installation path") -set(MAXSCALE_SHAREDIR share/maxscale CACHE PATH "Share file installation path, includes licence and readme files") -set(MAXSCALE_DOCDIR share/doc/maxscale CACHE PATH "Documentation installation path, text versions only") -set(MAXSCALE_CONFDIR etc CACHE PATH "Configuration file installation path, this is not usually needed") +set(MAXSCALE_LIBDIR ${CMAKE_INSTALL_LIBDIR}/maxscale CACHE PATH "Library installation path") +set(MAXSCALE_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Executable installation path") +set(MAXSCALE_SHAREDIR ${CMAKE_INSTALL_DATADIR}/maxscale CACHE PATH "Share file installation path, includes licence and readme files") +set(MAXSCALE_DOCDIR ${CMAKE_INSTALL_DOCDIR}/maxscale CACHE PATH "Documentation installation path, text versions only") +set(MAXSCALE_CONFDIR ${CMAKE_INSTALL_SYSCONFDIR} CACHE PATH "Configuration file installation path, this is not usually needed") +set(MAXSCALE_VARDIR /var CACHE PATH "Data file path (usually /var/)") diff --git a/server/core/gateway.c b/server/core/gateway.c index a4901ec23..f24cf8a11 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -505,15 +505,9 @@ static bool resolve_maxscale_conf_fname( * directory. * '-f MaxScale.cnf' */ - home_etc_dir = (char*)malloc(strlen(home_dir)+strlen("/etc")+1); - snprintf(home_etc_dir, - strlen(home_dir)+strlen("/etc")+1, - "%s/etc", - home_dir); *cnf_full_path = get_expanded_pathname(NULL, - home_etc_dir, + home_dir, cnf_file_arg); - free(home_etc_dir); if (*cnf_full_path != NULL) { @@ -1026,11 +1020,11 @@ static void usage(void) " -L|--logdir=... path to log file directory\n" " (default: /var/log/maxscale)\n" " -D|--datadir=... path to data directory\n" - " (default: /var/lib/maxscale)\n" + " (default: /usr/lib64/maxscale)\n" " -C|--configdir=... path to configuration file directory\n" " (default: /etc/)\n" - " -B|--libdir=... path to module directory\n" - " (default: /var/lib/maxscale)\n" + " -B|--libdir=... path to module directory\n" + " (default: /usr/lib64/maxscale)\n" " -A|--cachedir=... path to cache directory\n" " (default: /var/cache/maxscale)\n" " -s|--syslog= log messages to syslog.\n" @@ -1588,63 +1582,6 @@ int main(int argc, char **argv) sprintf(mysql_home, "%s/mysql", cachedir); setenv("MYSQL_HOME", mysql_home, 1); - /*< - * If MaxScale home directory wasn't set by command-line argument. - * Next, resolve it from environment variable and further on, - * try to use default. - */ -/* - - if (home_dir == NULL) - { - if (!resolve_maxscale_homedir(&home_dir)) - { - ss_dassert(home_dir != NULL); - rc = MAXSCALE_HOMELESS; - goto return_main; - } - - } - else - { - char* log_context = strdup("Home directory command-line argument"); - char* errstr; - - errstr = check_dir_access(home_dir,true,true); - - if (errstr != NULL) - { - char* logstr = (char*)malloc(strlen(log_context)+ - 1+ - strlen(errstr)+ - 1); - - snprintf(logstr, - strlen(log_context)+ - 1+ - strlen(errstr)+1, - "%s: %s", - log_context, - errstr); - - print_log_n_stderr(true, true, logstr, logstr, 0); - - free(errstr); - free(logstr); - rc = MAXSCALE_HOMELESS; - goto return_main; - } - else if (!daemon_mode) - { - fprintf(stderr, - "Using %s as MAXSCALE_HOME = %s\n", - log_context, - home_dir); - } - free(log_context); - } -*/ - /** * Resolve the full pathname for configuration file and check for * read accessibility. diff --git a/server/include/gw.h b/server/include/gw.h index e210fcfa2..b51bb0e2a 100644 --- a/server/include/gw.h +++ b/server/include/gw.h @@ -1,5 +1,25 @@ #ifndef _GW_HG #define _GW_HG + +/* + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright MariaDB Corporation Ab 2013-2014 + */ + + #include #include #include @@ -19,17 +39,7 @@ #include #include #include - -/** Default file locations */ -static const char* default_cnf_fname = "MaxScale.cnf"; -static const char* default_configdir = "/etc/"; -static const char* default_logdir = "/var/log/maxscale/"; -static const char* default_datadir = "/var/cache/maxscale/"; -static const char* default_libdir = "/lib64/maxscale/"; -static const char* default_cachedir = "/var/cache/maxscale/"; -static const char* default_langdir = "/usr/share/mysql/english/"; /*< This is where the MariaDB - * server installs errmsg.sys */ -static const char* default_piddir = "/var/run/maxscale/"; +#include #define EXIT_FAILURE 1 diff --git a/server/include/gwdirs.h.in b/server/include/gwdirs.h.in new file mode 100644 index 000000000..3bc6c3f67 --- /dev/null +++ b/server/include/gwdirs.h.in @@ -0,0 +1,33 @@ +#ifndef _GW_DIRS_HG +#define _GW_DIRS_HG + +/* + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright MariaDB Corporation Ab 2015 + */ + +/** Default file locations, configured by CMake */ +static const char* default_cnf_fname = "MaxScale.cnf"; +static const char* default_configdir = "/etc/"; +static const char* default_piddir = "/var/run/maxscale/"; +static const char* default_logdir = "/var/log/maxscale/"; +static const char* default_datadir = "/var/cache/maxscale/"; +static const char* default_libdir = "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@"; +static const char* default_cachedir = "/var/cache/maxscale/"; +static const char* default_langdir = "/usr/share/mysql/english/"; /*< This is where the MariaDB + * server installs errmsg.sys */ + +#endif From 9eeec2e9d3f131b038c2977f24c8d39f199c71aa Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 26 Apr 2015 11:41:02 +0300 Subject: [PATCH 07/34] Added FindJemalloc.cmake --- CMakeLists.txt | 2 +- cmake/FindJemalloc.cmake | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 cmake/FindJemalloc.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 564cb43a5..34d2767ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ find_package(MySQLClient) find_package(MySQL) find_package(Pandoc) find_package(TCMalloc) - +find_package(Jemalloc) # You can find the variables set by this in the FindCURL.cmake file # which is a default module in CMake. find_package(CURL) diff --git a/cmake/FindJemalloc.cmake b/cmake/FindJemalloc.cmake new file mode 100644 index 000000000..3bea2d5a0 --- /dev/null +++ b/cmake/FindJemalloc.cmake @@ -0,0 +1,11 @@ +# this CMake file defines the following variables +# JEMALLOC_FOUND - Jemalloc was found +# JEMALLOC_LIBRARIES - Jemalloc library +find_library(JEMALLOC_LIBRARIES NAMES jemalloc libjemalloc.so.4 libjemalloc.so.4.2.2) +if(JEMALLOC_LIBRARIES) + set(JEMALLOC_FOUND TRUE CACHE INTERNAL "") + message(STATUS "Found libjemalloc: ${JEMALLOC_LIBRARIES}") +else() + set(JEMALLOC_FOUND FALSE CACHE INTERNAL "") + message(STATUS "Could not find libjemalloc, using system default malloc instead.") +endif() From 49907ffdea3f5caf62bd6dddcf6d1fb87de81e7b Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 05:57:16 +0300 Subject: [PATCH 08/34] Added optional jemalloc linkage. --- server/core/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index ead8560d3..36d87865f 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,7 +1,9 @@ if(BUILD_TESTS OR BUILD_TOOLS) file(GLOB FULLCORE_SRC *.c) add_library(fullcore STATIC ${FULLCORE_SRC}) - if(WITH_TCMALLOC) + if(WITH_JEMALLOC) + target_link_libraries(fullcore ${JEMALLOC_LIBRARIES}) + elseif(WITH_TCMALLOC) target_link_libraries(fullcore ${TCMALLOC_LIBRARIES}) endif() target_link_libraries(fullcore ${CURL_LIBRARIES} log_manager utils pthread ${EMBEDDED_LIB} ${PCRE_LINK_FLAGS} ssl aio rt crypt dl crypto inih z m stdc++) @@ -13,7 +15,9 @@ add_executable(maxscale atomic.c buffer.c spinlock.c gateway.c monitor.c adminusers.c secrets.c filter.c modutil.c hint.c housekeeper.c memlog.c resultset.c) -if(WITH_TCMALLOC) +if(WITH_JEMALLOC) + target_link_libraries(maxscale ${JEMALLOC_LIBRARIES}) +elseif(WITH_TCMALLOC) target_link_libraries(maxscale ${TCMALLOC_LIBRARIES}) endif() From 41ddc6fbfda25356be73aa9050e9176544ca7117 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 09:43:22 +0300 Subject: [PATCH 09/34] Switched over to gwbuf_clone_portion in modutils_get_complete_packets. Conflicts: server/core/modutil.c --- server/core/modutil.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/core/modutil.c b/server/core/modutil.c index 82890e334..c01c7623a 100644 --- a/server/core/modutil.c +++ b/server/core/modutil.c @@ -538,7 +538,7 @@ return_packetbuf: GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf) { GWBUF *buff = NULL, *packet; - uint8_t *ptr,*end; + uint8_t *ptr; int len,blen,total = 0; if(p_readbuf == NULL || (*p_readbuf) == NULL || @@ -583,7 +583,6 @@ GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf) "Error: Failed to partially clone buffer."); return NULL; } - gwbuf_consume(packet,total); return buff; } @@ -841,4 +840,4 @@ int modutil_count_statements(GWBUF* buffer) } return num; -} \ No newline at end of file +} From d5682bf7c089a486bcc18cb2f04c79331182fe58 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 10:10:55 +0300 Subject: [PATCH 10/34] Removed file globbing in the core CMake file and used explicit names instead. --- server/core/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 36d87865f..218d2b0c4 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,6 +1,5 @@ if(BUILD_TESTS OR BUILD_TOOLS) - file(GLOB FULLCORE_SRC *.c) - add_library(fullcore STATIC ${FULLCORE_SRC}) + add_library(fullcore STATIC adminusers.c atomic.c config.c dbusers.c dcb.c filter.c gwbitmask.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c memlog.x modutil.c monitor.c poll.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c) if(WITH_JEMALLOC) target_link_libraries(fullcore ${JEMALLOC_LIBRARIES}) elseif(WITH_TCMALLOC) From 97653e98faa1cb73113354a7bfad0e5de712f188 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 10:14:47 +0300 Subject: [PATCH 11/34] Fixed a typo in the core CMakeLists.txt --- server/core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 218d2b0c4..25bf74c35 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,5 +1,5 @@ if(BUILD_TESTS OR BUILD_TOOLS) - add_library(fullcore STATIC adminusers.c atomic.c config.c dbusers.c dcb.c filter.c gwbitmask.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c memlog.x modutil.c monitor.c poll.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c) + add_library(fullcore STATIC adminusers.c atomic.c config.c dbusers.c dcb.c filter.c gwbitmask.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c memlog.c modutil.c monitor.c poll.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c) if(WITH_JEMALLOC) target_link_libraries(fullcore ${JEMALLOC_LIBRARIES}) elseif(WITH_TCMALLOC) From 2fce1144830a06c474c3a6a19b4a73c0849e0408 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 10:17:55 +0300 Subject: [PATCH 12/34] Added missing buffer.c from fullcore static lib. --- server/core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 25bf74c35..52ebf2b1e 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,5 +1,5 @@ if(BUILD_TESTS OR BUILD_TOOLS) - add_library(fullcore STATIC adminusers.c atomic.c config.c dbusers.c dcb.c filter.c gwbitmask.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c memlog.c modutil.c monitor.c poll.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c) + add_library(fullcore STATIC adminusers.c atomic.c config.c buffer.c dbusers.c dcb.c filter.c gwbitmask.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c memlog.c modutil.c monitor.c poll.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c) if(WITH_JEMALLOC) target_link_libraries(fullcore ${JEMALLOC_LIBRARIES}) elseif(WITH_TCMALLOC) From 0cfcad55dad5e03cb6ee4b62ab23c07368b5d3c3 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 11:06:11 +0300 Subject: [PATCH 13/34] Moved get_libdir function to its own file. --- server/core/CMakeLists.txt | 4 ++-- server/core/gateway.c | 15 ++------------- server/core/gwdirs.c | 10 ++++++++++ server/include/gwdirs.h.in | 10 ++++++++++ 4 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 server/core/gwdirs.c diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 52ebf2b1e..c952f5a1a 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,5 +1,5 @@ if(BUILD_TESTS OR BUILD_TOOLS) - add_library(fullcore STATIC adminusers.c atomic.c config.c buffer.c dbusers.c dcb.c filter.c gwbitmask.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c memlog.c modutil.c monitor.c poll.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c) + add_library(fullcore STATIC adminusers.c atomic.c config.c buffer.c dbusers.c dcb.c filter.c gwbitmask.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c memlog.c modutil.c monitor.c poll.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c gwdirs.c) if(WITH_JEMALLOC) target_link_libraries(fullcore ${JEMALLOC_LIBRARIES}) elseif(WITH_TCMALLOC) @@ -12,7 +12,7 @@ add_executable(maxscale atomic.c buffer.c spinlock.c gateway.c gw_utils.c utils.c dcb.c load_utils.c session.c service.c server.c poll.c config.c users.c hashtable.c dbusers.c thread.c gwbitmask.c monitor.c adminusers.c secrets.c filter.c modutil.c hint.c - housekeeper.c memlog.c resultset.c) + housekeeper.c memlog.c resultset.c gwdirs.c) if(WITH_JEMALLOC) target_link_libraries(maxscale ${JEMALLOC_LIBRARIES}) diff --git a/server/core/gateway.c b/server/core/gateway.c index f24cf8a11..77afe994b 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -129,11 +129,7 @@ static bool datadir_defined = false; /*< If the datadir was already set */ /* The data directory we created for this gateway instance */ static char pidfile[PATH_MAX+1] = ""; -static char* configdir = NULL; -static char* logdir = NULL; -static char* libdir = NULL; -static char* cachedir = NULL; -static char* langdir = NULL; + /** * exit flag for log flusher. */ @@ -200,14 +196,7 @@ static bool resolve_maxscale_homedir( static char* check_dir_access(char* dirname,bool,bool); -/** - * Get the directory with all the modules. - * @return The module directory - */ -char* get_libdir() -{ - return libdir; -} + /** * Handler for SIGHUP signal. Reload the configuration for the * gateway. diff --git a/server/core/gwdirs.c b/server/core/gwdirs.c new file mode 100644 index 000000000..af7edd9de --- /dev/null +++ b/server/core/gwdirs.c @@ -0,0 +1,10 @@ +#include + +/** + * Get the directory with all the modules. + * @return The module directory + */ +char* get_libdir() +{ + return libdir?libdir:(char*)default_libdir; +} diff --git a/server/include/gwdirs.h.in b/server/include/gwdirs.h.in index 3bc6c3f67..40bf3ba26 100644 --- a/server/include/gwdirs.h.in +++ b/server/include/gwdirs.h.in @@ -19,6 +19,8 @@ * Copyright MariaDB Corporation Ab 2015 */ +#include + /** Default file locations, configured by CMake */ static const char* default_cnf_fname = "MaxScale.cnf"; static const char* default_configdir = "/etc/"; @@ -30,4 +32,12 @@ static const char* default_cachedir = "/var/cache/maxscale/"; static const char* default_langdir = "/usr/share/mysql/english/"; /*< This is where the MariaDB * server installs errmsg.sys */ +static char* configdir = NULL; +static char* logdir = NULL; +static char* libdir = NULL; +static char* cachedir = NULL; +static char* langdir = NULL; + +char* get_libdir(); + #endif From bbcecc0db53b54087ad242405fb587c807ccf9a9 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 13:10:06 +0300 Subject: [PATCH 14/34] Changed all MaxScale.cnf code references to maxscale.cnf --- CMakeLists.txt | 8 ++-- cmake/testall.cmake | 2 +- server/core/gateway.c | 42 +++++++++---------- server/core/gwdirs.c | 9 ++++ server/core/service.c | 15 +++---- server/include/gwdirs.h.in | 2 +- ...cnf => maxscale_binlogserver_template.cnf} | 0 ...ale_template.cnf => maxscale_template.cnf} | 0 server/modules/filter/test/tee_recursion.sh | 4 +- .../{MaxScale_test.cnf => maxscale_test.cnf} | 4 ++ 10 files changed, 46 insertions(+), 40 deletions(-) rename server/{MaxScale_BinlogServer_template.cnf => maxscale_binlogserver_template.cnf} (100%) rename server/{MaxScale_template.cnf => maxscale_template.cnf} (100%) rename server/test/{MaxScale_test.cnf => maxscale_test.cnf} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34d2767ea..550724505 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ configure_file(${CMAKE_SOURCE_DIR}/server/include/gwdirs.h.in ${CMAKE_BINARY_DIR configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.h.in ${CMAKE_BINARY_DIR}/server/include/maxscale_test.h) configure_file(${CMAKE_SOURCE_DIR}/etc/postinst.in ${CMAKE_BINARY_DIR}/postinst) configure_file(${CMAKE_SOURCE_DIR}/etc/postrm.in ${CMAKE_BINARY_DIR}/postrm) +configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.cnf ${CMAKE_BINARY_DIR}/maxscale.cnf) set(FLAGS "-Wall -Wno-unused-variable -Wno-unused-function -fPIC" CACHE STRING "Compilation flags") set(DEBUG_FLAGS "-ggdb -pthread -pipe -Wformat -fstack-protector --param=ssp-buffer-size=4" CACHE STRING "Debug compilation flags") @@ -152,9 +153,9 @@ ${CMAKE_SOURCE_DIR}/Documentation/Upgrading-To-MaxScale-1.1.0.md install(FILES ${CMAKE_BINARY_DIR}/Changelog.txt DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION ${MAXSCALE_SHAREDIR}) -install(FILES server/MaxScale_template.cnf DESTINATION ${MAXSCALE_SHAREDIR}) -install(FILES server/MaxScale_BinlogServer_template.cnf DESTINATION ${MAXSCALE_SHAREDIR}) -install(FILES ${ERRMSG} DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES server/maxscale_template.cnf DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES server/maxscale_binlogserver_template.cnf DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES ${ERRMSG} DESTINATION /usr/share/mysql/english/) install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${MAXSCALE_SHAREDIR}) @@ -245,7 +246,6 @@ add_custom_target(buildtestsx add_custom_target(testall COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DWITH_SCRIPTS=N ${CMAKE_SOURCE_DIR} COMMAND make install - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/server/test/MaxScale_test.cnf ${CMAKE_BINARY_DIR}/etc/MaxScale.cnf COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/testall.cmake COMMENT "Running full test suite..." VERBATIM) diff --git a/cmake/testall.cmake b/cmake/testall.cmake index fedbdf273..1a438bc1a 100644 --- a/cmake/testall.cmake +++ b/cmake/testall.cmake @@ -1,4 +1,4 @@ -execute_process(COMMAND /bin/sh -c "${CMAKE_BINARY_DIR}/bin/maxscale -c ${CMAKE_BINARY_DIR} &>/dev/null 2> /dev/null > /dev/null") +execute_process(COMMAND /bin/sh -c "${CMAKE_BINARY_DIR}/bin/maxscale -f ${CMAKE_BINARY_DIR}/etc/maxscale.cnf &>/dev/null 2> /dev/null > /dev/null") execute_process(COMMAND make test RESULT_VARIABLE RVAL) execute_process(COMMAND killall maxscale) if(NOT RVAL EQUAL 0) diff --git a/server/core/gateway.c b/server/core/gateway.c index 77afe994b..ae6f1c5c0 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -999,29 +999,25 @@ return_cnf_file_buf: static void usage(void) { fprintf(stderr, - "\nUsage : %s [-h] | [-d] [-c ] [-f ]\n\n" - " -d|--nodaemon enable running in terminal process (default:disabled)\n" - " -c|--homedir=... relative|absolute MaxScale home directory\n" - " -f|--config=... relative|absolute pathname of MaxScale configuration file\n" - " (default: $MAXSCALE_HOME/etc/MaxScale.cnf)\n" - " -l|--log=... log to file or shared memory\n" - " -lfile or -lshm - defaults to shared memory\n" - " -L|--logdir=... path to log file directory\n" - " (default: /var/log/maxscale)\n" - " -D|--datadir=... path to data directory\n" - " (default: /usr/lib64/maxscale)\n" - " -C|--configdir=... path to configuration file directory\n" - " (default: /etc/)\n" - " -B|--libdir=... path to module directory\n" - " (default: /usr/lib64/maxscale)\n" - " -A|--cachedir=... path to cache directory\n" - " (default: /var/cache/maxscale)\n" - " -s|--syslog= log messages to syslog.\n" - " True or false - defaults to true\n" - " -S|--maxscalelog= log messages to MaxScale log.\n" - " True or false - defaults to true\n" - " -v|--version print version info and exit\n" - " -?|--help show this help\n" + "\nUsage : %s [OPTION]...\n\n" + " -d, --nodaemon enable running in terminal process (default:disabled)\n" + " -f, --config=FILE relative|absolute pathname of MaxScale configuration file\n" + " (default:/etc/maxscale.cnf)\n" + " -l, --log=[file|shm] log to file or shared memory (default: shm)\n" + " -L, --logdir=PATH path to log file directory\n" + " (default: /var/log/maxscale)\n" + " -D, --datadir=PATH path to data directory\n" + " (default: /usr/lib64/maxscale)\n" + " -C, --configdir=PATH path to configuration file directory\n" + " (default: /etc/)\n" + " -B, --libdir=PATH path to module directory\n" + " (default: /usr/lib64/maxscale)\n" + " -A, --cachedir=PATH path to cache directory\n" + " (default: /var/cache/maxscale)\n" + " -s, --syslog=[yes|no] log messages to syslog (default:yes)\n" + " -S, --maxscalelog=[yes|no] log messages to MaxScale log (default: yes)\n" + " -v, --version print version info and exit\n" + " -?, --help show this help\n" , progname); } diff --git a/server/core/gwdirs.c b/server/core/gwdirs.c index af7edd9de..9bf0185cd 100644 --- a/server/core/gwdirs.c +++ b/server/core/gwdirs.c @@ -8,3 +8,12 @@ char* get_libdir() { return libdir?libdir:(char*)default_libdir; } + +/** + * Get the service cache directory + * @return The path to the cache directory + */ +char* get_cachedir() +{ + return cachedir?cachedir:(char*)default_cachedir; +} diff --git a/server/core/service.c b/server/core/service.c index bd22117ec..d529cc54a 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -62,6 +62,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -259,15 +260,11 @@ GWPROTOCOL *funcs; else { /* Save authentication data to file cache */ - char *ptr, path[4097]; + char *ptr, path[PATH_MAX + 1]; int mkdir_rval = 0; - strcpy(path, "/usr/local/mariadb-maxscale"); - if ((ptr = getenv("MAXSCALE_HOME")) != NULL) - { - strncpy(path, ptr, 4096); - } + strcpy(path, get_cachedir()); strncat(path, "/", 4096); - strncat(path, service->name, 4096); + strncat(path, service->name, PATH_MAX); if (access(path, R_OK) == -1) { mkdir_rval = mkdir(path, 0777); @@ -282,7 +279,7 @@ GWPROTOCOL *funcs; mkdir_rval = 0; } - strncat(path, "/.cache", 4096); + strncat(path, "/.cache", PATH_MAX); if (access(path, R_OK) == -1) { mkdir_rval = mkdir(path, 0777); @@ -296,7 +293,7 @@ GWPROTOCOL *funcs; strerror(errno)); mkdir_rval = 0; } - strncat(path, "/dbusers", 4096); + strncat(path, "/dbusers", PATH_MAX); dbusers_save(service->users, path); } if (loaded == 0) diff --git a/server/include/gwdirs.h.in b/server/include/gwdirs.h.in index 40bf3ba26..e62696aab 100644 --- a/server/include/gwdirs.h.in +++ b/server/include/gwdirs.h.in @@ -22,7 +22,7 @@ #include /** Default file locations, configured by CMake */ -static const char* default_cnf_fname = "MaxScale.cnf"; +static const char* default_cnf_fname = "maxscale.cnf"; static const char* default_configdir = "/etc/"; static const char* default_piddir = "/var/run/maxscale/"; static const char* default_logdir = "/var/log/maxscale/"; diff --git a/server/MaxScale_BinlogServer_template.cnf b/server/maxscale_binlogserver_template.cnf similarity index 100% rename from server/MaxScale_BinlogServer_template.cnf rename to server/maxscale_binlogserver_template.cnf diff --git a/server/MaxScale_template.cnf b/server/maxscale_template.cnf similarity index 100% rename from server/MaxScale_template.cnf rename to server/maxscale_template.cnf diff --git a/server/modules/filter/test/tee_recursion.sh b/server/modules/filter/test/tee_recursion.sh index 015bb9a8e..82a8080e2 100755 --- a/server/modules/filter/test/tee_recursion.sh +++ b/server/modules/filter/test/tee_recursion.sh @@ -49,8 +49,8 @@ USER=$3 PWD=$4 HOST=$5 PORT=$6 -CONF=$BINDIR/etc/MaxScale.cnf -OLDCONF=$BINDIR/etc/MaxScale.cnf.old +CONF=$BINDIR/etc/maxscale.cnf +OLDCONF=$BINDIR/etc/maxscale.cnf.old MAXPID=$BINDIR/log/$(ls -1 $BINDIR/log|grep maxscale) TEST1=$SRCDIR/server/modules/filter/test/tee_recursion1.cnf TEST2=$SRCDIR/server/modules/filter/test/tee_recursion2.cnf diff --git a/server/test/MaxScale_test.cnf b/server/test/maxscale_test.cnf similarity index 92% rename from server/test/MaxScale_test.cnf rename to server/test/maxscale_test.cnf index 06b783ca5..2fd6ad0d8 100644 --- a/server/test/MaxScale_test.cnf +++ b/server/test/maxscale_test.cnf @@ -1,5 +1,9 @@ [maxscale] threads=4 +libdir=@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@ +logdir=@CMAKE_INSTALL_PREFIX@/log +datadir=@CMAKE_INSTALL_PREFIX@/data +cachedir=@CMAKE_INSTALL_PREFIX@/cache [feedback] feedback_enable=true From 55249193a9f9687f3e63b8e2fbc766b47c08938a Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 14:30:47 +0300 Subject: [PATCH 15/34] Updated post-install scripts and binlogrouter Binlogrouter: Switched hard-coded maximum path values to PATH_MAX and used cache directory instead of MAXSCALE_HOME Scripts: Updated with new executable file paths --- etc/init.d/maxscale.in | 13 ++++---- etc/postinst.in | 1 + etc/ubuntu/init.d/maxscale.in | 9 +++-- server/core/gateway.c | 4 +-- server/modules/routing/binlog/blr_file.c | 42 +++++++++--------------- 5 files changed, 28 insertions(+), 41 deletions(-) diff --git a/etc/init.d/maxscale.in b/etc/init.d/maxscale.in index 88f026e18..c8822109c 100755 --- a/etc/init.d/maxscale.in +++ b/etc/init.d/maxscale.in @@ -18,12 +18,11 @@ ### END INIT INFO ############################################# -# MaxScale HOME, PIDFILE, LIB +# MaxScale PIDFILE and LIB ############################################# -export MAXSCALE_HOME=@CMAKE_INSTALL_PREFIX@ -export MAXSCALE_PIDFILE=$MAXSCALE_HOME/log/maxscale.pid -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MAXSCALE_HOME/lib +export MAXSCALE_PIDFILE=/var/run/maxscale/maxscale.pid +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@/maxscale ############################### # LSB Exit codes (non-Status) @@ -56,7 +55,7 @@ start() { CHECK_RET=$? [ $CHECK_RET -eq 0 ] && echo -n " found $my_check" && success && CHECK_RET=0 - daemon --pidfile $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale >& /dev/null + daemon --pidfile $MAXSCALE_PIDFILE @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale >& /dev/null RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename @@ -68,7 +67,7 @@ start() { [ $CHECK_RET -eq 0 ] && echo -n $my_check && success || failure fi - # Return rigth code + # Return right code if [ $RETVAL -ne 0 ]; then failure RETVAL=$_RETVAL_NOT_RUNNING @@ -100,7 +99,7 @@ stop() { reload() { echo -n $"Reloading MaxScale: " - killproc -p $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale -HUP + killproc -p $MAXSCALE_PIDFILE @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale -HUP RETVAL=$? echo } diff --git a/etc/postinst.in b/etc/postinst.in index c04850019..464e240f1 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -3,6 +3,7 @@ mkdir -p /var/log/maxscale mkdir -p /var/cache/maxscale mkdir -p /var/run/maxscale +mkdir -p @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/ cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/maxscale /etc/init.d/ cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/maxscale.conf /etc/ld.so.conf.d/ /sbin/ldconfig diff --git a/etc/ubuntu/init.d/maxscale.in b/etc/ubuntu/init.d/maxscale.in index caf7d1408..9b8ff84e9 100755 --- a/etc/ubuntu/init.d/maxscale.in +++ b/etc/ubuntu/init.d/maxscale.in @@ -21,9 +21,8 @@ # MaxScale HOME, PIDFILE, LIB ############################################# -export MAXSCALE_HOME=@CMAKE_INSTALL_PREFIX@ -export MAXSCALE_PIDFILE=$MAXSCALE_HOME/log/maxscale.pid -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MAXSCALE_HOME/lib +export MAXSCALE_PIDFILE=/var/run/maxscale/maxscale.pid +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@/maxscale ############################### # LSB Exit codes (non-Status) @@ -45,7 +44,7 @@ _RETVAL_STATUS_NOT_RUNNING=3 # stop/start/status related vars ################################# NAME=maxscale -DAEMON=$MAXSCALE_HOME/bin/maxscale +DAEMON=@CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale # Source function library. . /lib/lsb/init-functions @@ -82,7 +81,7 @@ reload() { } maxscale_wait_stop() { - PIDTMP=$(pidofproc -p $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale) + PIDTMP=$(pidofproc -p $MAXSCALE_PIDFILE @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale) kill -TERM "${PIDTMP:-}" 2> /dev/null; if [ -n "${PIDTMP:-}" ] && kill -0 "${PIDTMP:-}" 2> /dev/null; then local i=0 diff --git a/server/core/gateway.c b/server/core/gateway.c index ae6f1c5c0..a5ad3e2fe 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -1006,8 +1006,8 @@ static void usage(void) " -l, --log=[file|shm] log to file or shared memory (default: shm)\n" " -L, --logdir=PATH path to log file directory\n" " (default: /var/log/maxscale)\n" - " -D, --datadir=PATH path to data directory\n" - " (default: /usr/lib64/maxscale)\n" + " -D, --datadir=PATH path to data directory, stored embedded mysql tables\n" + " (default: /var/cache/maxscale)\n" " -C, --configdir=PATH path to configuration file directory\n" " (default: /etc/)\n" " -B, --libdir=PATH path to module directory\n" diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index b8e201227..32fbad28c 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -71,7 +71,7 @@ static void blr_log_header(logfile_id_t file, char *msg, uint8_t *ptr); int blr_file_init(ROUTER_INSTANCE *router) { -char *ptr, path[PATH_MAX], filename[PATH_MAX]; +char *ptr, path[PATH_MAX+1], filename[PATH_MAX+1]; int file_found, n = 1; int root_len, i; DIR *dirp; @@ -79,12 +79,8 @@ struct dirent *dp; if (router->binlogdir == NULL) { - strcpy(path, "/usr/local/mariadb-maxscale"); - if ((ptr = getenv("MAXSCALE_HOME")) != NULL) - { - strncpy(path, ptr,PATH_MAX); - } - strncat(path, "/",PATH_MAX); + strcpy(path, get_cachedir()); + strncat(path,"/",PATH_MAX); strncat(path, router->service->name,PATH_MAX); if (access(path, R_OK) == -1) @@ -659,24 +655,20 @@ struct stat statb; void blr_cache_response(ROUTER_INSTANCE *router, char *response, GWBUF *buf) { -char path[4097], *ptr; +char path[PATH_MAX+1], *ptr; int fd; - strcpy(path, "/usr/local/mariadb-maxscale"); - if ((ptr = getenv("MAXSCALE_HOME")) != NULL) - { - strncpy(path, ptr, 4096); - } - strncat(path, "/", 4096); - strncat(path, router->service->name, 4096); + strcpy(path,get_cachedir()); + strncat(path,"/",PATH_MAX); + strncat(path, router->service->name, PATH_MAX); if (access(path, R_OK) == -1) mkdir(path, 0777); - strncat(path, "/.cache", 4096); + strncat(path, "/.cache", PATH_MAX); if (access(path, R_OK) == -1) mkdir(path, 0777); strncat(path, "/", 4096); - strncat(path, response, 4096); + strncat(path, response, PATH_MAX); if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) return; @@ -697,19 +689,15 @@ GWBUF * blr_cache_read_response(ROUTER_INSTANCE *router, char *response) { struct stat statb; -char path[4097], *ptr; +char path[PATH_MAX+1], *ptr; int fd; GWBUF *buf; - strcpy(path, "/usr/local/mariadb-maxscale"); - if ((ptr = getenv("MAXSCALE_HOME")) != NULL) - { - strncpy(path, ptr, 4096); - } - strncat(path, "/", 4096); - strncat(path, router->service->name, 4096); - strncat(path, "/.cache/", 4096); - strncat(path, response, 4096); + strcpy(path, get_cachedir()); + strncat(path, "/", PATH_MAX); + strncat(path, router->service->name, PATH_MAX); + strncat(path, "/.cache/", PATH_MAX); + strncat(path, response, PATH_MAX); if ((fd = open(path, O_RDONLY)) == -1) return NULL; From 1cc6ced505c47e18757d09388b5923b4a2677abc Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 15:06:45 +0300 Subject: [PATCH 16/34] Updated old references to MAXSCALE_HOME --- server/core/adminusers.c | 26 +++++--------------------- server/core/load_utils.c | 11 ----------- server/core/maxkeys.c | 24 +++++++++++++----------- server/include/modules.h | 1 - 4 files changed, 18 insertions(+), 44 deletions(-) diff --git a/server/core/adminusers.c b/server/core/adminusers.c index 64ea5f224..e20f9d1c3 100644 --- a/server/core/adminusers.c +++ b/server/core/adminusers.c @@ -26,6 +26,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -119,12 +120,7 @@ char fname[1024], *home; char uname[80], passwd[80]; initialise(); - if ((home = getenv("MAXSCALE_HOME")) != NULL && strlen(home) < 1024){ - sprintf(fname, "%s/etc/passwd", home); - } - else{ - sprintf(fname, "/usr/local/mariadb-maxscale/etc/passwd"); - } + sprintf(fname, "%s/passwd", get_cachedir()); if ((fp = fopen(fname, "r")) == NULL) return NULL; if ((rval = users_alloc()) == NULL) @@ -155,12 +151,7 @@ FILE *fp; char fname[1024], *home, *cpasswd; initialise(); - if ((home = getenv("MAXSCALE_HOME")) != NULL && strlen(home) < 1024){ - sprintf(fname, "%s/etc/passwd", home); - } - else{ - sprintf(fname, "/usr/local/mariadb-maxscale/etc/passwd"); - } + sprintf(fname, "%s/passwd", get_cachedir()); if (users == NULL) { @@ -253,15 +244,8 @@ char* admin_remove_user( /** * Open passwd file and remove user from the file. */ - if ((home = getenv("MAXSCALE_HOME")) != NULL && - strnlen(home,PATH_MAX) < PATH_MAX && - strnlen(home,PATH_MAX) > 0) { - sprintf(fname, "%s/etc/passwd", home); - sprintf(fname_tmp, "%s/etc/passwd_tmp", home); - } else { - sprintf(fname, "/usr/local/mariadb-maxscale/etc/passwd"); - sprintf(fname_tmp, "/usr/local/mariadb-maxscale/etc/passwd_tmp"); - } + sprintf(fname, "%s/passwd", get_cachedir()); + sprintf(fname_tmp, "%s/passwd_tmp", get_cachedir()); /** * Rewrite passwd file from memory. */ diff --git a/server/core/load_utils.c b/server/core/load_utils.c index 9451f6838..7e4a10c37 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -105,17 +105,6 @@ WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) return realsize; } -char* get_maxscale_home(void) -{ - char* home = getenv("MAXSCALE_HOME"); - if (home == NULL) - { - home = "/usr/local/mariadb-maxscale"; - } - return home; -} - - /** * Load the dynamic library related to a gateway module. The routine * will look for library files in the current directory, diff --git a/server/core/maxkeys.c b/server/core/maxkeys.c index 0d5c938ff..6cb4501ec 100644 --- a/server/core/maxkeys.c +++ b/server/core/maxkeys.c @@ -31,6 +31,7 @@ #include #include #include +#include int main(int argc, char **argv) { int arg_count = 3; @@ -52,19 +53,20 @@ int main(int argc, char **argv) return 1; } + if(access("/var/log/maxscale/maxkeys/",F_OK) != 0) + { + if(mkdir("/var/log/maxscale/maxkeys/",0777) == -1) + { + if(errno != EEXIST) + { + fprintf(stderr,"Error: %d - %s",errno,strerror(errno)); + return 1; + } + } + } arg_vector[0] = strdup("logmanager"); arg_vector[1] = strdup("-j"); - - if ((home = getenv("MAXSCALE_HOME")) != NULL) - { - arg_vector[2] = (char*)malloc((strlen(home) + strlen("/log"))*sizeof(char)); - sprintf(arg_vector[2],"%s/log",home); - } - else - { - arg_vector[2] = strdup("/usr/local/mariadb-maxscale/log"); - } - + arg_vector[2] = strdup("/var/log/maxscale/maxkeys"); arg_vector[3] = NULL; skygw_logmanager_init(arg_count,arg_vector); skygw_log_enable(LOGFILE_TRACE); diff --git a/server/include/modules.h b/server/include/modules.h index 51e10b29d..96d322402 100644 --- a/server/include/modules.h +++ b/server/include/modules.h @@ -68,7 +68,6 @@ extern void unload_all_modules(); extern void printModules(); extern void dprintAllModules(DCB *); extern RESULTSET *moduleGetList(); -extern char *get_maxscale_home(void); extern void module_feedback_send(void*); extern void moduleShowFeedbackReport(DCB *dcb); From 9e0a2bfc12f5d962b16f28b023de697f090ef0e7 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 21:38:49 +0300 Subject: [PATCH 17/34] Changed relevant files to use get_cachedir() instead of using the now deprecated MAXSCALE_HOME. --- etc/init.d/maxscale.in | 6 +- etc/ubuntu/init.d/maxscale.in | 2 +- server/core/CMakeLists.txt | 4 +- server/core/gateway.c | 206 +--------------------- server/core/load_utils.c | 3 +- server/core/maxpasswd.c | 11 +- server/core/secrets.c | 10 +- server/core/service.c | 6 +- server/core/test/CMakeLists.txt | 15 -- server/core/test/testadminusers.c | 9 +- server/core/test/testfeedback.c | 13 +- server/include/gwdirs.h.in | 2 +- server/maxscale_binlogserver_template.cnf | 5 +- server/modules/filter/dbfwfilter.c | 12 +- server/modules/filter/test/CMakeLists.txt | 10 -- 15 files changed, 29 insertions(+), 285 deletions(-) diff --git a/etc/init.d/maxscale.in b/etc/init.d/maxscale.in index c8822109c..4ee5ce0f4 100755 --- a/etc/init.d/maxscale.in +++ b/etc/init.d/maxscale.in @@ -38,7 +38,7 @@ _RETVAL_STATUS_OK=0 _RETVAL_STATUS_NOT_RUNNING=3 # Sanity checks. -[ -x $MAXSCALE_HOME/bin/maxscale ] || exit $_RETVAL_NOT_INSTALLED +[ -x @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale ] || exit $_RETVAL_NOT_INSTALLED # Source function library. . /etc/rc.d/init.d/functions @@ -51,7 +51,7 @@ RETVAL=0 start() { echo -n $"Starting MaxScale: " - my_check=`status -p $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale` + my_check=`status -p $MAXSCALE_PIDFILE @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale` CHECK_RET=$? [ $CHECK_RET -eq 0 ] && echo -n " found $my_check" && success && CHECK_RET=0 @@ -62,7 +62,7 @@ start() { if [ $CHECK_RET -ne 0 ]; then sleep 2 - my_check=`status -p $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale` + my_check=`status -p $MAXSCALE_PIDFILE @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale` CHECK_RET=$? [ $CHECK_RET -eq 0 ] && echo -n $my_check && success || failure fi diff --git a/etc/ubuntu/init.d/maxscale.in b/etc/ubuntu/init.d/maxscale.in index 9b8ff84e9..27a73092c 100755 --- a/etc/ubuntu/init.d/maxscale.in +++ b/etc/ubuntu/init.d/maxscale.in @@ -38,7 +38,7 @@ _RETVAL_STATUS_OK=0 _RETVAL_STATUS_NOT_RUNNING=3 # Sanity checks. -[ -x $MAXSCALE_HOME/bin/maxscale ] || exit $_RETVAL_NOT_INSTALLED +[ -x @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale ] || exit $_RETVAL_NOT_INSTALLED ################################# # stop/start/status related vars diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index c952f5a1a..39983e6ff 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -23,11 +23,11 @@ endif() target_link_libraries(maxscale ${EMBEDDED_LIB} ${PCRE_LINK_FLAGS} ${CURL_LIBRARIES} log_manager utils ssl aio pthread crypt dl crypto inih z rt m stdc++) install(TARGETS maxscale DESTINATION ${MAXSCALE_BINDIR}) -add_executable(maxkeys maxkeys.c secrets.c utils.c) +add_executable(maxkeys maxkeys.c secrets.c utils.c gwdirs.c) target_link_libraries(maxkeys log_manager utils pthread crypt crypto) install(TARGETS maxkeys DESTINATION ${MAXSCALE_BINDIR}) -add_executable(maxpasswd maxpasswd.c secrets.c utils.c) +add_executable(maxpasswd maxpasswd.c secrets.c utils.c gwdirs.c) target_link_libraries(maxpasswd log_manager utils pthread crypt crypto) install(TARGETS maxpasswd DESTINATION ${MAXSCALE_BINDIR}) diff --git a/server/core/gateway.c b/server/core/gateway.c index a5ad3e2fe..cf0f41525 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -191,8 +191,6 @@ static bool resolve_maxscale_conf_fname( char** cnf_full_path, char* home_dir, char* cnf_file_arg); -static bool resolve_maxscale_homedir( - char** p_home_dir); static char* check_dir_access(char* dirname,bool,bool); @@ -575,149 +573,6 @@ return_succp: return succp; } - -static bool resolve_maxscale_homedir( - char** p_home_dir) -{ - bool succp = false; - char* tmp; - char* tmp2; - char* log_context = NULL; - - ss_dassert(*p_home_dir == NULL); - - if (*p_home_dir != NULL) - { - log_context = strdup("Command-line argument"); - tmp = NULL; - goto check_home_dir; - } - /*< - * 1. if home dir wasn't specified by a command-line argument, - * read env. variable MAXSCALE_HOME. - */ - if (getenv("MAXSCALE_HOME") != NULL) - { - tmp = strndup(getenv("MAXSCALE_HOME"), PATH_MAX); - get_expanded_pathname(p_home_dir, tmp, NULL); - - if (*p_home_dir != NULL) - { - log_context = strdup("MAXSCALE_HOME"); - goto check_home_dir; - } - free(tmp); - } - else - { - fprintf(stderr, "\n*\n* Warning : MAXSCALE_HOME environment variable " - "is not set.\n*\n"); - LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, - "Warning : MAXSCALE_HOME environment " - "variable is not set."))); - } - /*< - * 2. if home dir wasn't specified in MAXSCALE_HOME, - * try access /etc/MaxScale/ - */ - tmp = strdup("/etc/MaxScale"); - get_expanded_pathname(p_home_dir, tmp, NULL); - - if (*p_home_dir != NULL) - { - log_context = strdup("/etc/MaxScale"); - goto check_home_dir; - } - free(tmp); - /*< - * 3. if /etc/MaxScale/MaxScale.cnf didn't exist or wasn't accessible, home - * isn't specified. Thus, try to access $PWD/MaxScale.cnf . - */ - char *pwd = getenv("PWD"); - tmp = strndup(pwd ? pwd : "PWD_NOT_SET", PATH_MAX); - tmp2 = get_expanded_pathname(p_home_dir, tmp, default_cnf_fname); - free(tmp2); /*< full path isn't needed so simply free it */ - - if (*p_home_dir != NULL) - { - log_context = strdup("Current working directory"); - } - -check_home_dir: - if (*p_home_dir != NULL) - { - if (!file_is_readable(*p_home_dir)) - { - char* tailstr = "MaxScale doesn't have read permission " - "to MAXSCALE_HOME."; - char* logstr = (char*)malloc(strlen(log_context)+ - 1+ - strlen(tailstr)+ - 1); - snprintf(logstr, - strlen(log_context)+ - 1+ - strlen(tailstr)+1, - "%s:%s", - log_context, - tailstr); - print_log_n_stderr(true, true, logstr, logstr, 0); - free(logstr); - goto return_succp; - } - -#if WRITABLE_HOME - if (!file_is_writable(*p_home_dir)) - { - char* tailstr = "MaxScale doesn't have write permission " - "to MAXSCALE_HOME. Exiting."; - char* logstr = (char*)malloc(strlen(log_context)+ - 1+ - strlen(tailstr)+ - 1); - snprintf(logstr, - strlen(log_context)+ - 1+ - strlen(tailstr)+1, - "%s:%s", - log_context, - tailstr); - print_log_n_stderr(true, true, logstr, logstr, 0); - free(logstr); - goto return_succp; - } -#endif - if (!daemon_mode) - { - fprintf(stderr, - "Using %s as MAXSCALE_HOME = %s\n", - log_context, - tmp); - } - succp = true; - goto return_succp; - } - -return_succp: - free (tmp); - - - if (log_context != NULL) - { - free(log_context); - } - - if (!succp) - { - char* logstr = "MaxScale was unable to locate home directory " - "with read and write permissions. \n*\n* Exiting."; - print_log_n_stderr(true, true, logstr, logstr, 0); - usage(); - } - return succp; -} - /** * Check read and write accessibility to a directory. * @param dirname directory to be checked @@ -1042,19 +897,13 @@ static void usage(void) * This is not obvious solution because stderr is often directed to somewhere, * but currently this is the case. * - * The configuration file is by default \/etc/MaxScale.cnf + * The configuration file is by default /etc/maxscale.cnf * The name of configuration file and its location can be specified by * command-line argument. * - * \ is resolved in the following order: - * 1. from '-c ' command-line argument - * 2. from MAXSCALE_HOME environment variable - * 3. /etc/ if MaxScale.cnf is found from there - * 4. current working directory if MaxScale.cnf is found from there - * * \ is resolved in the following order: * 1. from '-f \' command-line argument - * 2. by using default value "MaxScale.cnf" + * 2. by using default value "maxscale.cnf" * */ int main(int argc, char **argv) @@ -1131,56 +980,6 @@ int main(int argc, char **argv) /*< Debug mode, maxscale runs in this same process */ daemon_mode = false; break; - - case 'c': - /*< - * Create absolute path pointing to MaxScale home - * directory. User-provided home directory may be - * either absolute or relative. If latter, it is - * expanded and stored in home_dir if succeed. - */ - if (optarg[0] != '-') - { - struct stat sb; - - if (stat(optarg, &sb) != -1 - && (! S_ISDIR(sb.st_mode))) - { - char* logerr = "Home directory argument " - "identifier \'-c\' was specified but " - "the argument didn't specify a valid " - "a directory."; - print_log_n_stderr(true, true, logerr, logerr, 0); - usage(); - succp = false; - } - else - { - get_expanded_pathname(&home_dir, optarg, NULL); - } - } - - if (home_dir != NULL) - { - /*< - * MAXSCALE_HOME is set. - * It is used to assist in finding the modules - * to be loaded into MaxScale. - */ - setenv("MAXSCALE_HOME", home_dir, 1); - } - else - { - char* logerr = "Home directory argument " - "identifier \'-c\' was specified but " - "the argument didn't specify \n a valid " - "home directory or the argument was " - "missing."; - print_log_n_stderr(true, true, logerr, logerr, 0); - usage(); - succp = false; - } - break; case 'f': /*< @@ -1589,7 +1388,6 @@ int main(int argc, char **argv) sprintf(datadir,"%s",default_datadir); /** * Init Log Manager for MaxScale. - * If $MAXSCALE_HOME is set then write the logs into $MAXSCALE_HOME/log. * The skygw_logmanager_init expects to take arguments as passed to main * and proesses them with getopt, therefore we need to give it a dummy * argv[0] diff --git a/server/core/load_utils.c b/server/core/load_utils.c index 7e4a10c37..5ecbe7f34 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -49,6 +49,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -108,7 +109,7 @@ WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) /** * Load the dynamic library related to a gateway module. The routine * will look for library files in the current directory, - * $MAXSCALE_HOME/modules and /usr/local/mariadb-maxscale/modules. + * the configured folder and /usr/lib64/maxscale. * * @param module Name of the module to load * @param type Type of module, used purely for registration diff --git a/server/core/maxpasswd.c b/server/core/maxpasswd.c index 4da1dbde1..159fbae49 100644 --- a/server/core/maxpasswd.c +++ b/server/core/maxpasswd.c @@ -62,16 +62,7 @@ main(int argc, char **argv) arg_vector[0] = strdup("logmanager"); arg_vector[1] = strdup("-j"); - - if ((home = getenv("MAXSCALE_HOME")) != NULL) - { - arg_vector[2] = (char*)malloc((strlen(home) + strlen("/log"))*sizeof(char)); - sprintf(arg_vector[2],"%s/log",home); - } - else - { - arg_vector[2] = strdup("/usr/local/mariadb-maxscale/log"); - } + arg_vector[2] = strdup("/var/log/maxscale"); arg_vector[3] = NULL; skygw_logmanager_init(arg_count,arg_vector); diff --git a/server/core/secrets.c b/server/core/secrets.c index 3eae2cc48..b0ddc084b 100644 --- a/server/core/secrets.c +++ b/server/core/secrets.c @@ -22,6 +22,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -62,7 +63,7 @@ int i; static MAXKEYS * secrets_readKeys() { -char secret_file[255]; +char secret_file[PATH_MAX+1]; char *home; MAXKEYS *keys; struct stat secret_stats; @@ -70,12 +71,7 @@ int fd; int len; static int reported = 0; - home = getenv("MAXSCALE_HOME"); - - if (home == NULL) { - home = "/usr/local/mariadb-maxscale"; - } - snprintf(secret_file, 255, "%s/etc/.secrets", home); + snprintf(secret_file, PATH_MAX, "%s/.secrets", get_cachedir()); /* Try to access secrets file */ if (access(secret_file, R_OK) == -1) diff --git a/server/core/service.c b/server/core/service.c index d529cc54a..5ba5d539d 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -232,11 +232,7 @@ GWPROTOCOL *funcs; { /* Try loading authentication data from file cache */ char *ptr, path[4097]; - strcpy(path, "/usr/local/mariadb-maxscale"); - if ((ptr = getenv("MAXSCALE_HOME")) != NULL) - { - strncpy(path, ptr, 4096); - } + strcpy(path, get_cachedir()); strncat(path, "/", 4096); strncat(path, service->name, 4096); strncat(path, "/.cache/dbusers", 4096); diff --git a/server/core/test/CMakeLists.txt b/server/core/test/CMakeLists.txt index 626a75f3e..a1933aa0d 100644 --- a/server/core/test/CMakeLists.txt +++ b/server/core/test/CMakeLists.txt @@ -44,19 +44,4 @@ add_test(Internal-TestUsers test_users) add_test(Internal-TestAdminUsers test_adminusers) add_test(Internal-TestMemlog testmemlog) add_test(TestFeedback testfeedback) -set_tests_properties(Internal-TestMySQLUsers - Internal-TestHash - Internal-TestHint - Internal-TestSpinlock - Internal-TestFilter - Internal-TestBuffer - Internal-TestDCB - Internal-TestModutil - Internal-TestPoll - Internal-TestService - Internal-TestServer - Internal-TestUsers - Internal-TestAdminUsers - Internal-TestMemlog - TestFeedback PROPERTIES ENVIRONMENT MAXSCALE_HOME=${CMAKE_BINARY_DIR}/) set_tests_properties(TestFeedback PROPERTIES TIMEOUT 30) diff --git a/server/core/test/testadminusers.c b/server/core/test/testadminusers.c index ae52bd8b7..f9c34e500 100644 --- a/server/core/test/testadminusers.c +++ b/server/core/test/testadminusers.c @@ -30,7 +30,7 @@ #include #include #include - +#include #include @@ -40,7 +40,7 @@ * Test that the username password admin/mariadb is accepted if no users * have been created and that no other users are accepted * - * WARNING: $MAXSCALE_HOME/etc/passwd must be removed before this test is run + * WARNING: The passwd file must be removed before this test is run */ static int test1() @@ -269,9 +269,8 @@ int result = 0; char *home, buf[1024]; /* Unlink any existing password file before running this test */ - if ((home = getenv("MAXSCALE_HOME")) == NULL || strlen(home) >= 1024) - home = "/usr/local/mariadb-maxscale"; - sprintf(buf, "%s/etc/passwd", home); + + sprintf(buf, "%s/passwd", default_cachedir); if(!is_valid_posix_path(buf)) exit(1); if (strcmp(buf, "/etc/passwd") != 0) diff --git a/server/core/test/testfeedback.c b/server/core/test/testfeedback.c index 6549305c3..3b281537e 100644 --- a/server/core/test/testfeedback.c +++ b/server/core/test/testfeedback.c @@ -73,17 +73,8 @@ int main(int argc, char** argv) char* cnf; hkinit(); - home = getenv("MAXSCALE_HOME"); - if(home == NULL) - { - FAILTEST("MAXSCALE_HOME was not defined."); - } - printf("Home: %s\n",home); - - cnf = malloc(strlen(home) + strlen("/etc/MaxScale.cnf") + 1); - strcpy(cnf,home); - strcat(cnf,"/etc/MaxScale.cnf"); + cnf = strdup("/etc/MaxScale.cnf"); printf("Config: %s\n",cnf); @@ -116,4 +107,4 @@ int main(int argc, char** argv) } mysql_library_end(); return 0; -} \ No newline at end of file +} diff --git a/server/include/gwdirs.h.in b/server/include/gwdirs.h.in index e62696aab..bd878bb59 100644 --- a/server/include/gwdirs.h.in +++ b/server/include/gwdirs.h.in @@ -39,5 +39,5 @@ static char* cachedir = NULL; static char* langdir = NULL; char* get_libdir(); - +char* get_cachedir(); #endif diff --git a/server/maxscale_binlogserver_template.cnf b/server/maxscale_binlogserver_template.cnf index dddd74163..f9cc112aa 100644 --- a/server/maxscale_binlogserver_template.cnf +++ b/server/maxscale_binlogserver_template.cnf @@ -1,5 +1,5 @@ # -# Example MaxScale.cnf for the Binlog Server. +# Example maxscale.cnf for the Binlog Server. # # @@ -37,14 +37,13 @@ threads=6 # The MaxScale Binlog Server Service. # # The name of this service will be used as the directory name -# in $MAXSCALE_HOME where the binlogs will be saved. +# in the cache directory where the binlogs will be saved. # If this name is changed, it must be changed in the listener # configuration below. [Binlog_Service] # type must be service # router must be binlogrouter -# (corresponding to the so file in $MAXSCALE_HOME/modules). type=service router=binlogrouter diff --git a/server/modules/filter/dbfwfilter.c b/server/modules/filter/dbfwfilter.c index 9cdc2816f..d796bb3c0 100644 --- a/server/modules/filter/dbfwfilter.c +++ b/server/modules/filter/dbfwfilter.c @@ -2133,15 +2133,13 @@ int main(int argc, char** argv) return 1; } - if((home = getenv("MAXSCALE_HOME")) == NULL) + home = malloc(sizeof(char)*(PATH_MAX+1)); + if(getcwd(home,PATH_MAX) == NULL) { - home = malloc(sizeof(char)*(PATH_MAX+1)); - if(getcwd(home,PATH_MAX) == NULL) - { - free(home); - home = NULL; - } + free(home); + home = NULL; } + printf("Log files written to: %s\n",home?home:"/tpm"); int argc_ = 11; diff --git a/server/modules/filter/test/CMakeLists.txt b/server/modules/filter/test/CMakeLists.txt index 2ad0c2201..4e1006bfb 100644 --- a/server/modules/filter/test/CMakeLists.txt +++ b/server/modules/filter/test/CMakeLists.txt @@ -1,10 +1,3 @@ -aux_source_directory(${CMAKE_SOURCE_DIR}/server/core CORE_ALL) -foreach(VAR ${CORE_ALL}) - if(NOT( (${VAR} MATCHES "max[a-z_]*.c") OR (${VAR} MATCHES "gateway.c"))) - list(APPEND CORE ${VAR}) - endif() -endforeach() - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_executable(harness_ui harness_ui.c harness_common.c) add_executable(harness harness_util.c harness_common.c ${CORE}) @@ -32,6 +25,3 @@ add_test(TestTeeRecursion ${CMAKE_CURRENT_SOURCE_DIR}/tee_recursion.sh ${TEST_HOST} ${TEST_PORT}) -set_tests_properties(TestHintfilter TestRegexfilter TestFwfilter1 TestFwfilter2 TestTeeRecursion -PROPERTIES -ENVIRONMENT MAXSCALE_HOME=${CMAKE_BINARY_DIR}/) From e681d18fdd011c4dbcc0da3403b888cd84832302 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 27 Apr 2015 23:11:49 +0300 Subject: [PATCH 18/34] Split packaging to RPM and DEB cmake files. --- CMakeLists.txt | 71 +++++++++++++++++++---------------------- cmake/package_deb.cmake | 6 ++++ cmake/package_rpm.cmake | 23 +++++++++++++ 3 files changed, 62 insertions(+), 38 deletions(-) create mode 100644 cmake/package_deb.cmake create mode 100644 cmake/package_rpm.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 550724505..eff114eb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,14 @@ message(STATUS "CMake version: ${CMAKE_VERSION}") include(${CMAKE_SOURCE_DIR}/cmake/macros.cmake) enable_testing() -set(INSTALL_LAYOUT "STANDALONE" CACHE STRING "Install layout, options are: STANDALONE, RPM, DEB") +# Packaging builds install to /usr and other builds to /usr/local/mariadb-maxscale +if(PACKAGE) + set(INSTALL_LAYOUT "PACKAGE" CACHE STRING "Install layout, options are: STANDALONE, PACKAGE") +else() + set(INSTALL_LAYOUT "STANDALONE" CACHE STRING "Install layout, options are: STANDALONE, PACKAGE") +endif() + +# Installation prefixes for different layouts if(${INSTALL_LAYOUT} MATCHES "STANDALONE") set(CMAKE_INSTALL_PREFIX "/usr/local/mariadb-maxscale" CACHE PATH "Prefix prepended to install directories.") else() @@ -58,12 +65,12 @@ if(${MAXSCALE_VERSION} MATCHES "-stable") endif() file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/server/include) -configure_file(${CMAKE_SOURCE_DIR}/server/include/version.h.in ${CMAKE_BINARY_DIR}/server/include/version.h) -configure_file(${CMAKE_SOURCE_DIR}/server/include/gwdirs.h.in ${CMAKE_BINARY_DIR}/server/include/gwdirs.h) -configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.h.in ${CMAKE_BINARY_DIR}/server/include/maxscale_test.h) -configure_file(${CMAKE_SOURCE_DIR}/etc/postinst.in ${CMAKE_BINARY_DIR}/postinst) -configure_file(${CMAKE_SOURCE_DIR}/etc/postrm.in ${CMAKE_BINARY_DIR}/postrm) -configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.cnf ${CMAKE_BINARY_DIR}/maxscale.cnf) +configure_file(${CMAKE_SOURCE_DIR}/server/include/version.h.in ${CMAKE_BINARY_DIR}/server/include/version.h @ONLY) +configure_file(${CMAKE_SOURCE_DIR}/server/include/gwdirs.h.in ${CMAKE_BINARY_DIR}/server/include/gwdirs.h @ONLY) +configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.h.in ${CMAKE_BINARY_DIR}/server/include/maxscale_test.h @ONLY) +configure_file(${CMAKE_SOURCE_DIR}/etc/postinst.in ${CMAKE_BINARY_DIR}/postinst @ONLY) +configure_file(${CMAKE_SOURCE_DIR}/etc/postrm.in ${CMAKE_BINARY_DIR}/postrm @ONLY) +configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.cnf ${CMAKE_BINARY_DIR}/maxscale.cnf @ONLY) set(FLAGS "-Wall -Wno-unused-variable -Wno-unused-function -fPIC" CACHE STRING "Compilation flags") set(DEBUG_FLAGS "-ggdb -pthread -pipe -Wformat -fstack-protector --param=ssp-buffer-size=4" CACHE STRING "Debug compilation flags") @@ -81,7 +88,7 @@ if(CMAKE_VERSION VERSION_GREATER 2.6) endif() -IF(DEFINED OLEVEL ) +IF(DEFINED OLEVEL) if((OLEVEL GREATER -1) AND (OLEVEL LESS 4) ) set(FLAGS "${FLAGS} -O${OLEVEL}" CACHE STRING "Compilation flags") message(STATUS "Optimization level at: ${OLEVEL}") @@ -181,7 +188,9 @@ if(WITH_SCRIPTS) endif() endif() +# Only do packaging if configured if(PACKAGE) + # Install the files copied by the postinst script into the share folder install(FILES ${CMAKE_BINARY_DIR}/maxscale DESTINATION ${MAXSCALE_SHAREDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) @@ -194,23 +203,8 @@ if(PACKAGE) if(${CMAKE_VERSION} VERSION_LESS 2.8.12) message(WARNING "CMake version is ${CMAKE_VERSION}. Building of packages requires version 2.8.12 or greater.") else() - # See if we are on a RPM-capable or DEB-capable system - find_program(RPMBUILD rpmbuild) - find_program(DEBBUILD dpkg-buildpackage) - set(CPACK_GENERATOR "TGZ") - if(NOT ( ${RPMBUILD} STREQUAL "RPMBUILD-NOTFOUND" ) ) - message(STATUS "Generating RPM packages") - set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM") - endif() - - if(NOT ( ${DEBBUILD} STREQUAL "DEBBUILD-NOTFOUND" ) ) - set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB") - execute_process(COMMAND dpgk --print-architecture OUTPUT_VARIABLE DEB_ARCHITECTURE) - set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEB_ARCHITECTURE}) - set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) - message(STATUS "Generating DEB packages for ${DEB_ARCHITECTURE}") - endif() + # Generic CPack configuration variables set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MaxScale") set(CPACK_PACKAGE_VERSION_MAJOR "${MAXSCALE_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${MAXSCALE_VERSION_MINOR}") @@ -221,23 +215,25 @@ if(PACKAGE) set(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab") set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/etc/DESCRIPTION) set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") - set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/postinst;{CMAKE_BINARY_DIR}/postrm") - set(CPACK_RPM_PACKAGE_RELEASE ${MAXSCALE_BUILD_NUMBER}) - set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_BINARY_DIR}/postinst) - set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_BINARY_DIR}/postrm) - set(CPACK_RPM_PACKAGE_NAME "maxscale") - set(CPACK_RPM_PACKAGE_VENDOR "MariaDB Corporation Ab") - set(CPACK_RPM_PACKAGE_LICENSE "GPLv2") - set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/etc /etc/ld.so.conf.d /etc/init.d /etc/rc.d/init.d") - set(CPACK_RPM_SPEC_MORE_DEFINE "%define ignore \#") - set(CPACK_RPM_USER_FILELIST "%ignore /etc/init.d") - set(CPACK_RPM_USER_FILELIST "%ignore /etc/ld.so.conf.d") - set(CPACK_RPM_USER_FILELIST "%ignore /etc") + + # See if we are on a RPM-capable or DEB-capable system + find_program(RPMBUILD rpmbuild) + find_program(DEBBUILD dpkg-buildpackage) + set(CPACK_GENERATOR "TGZ") + + if(NOT ( ${RPMBUILD} STREQUAL "RPMBUILD-NOTFOUND" ) ) + include(cmake/package_rpm.cmake) + message(STATUS "Generating RPM packages") + elseif(NOT ( ${DEBBUILD} STREQUAL "DEBBUILD-NOTFOUND" ) ) + include(cmake/package_deb.cmake) + message(STATUS "Generating DEB packages for ${DEB_ARCHITECTURE}") + endif() + include(CPack) endif() endif() -add_custom_target(buildtestsx +add_custom_target(buildtests COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DWITH_SCRIPTS=N ${CMAKE_SOURCE_DIR} COMMAND make COMMENT "Building test suite..." VERBATIM @@ -252,7 +248,6 @@ add_custom_target(testall add_custom_target(testcore COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DWITH_SCRIPTS=N ${CMAKE_SOURCE_DIR} COMMAND make install - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/server/test/MaxScale_test.cnf ${CMAKE_BINARY_DIR}/etc/MaxScale.cnf COMMAND ctest -R Internal COMMENT "Running core test suite..." VERBATIM) diff --git a/cmake/package_deb.cmake b/cmake/package_deb.cmake new file mode 100644 index 000000000..90d66d4bc --- /dev/null +++ b/cmake/package_deb.cmake @@ -0,0 +1,6 @@ +# DEB specific CPack configuration parameters +set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB") +set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/postinst;{CMAKE_BINARY_DIR}/postrm") +execute_process(COMMAND dpgk --print-architecture OUTPUT_VARIABLE DEB_ARCHITECTURE) +set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEB_ARCHITECTURE}) +set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) diff --git a/cmake/package_rpm.cmake b/cmake/package_rpm.cmake new file mode 100644 index 000000000..0f65bcdd2 --- /dev/null +++ b/cmake/package_rpm.cmake @@ -0,0 +1,23 @@ +# RPM specific CPack configuration parameters +set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MaxScale") +set(CPACK_PACKAGE_VERSION_MAJOR "${MAXSCALE_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${MAXSCALE_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${MAXSCALE_VERSION_PATCH}") +set(CPACK_PACKAGE_CONTACT "MariaDB Corporation Ab") +set(CPACK_PACKAGE_FILE_NAME "maxscale-${MAXSCALE_VERSION}") +set(CPACK_PACKAGE_NAME "maxscale") +set(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab") +set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/etc/DESCRIPTION) +set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") +set(CPACK_RPM_PACKAGE_RELEASE ${MAXSCALE_BUILD_NUMBER}) +set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_BINARY_DIR}/postinst) +set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_BINARY_DIR}/postrm) +set(CPACK_RPM_PACKAGE_NAME "maxscale") +set(CPACK_RPM_PACKAGE_VENDOR "MariaDB Corporation Ab") +set(CPACK_RPM_PACKAGE_LICENSE "GPLv2") +set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/etc /etc/ld.so.conf.d /etc/init.d /etc/rc.d/init.d") +set(CPACK_RPM_SPEC_MORE_DEFINE "%define ignore \#") +set(CPACK_RPM_USER_FILELIST "%ignore /etc/init.d") +set(CPACK_RPM_USER_FILELIST "%ignore /etc/ld.so.conf.d") +set(CPACK_RPM_USER_FILELIST "%ignore /etc") From 71531cde3ed0e69d826721ab00e806c91dece731 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 28 Apr 2015 11:09:49 +0300 Subject: [PATCH 19/34] Updated package installation and started documentation update. --- CMakeLists.txt | 1 + .../Getting-Started/Configuration-Guide.md | 14 +++-- cmake/install_layout.cmake | 3 +- cmake/macros.cmake | 62 ------------------- etc/maxscale.service.in | 11 ++++ 5 files changed, 21 insertions(+), 70 deletions(-) create mode 100644 etc/maxscale.service.in diff --git a/CMakeLists.txt b/CMakeLists.txt index eff114eb5..43ede7f92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,7 @@ install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${MAXSCALE_SHAREDIR}) # Install startup scripts and ldconfig files if(WITH_SCRIPTS) configure_file(${CMAKE_SOURCE_DIR}/maxscale.conf.in ${CMAKE_BINARY_DIR}/maxscale.conf @ONLY) + configure_file(${CMAKE_SOURCE_DIR}/etc/maxscale.service.in ${CMAKE_BINARY_DIR}/maxscale.service @ONLY) if(DEB_BASED) configure_file(${CMAKE_SOURCE_DIR}/etc/ubuntu/init.d/maxscale.in ${CMAKE_BINARY_DIR}/maxscale @ONLY) else() diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index 81d3c90e2..3f3dee484 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -1244,7 +1244,7 @@ In addition parameters may be added to define patterns to match against to eithe The top filter is a filter module for MaxScale that monitors every SQL statement that passes through the filter. It measures the duration of that statement, the time between the statement being sent and the first result being returned. The top N times are kept, along with the SQL text itself and a list sorted on the execution times of the query is written to a file upon closure of the client session. -The configuration block for the **top** filter requires the minimal filter options in its section within the `MaxScale.cnf` file, stored in `$MAXSCALE_HOME/etc/MaxScale.cnf`. +The configuration block for the **top** filter requires the minimal filter options in its section within the `MaxScale.cnf` file, stored in `/etc/MaxScale.cnf`. ``` [MyLogFilter] @@ -1258,9 +1258,11 @@ In addition parameters may be added to define patterns to match against to eithe ## Encrypting Passwords -Passwords stored in the MaxScale.cnf file may optionally be encrypted for added security. This is done by creation of an encryption key on installation of MaxScale. Encryption keys may be created manually by executing the maxkeys utility with the argument of the filename to store the key. +Passwords stored in the MaxScale.cnf file may optionally be encrypted for added security. This is done by creation of an encryption key on installation of MaxScale. Encryption keys may be created manually by executing the maxkeys utility with the argument of the filename to store the key. The default location MaxScale stores the keys is `/var/cache/maxscale`. - maxkeys $MAXSCALE_HOME/etc/.secrets +``` +maxkeys /var/cache/maxscale/.secrets +``` Changing the encryption key for MaxScale will invalidate any currently encrypted keys stored in the MaxScale.cnf file. @@ -1352,7 +1354,7 @@ and short notations ## Error Reporting -MaxScale is designed to be executed as a service, therefore all error reports, including configuration errors, are written to the MaxScale error log file. MaxScale will log to a set of files in the directory `$MAXSCALE_HOME/log`, the only exception to this is if the log directory is not writable, in which case a message is sent to the standard error descriptor. +MaxScale is designed to be executed as a service, therefore all error reports, including configuration errors, are written to the MaxScale error log file. By default, MaxScale will log to a set of files in the directory `/var/log/maxscale`, the only exception to this is if the log directory is not writable, in which case a message is sent to the standard error descriptor. ### Troubleshooting @@ -1367,11 +1369,11 @@ Example: ``` [Galera Listener] type=listener -address=192.1681.3.33 +address=192.168.3.33 port=4408 socket=/servers/maxscale/galera.sock ``` -TCP/IP Traffic must be permitted to 192.1681.3.33 port 4408 +TCP/IP Traffic must be permitted to 192.168.3.33 port 4408 For Unix socket, the socket file path (example: `/servers/maxscale/galera.sock`) must be writable by the Unix user MaxScale runs as. diff --git a/cmake/install_layout.cmake b/cmake/install_layout.cmake index 1425b4d49..f7ce45441 100644 --- a/cmake/install_layout.cmake +++ b/cmake/install_layout.cmake @@ -1,8 +1,7 @@ # Set the install layout # Possible values: # STANDALONE - Installs to /usr/local/mariadb-maxscale -# RPM - Installs to /usr -# DEB - Installs to /usr +# PACKAGE - Installs to /usr include(GNUInstallDirs) set(MAXSCALE_LIBDIR ${CMAKE_INSTALL_LIBDIR}/maxscale CACHE PATH "Library installation path") diff --git a/cmake/macros.cmake b/cmake/macros.cmake index 440c3fed5..aaed9cd69 100644 --- a/cmake/macros.cmake +++ b/cmake/macros.cmake @@ -196,68 +196,6 @@ debugmsg("Search returned: ${MYSQL_DIR_LOC}") set(ERRMSG ${ERRMSG_FILE} CACHE FILEPATH "Path to the errmsg.sys file." FORCE) unset(ERRMSG_FILE) - # Find the embedded mysql library - - # if (DEFINED EMBEDDED_LIB) - # if( NOT (IS_DIRECTORY ${EMBEDDED_LIB}) ) - # debugmsg("EMBEDDED_LIB is not a directory: ${EMBEDDED_LIB}") - # if(${CMAKE_VERSION} VERSION_LESS 2.8.12 ) - # set(COMP_VAR PATH) - # else() - # set(COMP_VAR DIRECTORY) - # endif() - # get_filename_component(EMBEDDED_LIB ${EMBEDDED_LIB} ${COMP_VAR}) - # debugmsg("EMBEDDED_LIB directory component: ${EMBEDDED_LIB}") - # endif() - # debugmsg("Searching for the embedded library at: ${EMBEDDED_LIB}") - # endif() - - # if(STATIC_EMBEDDED) - - # debugmsg("Using the static embedded library...") - # set(OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - # set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - # if (DEFINED EMBEDDED_LIB) - # debugmsg("Searching for libmysqld.a at: ${EMBEDDED_LIB}") - # find_library(EMBEDDED_LIB_STATIC libmysqld.a PATHS ${EMBEDDED_LIB} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH) - # else() - # find_library(EMBEDDED_LIB_STATIC libmysqld.a PATH_SUFFIXES mysql mariadb) - # endif() - # debugmsg("Search returned: ${EMBEDDED_LIB_STATIC}") - - # set(EMBEDDED_LIB ${EMBEDDED_LIB_STATIC} CACHE FILEPATH "Path to libmysqld" FORCE) - # set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES}) - - # else() - # debugmsg("Using the dynamic embedded library...") - # set(OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - # set(CMAKE_FIND_LIBRARY_SUFFIXES ".so") - # if (DEFINED EMBEDDED_LIB) - # debugmsg("Searching for libmysqld.so at: ${EMBEDDED_LIB}") - # find_library(EMBEDDED_LIB_DYNAMIC mysqld PATHS ${EMBEDDED_LIB} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH) - # else() - # find_library(EMBEDDED_LIB_DYNAMIC mysqld PATH_SUFFIXES mysql mariadb) - # endif() - # debugmsg("Search returned: ${EMBEDDED_LIB_DYNAMIC}") - # set(EMBEDDED_LIB ${EMBEDDED_LIB_DYNAMIC} CACHE FILEPATH "Path to libmysqld" FORCE) - # set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES}) - - # endif() - - # unset(EMBEDDED_LIB_DYNAMIC) - # unset(EMBEDDED_LIB_STATIC) - # unset(OLD_SUFFIXES) - - # # Inform the user about the embedded library - # if( (${EMBEDDED_LIB} MATCHES "NOTFOUND") OR (${EMBEDDED_LIB} MATCHES "NOTFOUND")) - # set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") - # message(FATAL_ERROR "Library not found: libmysqld. If your install of MySQL is in a non-default location, please provide the location with -DEMBEDDED_LIB=") - # else() - # get_filename_component(EMBEDDED_LIB ${EMBEDDED_LIB} REALPATH) - # message(STATUS "Using embedded library: ${EMBEDDED_LIB}") - # endif() - - # Check which init.d script to install find_file(RPM_FNC functions PATHS /etc/rc.d/init.d) if(${RPM_FNC} MATCHES "RPM_FNC-NOTFOUND") diff --git a/etc/maxscale.service.in b/etc/maxscale.service.in new file mode 100644 index 000000000..56b49d98f --- /dev/null +++ b/etc/maxscale.service.in @@ -0,0 +1,11 @@ +[Unit] +Description=MariaDB MaxScale Database Proxy +After=network.target + +[Service] +Type=forking +PIDFile=/var/run/maxscale/maxscale.pid +ExecStart=@CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale + +[Install] +WantedBy=multi-user.target From 3501ffb689f02d54824291e65eb8473da1c8642d Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 28 Apr 2015 16:39:52 +0300 Subject: [PATCH 20/34] Updated documentation --- .../Getting-Started/Configuration-Guide.md | 2 +- .../Reference/Debug-And-Diagnostic-Support.md | 10 ++-- .../Tutorials/Administration-Tutorial.md | 53 ++++++------------- 3 files changed, 22 insertions(+), 43 deletions(-) diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index 3f3dee484..19d4c2b6e 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -1268,7 +1268,7 @@ Changing the encryption key for MaxScale will invalidate any currently encrypted ### Creating Encrypted Passwords -Encrypted passwords are created by executing the maxpasswd command with the password you require to encrypt as an argument. The environment variable `MAXSCALE_HOME` must be set, or MaxScale must be installed in the default location before maxpasswd can be executed. +Encrypted passwords are created by executing the maxpasswd command with the password you require to encrypt as an argument. maxpasswd MaxScalePw001 61DD955512C39A4A8BC4BB1E5F116705 diff --git a/Documentation/Reference/Debug-And-Diagnostic-Support.md b/Documentation/Reference/Debug-And-Diagnostic-Support.md index 34fda6653..d9bffa268 100644 --- a/Documentation/Reference/Debug-And-Diagnostic-Support.md +++ b/Documentation/Reference/Debug-And-Diagnostic-Support.md @@ -1711,7 +1711,7 @@ User admin already exists. **MaxScale>**** ** -If you should forget or lose the the account details you may simply remove the passwd file in $MAXSCALE_HOME/etc and the system will revert to the default behavior with admin/mariadb as the account. +If you should forget or lose the the account details you may simply remove the passwd file in /var/cache/maxscale and the system will revert to the default behavior with admin/mariadb as the account. ## Enable/disable log @@ -1745,7 +1745,7 @@ MaxScale generates output of its behavior to four distinct logs, error, messages ## Log contents -By default all log files are located in : $MAXSCALE_HOME/log and named as : +By default all log files are located in : /var/log/maxscale and named as : skygw_errW.log, skygw_msgX.log, skygw_traceY.log and skygw_debugZ.log @@ -1837,7 +1837,7 @@ MariaDB Corporation MaxScale /home/jdoe/bin/develop/log/skygw_msg1.log Tue Dec ### Trace log -Trace log includes information about available servers and their states, client sessions, queries being executed, routing decisions and other routing related data. Trace log can be found from the same directory with other logs but it is physically stored elsewhere, to OSs shared memory to reduce the latency caused by logging. The location of physical file is : /dev/shm//skygw_traceX.log where ‘X’ is the same sequence number as in the file name in the $MAXSCALE_HOME/log directory. +Trace log includes information about available servers and their states, client sessions, queries being executed, routing decisions and other routing related data. Trace log can be found from the same directory with other logs but it is physically stored elsewhere, to OSs shared memory to reduce the latency caused by logging. The location of physical file is : /dev/shm//skygw_traceX.log where ‘X’ is the same sequence number as in the file name in the /var/log/maxscale directory. Individual trace log entry looks similar to those in other logs but there is some difference too. Some log entries include a number within square brackets to specify which client session they belong to. For example: @@ -1923,11 +1923,11 @@ In the log, session’s life cycle is covered by annotating its beginning and th The log files are located in -$MAXSCALE_HOME/log +/var/log/maxscale by default. If, however, trace and debug logs are enabled, only a soft link is created there. MaxScale process creates a directory under -/dev/shm/ +/dev/shm/maxscale. where it stores the physical trace and debug log files. Link and physical files share the same name. These logs consume the main memory of the host they run on so it is important to archive or remove them periodically to avoid unnecessary main-memory consumption. diff --git a/Documentation/Tutorials/Administration-Tutorial.md b/Documentation/Tutorials/Administration-Tutorial.md index 894f89f94..943ecaa27 100644 --- a/Documentation/Tutorials/Administration-Tutorial.md +++ b/Documentation/Tutorials/Administration-Tutorial.md @@ -26,43 +26,20 @@ It is also possible to start MaxScale by executing the maxscale command itself, Options may be passed to the MaxScale binary that alter this default behavior, this options are documented in the table below. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SwitchLong OptionDescription
-d--nodaemonRun MaxScale attached to the terminal rather than as a daemon process. This is useful for debugging purposes.
-c--homedir=Ignore the environment variable MAXSCALE_HOME and use the supplied argument instead.
-f--config=Use the filename passed as an argument instead of looking in /etc/MaxScale.cnf
-l|--log=Control where logs are written for the debug and trace level log messages. the default is to write these to a shared memory device, however using the -lfile or --log=file option will forced these to be written to regular files.
-v--versionPrint version information for MaxScale
-?--helpPrint usage information for MaxScale
+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: shm) +`-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) +`-s [yes no]`|`--syslog=[yes no]`|log messages to syslog (default:yes) +`-S [yes no]`|`--maxscalelog=[yes no]`|log messages to MaxScale log (default: yes) +`-v`|`--version`|print version info and exit +`-?`|`--help`|show this help ### Stopping MaxScale @@ -90,6 +67,7 @@ In order to shutdown MaxScale using the maxadmin command you may either connect It is possible to use the maxadmin command to obtain statistics regarding the services that are configured within your MaxScale configuration file. The maxadmin command "list services" will give very basic information regarding the services that are define. This command may be either run in interactive mode or passed on the maxadmin command line. +``` $ maxadmin -pmariadb MaxScale> list services @@ -110,6 +88,7 @@ It is possible to use the maxadmin command to obtain statistics regarding the se --------------------------+----------------------+--------+--------------- MaxScale> +``` It should be noted that network listeners count as a user of the service, therefore there will always be one user per network port in which the service listens. More detail can be obtained by use of the "show service" command which is passed a service name. From 5394b4d0fab6d71272f0f1da595f71c17baf4e69 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 29 Apr 2015 05:42:58 +0300 Subject: [PATCH 21/34] Changed standard installation directory from /usr/local/mariadb-maxscale to /usr/local. --- CMakeLists.txt | 11 +---------- cmake/install_layout.cmake | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43ede7f92..28b3229d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,17 +9,8 @@ message(STATUS "CMake version: ${CMAKE_VERSION}") include(${CMAKE_SOURCE_DIR}/cmake/macros.cmake) enable_testing() -# Packaging builds install to /usr and other builds to /usr/local/mariadb-maxscale +# Packaging builds install to /usr and other builds to /usr/local if(PACKAGE) - set(INSTALL_LAYOUT "PACKAGE" CACHE STRING "Install layout, options are: STANDALONE, PACKAGE") -else() - set(INSTALL_LAYOUT "STANDALONE" CACHE STRING "Install layout, options are: STANDALONE, PACKAGE") -endif() - -# Installation prefixes for different layouts -if(${INSTALL_LAYOUT} MATCHES "STANDALONE") - set(CMAKE_INSTALL_PREFIX "/usr/local/mariadb-maxscale" CACHE PATH "Prefix prepended to install directories.") -else() set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Prefix prepended to install directories.") endif() diff --git a/cmake/install_layout.cmake b/cmake/install_layout.cmake index f7ce45441..c55a25a32 100644 --- a/cmake/install_layout.cmake +++ b/cmake/install_layout.cmake @@ -1,6 +1,6 @@ # Set the install layout # Possible values: -# STANDALONE - Installs to /usr/local/mariadb-maxscale +# STANDALONE - Installs to /usr/local # PACKAGE - Installs to /usr include(GNUInstallDirs) From c035f4b8b75eb9a11b7cea9ef334ba8d2d632083 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 29 Apr 2015 07:03:05 +0300 Subject: [PATCH 22/34] Removed current directory from the module search path. --- server/core/load_utils.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/server/core/load_utils.c b/server/core/load_utils.c index 5ecbe7f34..9d7d69220 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -133,21 +133,17 @@ MODULE_INFO *mod_info = NULL; * * Search of the shared object. */ - snprintf(fname,MAXPATHLEN+1, "./lib%s.so", module); - + + snprintf(fname, MAXPATHLEN+1,"%s/lib%s.so", get_libdir(), module); + if (access(fname, F_OK) == -1) { - snprintf(fname, MAXPATHLEN+1,"%s/lib%s.so", get_libdir(), module); - - if (access(fname, F_OK) == -1) - { - LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, - "Error : Unable to find library for " - "module: %s. Module dir: %s", - module, get_libdir()))); - return NULL; - } + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error : Unable to find library for " + "module: %s. Module dir: %s", + module, get_libdir()))); + return NULL; } if ((dlhandle = dlopen(fname, RTLD_NOW|RTLD_LOCAL)) == NULL) From 416ffea9b76fd45a4d643dcecd8da61d2f2326fb Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 30 Apr 2015 10:37:06 +0300 Subject: [PATCH 23/34] Changed errmsg.sys installation location to /var/lib/maxscale --- CMakeLists.txt | 2 +- server/include/gwdirs.h.in | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 28b3229d8..33627ba15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,7 @@ install(FILES ${CMAKE_BINARY_DIR}/ReleaseNotes.txt DESTINATION ${MAXSCALE_SHARED install(FILES ${CMAKE_BINARY_DIR}/UpgradingToMaxScale110.txt DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES server/maxscale_template.cnf DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES server/maxscale_binlogserver_template.cnf DESTINATION ${MAXSCALE_SHAREDIR}) -install(FILES ${ERRMSG} DESTINATION /usr/share/mysql/english/) +install(FILES ${ERRMSG} DESTINATION ${MAXSCALE_VARDIR}/lib/maxscale) install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${MAXSCALE_SHAREDIR}) diff --git a/server/include/gwdirs.h.in b/server/include/gwdirs.h.in index bd878bb59..ac8fcf4af 100644 --- a/server/include/gwdirs.h.in +++ b/server/include/gwdirs.h.in @@ -29,8 +29,7 @@ static const char* default_logdir = "/var/log/maxscale/"; static const char* default_datadir = "/var/cache/maxscale/"; static const char* default_libdir = "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@"; static const char* default_cachedir = "/var/cache/maxscale/"; -static const char* default_langdir = "/usr/share/mysql/english/"; /*< This is where the MariaDB - * server installs errmsg.sys */ +static const char* default_langdir = "@MAXSCALE_VARDIR@/lib/maxscale/"; static char* configdir = NULL; static char* logdir = NULL; From fb8359b5ca0120f73e1c5be1fa09089f07ac997f Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 6 May 2015 12:34:10 +0300 Subject: [PATCH 24/34] Fixed missing installation of init.d and ldconfig files. --- CMakeLists.txt | 4 ++++ etc/postinst.in | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33627ba15..3e975c4f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,10 @@ if(WITH_SCRIPTS) if(PACKAGE) message(STATUS "maxscale.conf will unpack to: /etc/ld.so.conf.d") message(STATUS "startup scripts will unpack to to: /etc/init.d") + install(FILES ${CMAKE_BINARY_DIR}/maxscale DESTINATION ${MAXSCALE_SHAREDIR} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + install(FILES ${CMAKE_BINARY_DIR}/maxscale.conf DESTINATION ${MAXSCALE_SHAREDIR} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) else() install(FILES ${CMAKE_BINARY_DIR}/maxscale DESTINATION /etc/init.d PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/etc/postinst.in b/etc/postinst.in index 464e240f1..fa0c4271c 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -4,6 +4,6 @@ mkdir -p /var/log/maxscale mkdir -p /var/cache/maxscale mkdir -p /var/run/maxscale mkdir -p @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/ -cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/maxscale /etc/init.d/ -cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/maxscale.conf /etc/ld.so.conf.d/ +cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale /etc/init.d/ +cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.conf /etc/ld.so.conf.d/ /sbin/ldconfig From 63060d123334893a6cef833b72932fd4a2ec138e Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 10 May 2015 06:23:50 +0300 Subject: [PATCH 25/34] Added possibility to run as non-root user. --- server/core/gateway.c | 68 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/server/core/gateway.c b/server/core/gateway.c index cf0f41525..0dbffc637 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -159,6 +159,7 @@ static struct option long_options[] = { {"language",required_argument, 0, 'N'}, {"syslog", required_argument, 0, 's'}, {"maxscalelog",required_argument,0,'S'}, + {"user",required_argument,0,'U'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, '?'}, {0, 0, 0, 0} @@ -193,7 +194,7 @@ static bool resolve_maxscale_conf_fname( char* cnf_file_arg); static char* check_dir_access(char* dirname,bool,bool); - +static int set_user(); /** * Handler for SIGHUP signal. Reload the configuration for the @@ -861,14 +862,16 @@ static void usage(void) " -l, --log=[file|shm] log to file or shared memory (default: shm)\n" " -L, --logdir=PATH path to log file directory\n" " (default: /var/log/maxscale)\n" - " -D, --datadir=PATH path to data directory, stored embedded mysql tables\n" - " (default: /var/cache/maxscale)\n" - " -C, --configdir=PATH path to configuration file directory\n" - " (default: /etc/)\n" - " -B, --libdir=PATH path to module directory\n" - " (default: /usr/lib64/maxscale)\n" " -A, --cachedir=PATH path to cache directory\n" " (default: /var/cache/maxscale)\n" + " -B, --libdir=PATH path to module directory\n" + " (default: /usr/lib64/maxscale)\n" + " -C, --configdir=PATH path to configuration file directory\n" + " (default: /etc/)\n" + " -D, --datadir=PATH path to data directory, stored embedded mysql tables\n" + " (default: /var/cache/maxscale)\n" + " -U, --user=USER run MaxScale as another user.\n" + " The user ID and group ID of this user are used to run MaxScale." " -s, --syslog=[yes|no] log messages to syslog (default:yes)\n" " -S, --maxscalelog=[yes|no] log messages to MaxScale log (default: yes)\n" " -v, --version print version info and exit\n" @@ -939,6 +942,9 @@ int main(int argc, char **argv) datadir_cleanup, write_footer, NULL}; + + + sigemptyset(&sigpipe_mask); sigaddset(&sigpipe_mask, SIGPIPE); progname = *argv; @@ -970,7 +976,7 @@ int main(int argc, char **argv) } } - while ((opt = getopt_long(argc, argv, "dc:f:l:vs:S:?L:D:C:B:", + while ((opt = getopt_long(argc, argv, "dc:f:l:vs:S:?L:D:C:B:U:A:", long_options, &option_index)) != -1) { bool succp = true; @@ -1083,6 +1089,12 @@ int main(int argc, char **argv) syslog_enabled = config_truth_value(optarg); } break; + case 'U': + if(set_user(optarg) != 0) + { + succp = false; + } + break; case '?': usage(); rc = EXIT_SUCCESS; @@ -1931,3 +1943,43 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons return 1; } + +static int set_user(char* user) +{ + errno = 0; + struct passwd *pwname; + int rval; + + pwname = getpwnam(user); + if(pwname == NULL) + { + printf("Error: Failed to retrieve user information for '%s': %d %s\n", + user,errno,errno == 0 ? "User not found" : strerror(errno)); + return -1; + } + + rval = setgid(pwname->pw_gid); + if(rval != 0) + { + printf("Error: Failed to change group to '%d': %d %s\n", + pwname->pw_gid,errno,strerror(errno)); + return rval; + } + + rval = setuid(pwname->pw_uid); + if(rval != 0) + { + printf("Error: Failed to change user to '%s': %d %s\n", + pwname->pw_name,errno,strerror(errno)); + return rval; + } +#ifdef SS_DEBUG + else + { + printf("Running MaxScale as: %s %d:%d\n",pwname->pw_name,pwname->pw_uid,pwname->pw_gid); + } +#endif + + + return rval; +} \ No newline at end of file From 2b457bf372ef9c81d3a29582ff00898dc0299e2b Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 11 May 2015 06:19:06 +0300 Subject: [PATCH 26/34] Updated init.d and systemd scripts. --- cmake/install_layout.cmake | 5 ++--- etc/init.d/maxscale.in | 4 ++-- etc/maxscale.service.in | 2 +- etc/postinst.in | 24 ++++++++++++++++++++---- etc/ubuntu/init.d/maxscale.in | 4 ++-- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/cmake/install_layout.cmake b/cmake/install_layout.cmake index c55a25a32..e25bd0a8d 100644 --- a/cmake/install_layout.cmake +++ b/cmake/install_layout.cmake @@ -1,7 +1,4 @@ # Set the install layout -# Possible values: -# STANDALONE - Installs to /usr/local -# PACKAGE - Installs to /usr include(GNUInstallDirs) set(MAXSCALE_LIBDIR ${CMAKE_INSTALL_LIBDIR}/maxscale CACHE PATH "Library installation path") @@ -9,5 +6,7 @@ set(MAXSCALE_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Executable installation set(MAXSCALE_SHAREDIR ${CMAKE_INSTALL_DATADIR}/maxscale CACHE PATH "Share file installation path, includes licence and readme files") set(MAXSCALE_DOCDIR ${CMAKE_INSTALL_DOCDIR}/maxscale CACHE PATH "Documentation installation path, text versions only") set(MAXSCALE_CONFDIR ${CMAKE_INSTALL_SYSCONFDIR} CACHE PATH "Configuration file installation path, this is not usually needed") + +# This is the only hard-coded absolute path set(MAXSCALE_VARDIR /var CACHE PATH "Data file path (usually /var/)") diff --git a/etc/init.d/maxscale.in b/etc/init.d/maxscale.in index 4ee5ce0f4..70cdf5b3d 100755 --- a/etc/init.d/maxscale.in +++ b/etc/init.d/maxscale.in @@ -21,7 +21,7 @@ # MaxScale PIDFILE and LIB ############################################# -export MAXSCALE_PIDFILE=/var/run/maxscale/maxscale.pid +export MAXSCALE_PIDFILE=@MAXSCALE_VARDIR@/run/maxscale/maxscale.pid export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@/maxscale ############################### @@ -55,7 +55,7 @@ start() { CHECK_RET=$? [ $CHECK_RET -eq 0 ] && echo -n " found $my_check" && success && CHECK_RET=0 - daemon --pidfile $MAXSCALE_PIDFILE @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale >& /dev/null + daemon --pidfile $MAXSCALE_PIDFILE @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale --user=maxscale >& /dev/null RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename diff --git a/etc/maxscale.service.in b/etc/maxscale.service.in index 56b49d98f..50e781f30 100644 --- a/etc/maxscale.service.in +++ b/etc/maxscale.service.in @@ -4,7 +4,7 @@ After=network.target [Service] Type=forking -PIDFile=/var/run/maxscale/maxscale.pid +PIDFile=@MAXSCALE_VARDIR@/run/maxscale/maxscale.pid ExecStart=@CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale [Install] diff --git a/etc/postinst.in b/etc/postinst.in index fa0c4271c..f5b85f537 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -1,9 +1,25 @@ #!/bin/sh -mkdir -p /var/log/maxscale -mkdir -p /var/cache/maxscale -mkdir -p /var/run/maxscale -mkdir -p @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/ + +# Create directories +mkdir -p @MAXSCALE_LIBDIR@ +mkdir -p @MAXSCALE_BINDIR@ +mkdir -p @MAXSCALE_SHAREDIR@ +mkdir -p @MAXSCALE_DOCDIR@ +mkdir -p @MAXSCALE_CONFDIR@ +mkdir -p @MAXSCALE_VARDIR@/log/maxscale +mkdir -p @MAXSCALE_VARDIR@/lib/maxscale +mkdir -p @MAXSCALE_VARDIR@/cache/maxscale +mkdir -p @MAXSCALE_VARDIR@/run/maxscale + +# Create MaxScale user +if [ -f "/etc/passwd" -a "$(grep -c 'maxscale' /etc/passwd)" -eq 0 ] +then + useradd -s -r /bin/false maxscale + groupadd maxscale +fi + +# Copy init.d script and ldconfig file cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale /etc/init.d/ cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.conf /etc/ld.so.conf.d/ /sbin/ldconfig diff --git a/etc/ubuntu/init.d/maxscale.in b/etc/ubuntu/init.d/maxscale.in index 27a73092c..315f16c5d 100755 --- a/etc/ubuntu/init.d/maxscale.in +++ b/etc/ubuntu/init.d/maxscale.in @@ -21,7 +21,7 @@ # MaxScale HOME, PIDFILE, LIB ############################################# -export MAXSCALE_PIDFILE=/var/run/maxscale/maxscale.pid +export MAXSCALE_PIDFILE=@MAXSCALE_VARDIR@/run/maxscale/maxscale.pid export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@/maxscale ############################### @@ -44,7 +44,7 @@ _RETVAL_STATUS_NOT_RUNNING=3 # stop/start/status related vars ################################# NAME=maxscale -DAEMON=@CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale +DAEMON=@CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale --user=maxscale # Source function library. . /lib/lsb/init-functions From 3fcc1778bbda69f5618c188b7881a398f6b58a00 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 12 May 2015 06:43:36 +0300 Subject: [PATCH 27/34] Added changing of directory ownership. --- etc/postinst.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/etc/postinst.in b/etc/postinst.in index f5b85f537..8d81907ed 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -19,6 +19,12 @@ then groupadd maxscale fi +# Change the owner of the directories to maxscale:maxscale +chown maxscale:maxscale @MAXSCALE_VARDIR@/log/maxscale +chown maxscale:maxscale @MAXSCALE_VARDIR@/lib/maxscale +chown maxscale:maxscale @MAXSCALE_VARDIR@/cache/maxscale +chown maxscale:maxscale @MAXSCALE_VARDIR@/run/maxscale + # Copy init.d script and ldconfig file cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale /etc/init.d/ cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.conf /etc/ld.so.conf.d/ From b41130b533c91fcf6d73fe5a1760abf273fb0eea Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 12 May 2015 08:11:10 +0300 Subject: [PATCH 28/34] Fixed the useradd command in the postinst script having he command line arguments in the wrong order. --- etc/postinst.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/postinst.in b/etc/postinst.in index 8d81907ed..e04a34f5f 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -15,7 +15,7 @@ mkdir -p @MAXSCALE_VARDIR@/run/maxscale # Create MaxScale user if [ -f "/etc/passwd" -a "$(grep -c 'maxscale' /etc/passwd)" -eq 0 ] then - useradd -s -r /bin/false maxscale + useradd -r -s /bin/false maxscale groupadd maxscale fi From a6701ee7861ac9bd0e0f51996ca3a09b606dd3e3 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 14 May 2015 15:42:49 +0300 Subject: [PATCH 29/34] Added missing newline to usage output. --- server/core/gateway.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/core/gateway.c b/server/core/gateway.c index 0dbffc637..462d28e8e 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -871,7 +871,7 @@ static void usage(void) " -D, --datadir=PATH path to data directory, stored embedded mysql tables\n" " (default: /var/cache/maxscale)\n" " -U, --user=USER run MaxScale as another user.\n" - " The user ID and group ID of this user are used to run MaxScale." + " The user ID and group ID of this user are used to run MaxScale.\n" " -s, --syslog=[yes|no] log messages to syslog (default:yes)\n" " -S, --maxscalelog=[yes|no] log messages to MaxScale log (default: yes)\n" " -v, --version print version info and exit\n" From e794c0953c0a1f216cebefd0b74417355022aac4 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 19 May 2015 18:17:42 +0300 Subject: [PATCH 30/34] Added systemd script installation --- CMakeLists.txt | 2 ++ etc/postinst.in | 1 + 2 files changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e975c4f7..44516cdfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,6 +174,8 @@ if(WITH_SCRIPTS) PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) install(FILES ${CMAKE_BINARY_DIR}/maxscale.conf DESTINATION ${MAXSCALE_SHAREDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + install(FILES ${CMAKE_BINARY_DIR}/maxscale.service DESTINATION ${MAXSCALE_SHAREDIR} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) else() install(FILES ${CMAKE_BINARY_DIR}/maxscale DESTINATION /etc/init.d PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/etc/postinst.in b/etc/postinst.in index e04a34f5f..dca7215df 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -28,4 +28,5 @@ chown maxscale:maxscale @MAXSCALE_VARDIR@/run/maxscale # Copy init.d script and ldconfig file cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale /etc/init.d/ cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.conf /etc/ld.so.conf.d/ +cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.service /usr/lib/systemd/system /sbin/ldconfig From 6d9765f736ef51baf8b8e2b67f68a4fcf6301300 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 21 May 2015 15:22:18 +0300 Subject: [PATCH 31/34] Added copying of old configuration files to new directories. --- etc/postrm.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/etc/postrm.in b/etc/postrm.in index b1e86fca5..65c0f7116 100755 --- a/etc/postrm.in +++ b/etc/postrm.in @@ -3,4 +3,9 @@ if [ "$1" -eq 0 ] then rm -f /etc/init.d/maxscale rm -f /etc/ld.so.conf.d/maxscale.conf +else + if [ -f "/usr/local/mariadb-maxscale/etc/MaxScale.cnf" ] + then + cp "/usr/local/mariadb-maxscale/etc/MaxScale.cnf" "/etc/maxscale.cnf" + fi fi From 0d85ae66039e52f1407500de18af6d8da461c86d Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Fri, 22 May 2015 11:31:22 +0300 Subject: [PATCH 32/34] Changed data directory to /var/lib/maxscale. --- server/core/adminusers.c | 8 ++++---- server/core/gateway.c | 1 + server/core/gwdirs.c | 10 ++++++++++ server/core/secrets.c | 2 +- server/include/gwdirs.h.in | 4 +++- server/modules/routing/binlog/blr_file.c | 6 +++--- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/server/core/adminusers.c b/server/core/adminusers.c index e20f9d1c3..53734e9cc 100644 --- a/server/core/adminusers.c +++ b/server/core/adminusers.c @@ -120,7 +120,7 @@ char fname[1024], *home; char uname[80], passwd[80]; initialise(); - sprintf(fname, "%s/passwd", get_cachedir()); + sprintf(fname, "%s/passwd", get_datadir()); if ((fp = fopen(fname, "r")) == NULL) return NULL; if ((rval = users_alloc()) == NULL) @@ -151,7 +151,7 @@ FILE *fp; char fname[1024], *home, *cpasswd; initialise(); - sprintf(fname, "%s/passwd", get_cachedir()); + sprintf(fname, "%s/passwd", get_datadir()); if (users == NULL) { @@ -244,8 +244,8 @@ char* admin_remove_user( /** * Open passwd file and remove user from the file. */ - sprintf(fname, "%s/passwd", get_cachedir()); - sprintf(fname_tmp, "%s/passwd_tmp", get_cachedir()); + sprintf(fname, "%s/passwd", get_datadir()); + sprintf(fname_tmp, "%s/passwd_tmp", get_datadir()); /** * Rewrite passwd file from memory. */ diff --git a/server/core/gateway.c b/server/core/gateway.c index 462d28e8e..3ab50609b 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -1047,6 +1047,7 @@ int main(int argc, char **argv) break; case 'D': sprintf(datadir,"%s",optarg); + maxscaledatadir = strdup(optarg); datadir_defined = true; break; case 'C': diff --git a/server/core/gwdirs.c b/server/core/gwdirs.c index 9bf0185cd..1fe8af008 100644 --- a/server/core/gwdirs.c +++ b/server/core/gwdirs.c @@ -17,3 +17,13 @@ char* get_cachedir() { return cachedir?cachedir:(char*)default_cachedir; } + + +/** + * Get the service cache directory + * @return The path to the cache directory + */ +char* get_datadir() +{ + return maxscaledatadir?maxscaledatadir:(char*)default_datadir; +} diff --git a/server/core/secrets.c b/server/core/secrets.c index b0ddc084b..2ec3e75a9 100644 --- a/server/core/secrets.c +++ b/server/core/secrets.c @@ -71,7 +71,7 @@ int fd; int len; static int reported = 0; - snprintf(secret_file, PATH_MAX, "%s/.secrets", get_cachedir()); + snprintf(secret_file, PATH_MAX, "%s/.secrets", get_datadir()); /* Try to access secrets file */ if (access(secret_file, R_OK) == -1) diff --git a/server/include/gwdirs.h.in b/server/include/gwdirs.h.in index ac8fcf4af..66e34426f 100644 --- a/server/include/gwdirs.h.in +++ b/server/include/gwdirs.h.in @@ -26,7 +26,7 @@ static const char* default_cnf_fname = "maxscale.cnf"; static const char* default_configdir = "/etc/"; static const char* default_piddir = "/var/run/maxscale/"; static const char* default_logdir = "/var/log/maxscale/"; -static const char* default_datadir = "/var/cache/maxscale/"; +static const char* default_datadir = "/var/lib/maxscale/"; static const char* default_libdir = "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@"; static const char* default_cachedir = "/var/cache/maxscale/"; static const char* default_langdir = "@MAXSCALE_VARDIR@/lib/maxscale/"; @@ -35,8 +35,10 @@ static char* configdir = NULL; static char* logdir = NULL; static char* libdir = NULL; static char* cachedir = NULL; +static char* maxscaledatadir = NULL; static char* langdir = NULL; char* get_libdir(); +char* get_datadir(); char* get_cachedir(); #endif diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index 32fbad28c..91944eea1 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -79,7 +79,7 @@ struct dirent *dp; if (router->binlogdir == NULL) { - strcpy(path, get_cachedir()); + strcpy(path, get_datadir()); strncat(path,"/",PATH_MAX); strncat(path, router->service->name,PATH_MAX); @@ -658,7 +658,7 @@ blr_cache_response(ROUTER_INSTANCE *router, char *response, GWBUF *buf) char path[PATH_MAX+1], *ptr; int fd; - strcpy(path,get_cachedir()); + strcpy(path,get_datadir()); strncat(path,"/",PATH_MAX); strncat(path, router->service->name, PATH_MAX); @@ -693,7 +693,7 @@ char path[PATH_MAX+1], *ptr; int fd; GWBUF *buf; - strcpy(path, get_cachedir()); + strcpy(path, get_datadir()); strncat(path, "/", PATH_MAX); strncat(path, router->service->name, PATH_MAX); strncat(path, "/.cache/", PATH_MAX); From 72066a4262325545f6ac190ef0abfcda186c5d2c Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Fri, 22 May 2015 14:12:40 +0300 Subject: [PATCH 33/34] Added a conditional for systemd script installation and changed directory rights for the maxscale user. --- etc/postinst.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/etc/postinst.in b/etc/postinst.in index dca7215df..abf2db1ef 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -24,9 +24,16 @@ chown maxscale:maxscale @MAXSCALE_VARDIR@/log/maxscale chown maxscale:maxscale @MAXSCALE_VARDIR@/lib/maxscale chown maxscale:maxscale @MAXSCALE_VARDIR@/cache/maxscale chown maxscale:maxscale @MAXSCALE_VARDIR@/run/maxscale +chmod 0755 @MAXSCALE_VARDIR@/log/maxscale +chmod 0755 @MAXSCALE_VARDIR@/lib/maxscale +chmod 0755 @MAXSCALE_VARDIR@/cache/maxscale +chmod 0755 @MAXSCALE_VARDIR@/run/maxscale # Copy init.d script and ldconfig file cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale /etc/init.d/ cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.conf /etc/ld.so.conf.d/ -cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.service /usr/lib/systemd/system +if [ -d "/usr/lib/systemd/system" ] +then + cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.service /usr/lib/systemd/system +fi /sbin/ldconfig From 04aaaea717214f2cca247cd7a0b494a18efd4d71 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Fri, 22 May 2015 18:26:20 +0300 Subject: [PATCH 34/34] Added 1.2 release notes. --- .../MaxScale-1.2.0-Release-Notes.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Documentation/Release-Notes/MaxScale-1.2.0-Release-Notes.md diff --git a/Documentation/Release-Notes/MaxScale-1.2.0-Release-Notes.md b/Documentation/Release-Notes/MaxScale-1.2.0-Release-Notes.md new file mode 100644 index 000000000..f85382b3c --- /dev/null +++ b/Documentation/Release-Notes/MaxScale-1.2.0-Release-Notes.md @@ -0,0 +1,26 @@ +# MaxScale Release Notes + +## 1.2 GA + +This document details the changes in version 1.2 since the release of the 1.1.1 GA Release of the MaxScale product. + +###***PLEASE NOTICE: MaxScale installation directories have changed in this version*** +The 1.2 version of MaxScale differs from previos versions in its installation layout. Please take great care when upgrading MaxScale from previous versions to version 1.2. An automatic upgrade will not work due to the severe changes in the installation layout. + +## New Features + +### Non-root MaxScale +You can now run MaxScale as any user. The standard installation of a MaxScale package now creates the maxscale user and the maxscale group. + +### FHS-compliant installation +The 1.2 version of MaxScale now complies to the Filesystem Hierarchy Standard. This means that MAXSCALE_HOME is no longer necessary and directories can be moved to different locations. + +A quick list of changes in installation directories and file names: + + * Binaries go into `/usr/bin` + * Configuration files to `/etc` and the configuration file is now lower case: `maxscale.cnf` + * Logs to `/var/log/maxscale` + * The module and library directory have been combined into a single directory in `/usr/lib64/maxscale`. If you have custom modules please make sure they are located there. + * Data directory is `/var/lib/maxscale`. This is the default location for MaxScale-specific data. + * PID file can be found at `/var/run/maxscale` +