From a0f905bbe932b236f786115994bb3ea74a69ba7b Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 24 Aug 2016 13:51:24 +0300 Subject: [PATCH] Make maxscaled upgrade friendlier Currently, if the address/port information of a maxscaled protocol listener is not updated to socket when MaxScale is upgraded to 2.0, maxscaled would not start, with the effect of a user loosing maxadmin after an upgrade. After this change, if address/port information is detected, a warning is logged and the default socket path is used. That way, maxadmin will still be usable after an upgrade, even if the address/port information is not updated. --- server/modules/protocol/maxscaled.c | 37 ++++++++++++++++++----------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/server/modules/protocol/maxscaled.c b/server/modules/protocol/maxscaled.c index db10f977d..58d5b8518 100644 --- a/server/modules/protocol/maxscaled.c +++ b/server/modules/protocol/maxscaled.c @@ -349,7 +349,7 @@ static int maxscaled_close(DCB *dcb) */ static int maxscaled_listen(DCB *listener, char *config) { - char *socket_path; + char *socket_path = NULL; /* check for default UNIX socket */ if (strncmp(config, MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG, MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG_LEN) == 0) @@ -358,19 +358,28 @@ static int maxscaled_listen(DCB *listener, char *config) } else { - socket_path = config; + const char* colon = strchr(config, ':'); + ss_dassert(colon); + const char* port = colon + 1; + + if (*port == '0') + { + // It seems "socket=socket-path" has been specified. + + // The colon etc. will be stripped away in dcb_listen_create_socket_unix. + socket_path = config; + } + else + { + MXS_WARNING("The 'maxscaled' protocol can only be used with a domain socket, but " + "it seems to have been configured with a socket and port: %s. " + "Using the default socket path instead: %s. " + "Remove all 'port' and 'address' entries from maxscaled protocol " + "listeners and replace with 'socket=default' or 'socket=path-to-socket'.", + config, MAXADMIN_DEFAULT_SOCKET); + socket_path = MAXADMIN_DEFAULT_SOCKET; + } } - /* check for UNIX socket path*/ - if (strchr(socket_path,'/') == NULL) - { - MXS_ERROR("Failed to start listening on '%s' with 'MaxScale Admin' protocol," - " only UNIX domain sockets are supported. Remove all 'port' and 'address'" - " parameters from this listener and add 'socket=default' to enable UNIX domain sockets.", socket_path); - return -1; - } - else - { - return (dcb_listen(listener, socket_path, "MaxScale Admin") < 0) ? 0 : 1; - } + return (dcb_listen(listener, socket_path, "MaxScale Admin") < 0) ? 0 : 1; }