diff --git a/include/maxscale/service.h b/include/maxscale/service.h index fb0d29c78..37670a5ad 100644 --- a/include/maxscale/service.h +++ b/include/maxscale/service.h @@ -242,6 +242,26 @@ SERVICE* service_find(const char *name); // TODO: Change binlogrouter to use the functions in config_runtime.h void serviceAddBackend(SERVICE *service, SERVER *server); +/** + * @brief Check if a service uses a server + * @param service Service to check + * @param server Server being used + * @return True if service uses the server + */ +bool serviceHasBackend(SERVICE *service, SERVER *server); + +/** + * @brief Check if a service has a listener + * + * @param service Service to check + * @param protocol Listener protocol + * @param address Listener address + * @param port Listener port + * @return True if service has the listener + */ +bool serviceHasListener(SERVICE *service, const char *protocol, + const char* address, unsigned short port); + int serviceGetUser(SERVICE *service, char **user, char **auth); int serviceSetUser(SERVICE *service, char *user, char *auth); bool serviceSetFilters(SERVICE *service, char *filters); diff --git a/server/core/config.c b/server/core/config.c index 2e9009889..5ef1b9ca9 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -3110,7 +3110,7 @@ int create_new_listener(CONFIG_CONTEXT *obj) SSL_LISTENER *ssl_info = make_ssl_structure(obj, true, &error_count); if (socket) { - if (serviceHasProtocol(service, protocol, address, 0)) + if (serviceHasListener(service, protocol, address, 0)) { MXS_ERROR("Listener '%s' for service '%s' already has a socket at '%s.", obj->object, service_name, socket); @@ -3125,7 +3125,7 @@ int create_new_listener(CONFIG_CONTEXT *obj) if (port) { - if (serviceHasProtocol(service, protocol, address, atoi(port))) + if (serviceHasListener(service, protocol, address, atoi(port))) { MXS_ERROR("Listener '%s', for service '%s', already have port %s.", obj->object, diff --git a/server/core/config_runtime.c b/server/core/config_runtime.c index c5900990a..bc02b1dac 100644 --- a/server/core/config_runtime.c +++ b/server/core/config_runtime.c @@ -396,8 +396,6 @@ bool runtime_create_listener(SERVICE *service, const char *name, const char *add const char *ssl_cert, const char *ssl_ca, const char *ssl_version, const char *ssl_depth) { - SSL_LISTENER *ssl = NULL; - bool rval = true; if (addr == NULL || strcasecmp(addr, "default") == 0) { @@ -426,34 +424,42 @@ bool runtime_create_listener(SERVICE *service, const char *name, const char *add unsigned short u_port = atoi(port); - if (ssl_key && ssl_cert && ssl_ca) - { - ssl = create_ssl(name, ssl_key, ssl_cert, ssl_ca, ssl_version, ssl_depth); - - if (ssl == NULL) - { - MXS_ERROR("SSL initialization for listener '%s' failed.", name); - rval = false; - } - } - spinlock_acquire(&crt_lock); - if (rval) - { - const char *print_addr = addr ? addr : "0.0.0.0"; - SERV_LISTENER *listener = serviceCreateListener(service, name, proto, addr, - u_port, auth, auth_opt, ssl); + SSL_LISTENER *ssl = NULL; + bool rval = false; - if (listener && listener_serialize(listener) && serviceLaunchListener(service, listener)) + if (!serviceHasListener(service, proto, addr, u_port)) + { + rval = true; + + if (ssl_key && ssl_cert && ssl_ca) { - MXS_NOTICE("Listener '%s' at %s:%s for service '%s' created", - name, print_addr, port, service->name); + ssl = create_ssl(name, ssl_key, ssl_cert, ssl_ca, ssl_version, ssl_depth); + + if (ssl == NULL) + { + MXS_ERROR("SSL initialization for listener '%s' failed.", name); + rval = false; + } } - else + + if (rval) { - MXS_ERROR("Failed to start listener '%s' at %s:%s.", name, print_addr, port); - rval = false; + const char *print_addr = addr ? addr : "0.0.0.0"; + SERV_LISTENER *listener = serviceCreateListener(service, name, proto, addr, + u_port, auth, auth_opt, ssl); + + if (listener && listener_serialize(listener) && serviceLaunchListener(service, listener)) + { + MXS_NOTICE("Listener '%s' at %s:%s for service '%s' created", + name, print_addr, port, service->name); + } + else + { + MXS_ERROR("Failed to start listener '%s' at %s:%s.", name, print_addr, port); + rval = false; + } } } @@ -514,16 +520,20 @@ bool runtime_create_monitor(const char *name, const char *module) { spinlock_acquire(&crt_lock); bool rval = false; - MONITOR *monitor = monitor_alloc((char*)name, (char*)module); - if (monitor) + if (monitor_find(name) == NULL) { - /** Mark that this monitor was created after MaxScale was started */ - monitor->created_online = true; + MONITOR *monitor = monitor_alloc((char*)name, (char*)module); - if (monitor_serialize(monitor)) + if (monitor) { - rval = true; + /** Mark that this monitor was created after MaxScale was started */ + monitor->created_online = true; + + if (monitor_serialize(monitor)) + { + rval = true; + } } } diff --git a/server/core/maxscale/service.h b/server/core/maxscale/service.h index aa17a1e22..ada5c7c7c 100644 --- a/server/core/maxscale/service.h +++ b/server/core/maxscale/service.h @@ -68,10 +68,8 @@ SERV_LISTENER* serviceCreateListener(SERVICE *service, const char *name, const char *protocol, const char *address, unsigned short port, const char *authenticator, const char *options, SSL_LISTENER *ssl); -int serviceHasProtocol(SERVICE *service, const char *protocol, - const char* address, unsigned short port); + void serviceRemoveBackend(SERVICE *service, const SERVER *server); -bool serviceHasBackend(SERVICE *service, SERVER *server); /** * @brief Serialize a service to a file diff --git a/server/core/service.c b/server/core/service.c index 310fd712f..e34efc7c0 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -708,9 +708,9 @@ SERV_LISTENER* serviceCreateListener(SERVICE *service, const char *name, const c * @param protocol The name of the protocol module * @param address The address to listen on * @param port The port to listen on - * @return TRUE if the protocol/port is already part of the service + * @return True if the protocol/port is already part of the service */ -int serviceHasProtocol(SERVICE *service, const char *protocol, +bool serviceHasListener(SERVICE *service, const char *protocol, const char* address, unsigned short port) { SERV_LISTENER *proto; diff --git a/server/core/test/testservice.c b/server/core/test/testservice.c index 22eac3876..c9aa88d9d 100644 --- a/server/core/test/testservice.c +++ b/server/core/test/testservice.c @@ -72,7 +72,7 @@ test1() ss_info_dassert(serviceCreateListener(service, "TestProtocol", "testprotocol", "localhost", 9876, "MySQLAuth", NULL, NULL), "Add Protocol should succeed"); - ss_info_dassert(0 != serviceHasProtocol(service, "testprotocol", "localhost", 9876), + ss_info_dassert(0 != serviceHasListener(service, "testprotocol", "localhost", 9876), "Service should have new protocol as requested"); return 0; diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.c index bdddbd68e..d64573b6e 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.c @@ -1085,7 +1085,11 @@ static void createListener(DCB *dcb, SERVICE *service, char *name, char *address static void createMonitor(DCB *dcb, const char *name, const char *module) { - if (runtime_create_monitor(name, module)) + if (monitor_find(name)) + { + dcb_printf(dcb, "Monitor '%s' already exists\n", name); + } + else if (runtime_create_monitor(name, module)) { dcb_printf(dcb, "Created monitor '%s'\n", name); }