Take server destruction into use

The servers can now be destroyed with the `destroy server NAME` maxadmin
command.
This commit is contained in:
Markus Makela 2016-11-10 15:34:22 +02:00
parent 261f5fdc36
commit e67a829daf
3 changed files with 36 additions and 8 deletions

View File

@ -249,7 +249,8 @@ bool server_serialize(SERVER *server);
* This removes any created server configuration files and marks the server removed
* If the server is not in use.
* @param server Server to destroy
* @return True if server was destroyed
*/
void server_destroy(SERVER *server);
bool server_destroy(SERVER *server);
MXS_END_DECLS

View File

@ -1242,8 +1242,10 @@ bool server_serialize(SERVER *server)
return rval;
}
void server_destroy(SERVER *server)
bool server_destroy(SERVER *server)
{
bool rval = false;
if (service_server_in_use(server) || monitor_server_in_use(server))
{
MXS_ERROR("Cannot destroy server '%s' as it is used by at least one "
@ -1265,14 +1267,26 @@ void server_destroy(SERVER *server)
}
else
{
rval = true;
MXS_WARNING("Server '%s' was not created at runtime. Remove the "
"server manually from the correct configuration file.",
server->unique_name);
}
}
else
{
rval = true;
}
server->is_active = false;
if (rval)
{
MXS_NOTICE("Destroyed server '%s' at %s:%u", server->unique_name,
server->name, server->port);
server->is_active = false;
}
}
return rval;
}
bool server_is_ssl_parameter(const char *key)

View File

@ -1023,9 +1023,9 @@ static void createServer(DCB *dcb, char *name, char *address, char *port,
}
else
{
dcb_printf(dcb, "WARNING: The server was added to the runtime "
"configuration but persisting the new server to disk "
"failed. This server will NOT be loaded when MaxScale "
dcb_printf(dcb, "WARNING: The server was added to the runtime \n"
"configuration but persisting the new server to disk \n"
"failed. This server will NOT be loaded when MaxScale \n"
"is restarted. See log file for more details on why it failed.\n");
}
}
@ -1068,7 +1068,20 @@ struct subcommand createoptions[] =
static void destroyServer(DCB *dcb, SERVER *server)
{
dcb_printf(dcb, "Not yet implemented.\n");
/** Do this so that we don't directly access the server. Currently, the
* destruction of a server does not free any memory and the server stays
* valid. */
char name[strlen(server->unique_name) + 1];
strcpy(name, server->unique_name);
if (server_destroy(server))
{
dcb_printf(dcb, "Destroyed server '%s'\n", name);
}
else
{
dcb_printf(dcb, "Failed to destroy server '%s', see log file for more details\n", name);
}
}
struct subcommand destroyoptions[] =
@ -1077,7 +1090,7 @@ struct subcommand destroyoptions[] =
"server", 1, 1, destroyServer,
"Destroy a server",
"Usage: destroy server NAME",
{ARG_TYPE_STRING}
{ARG_TYPE_SERVER}
},
{
EMPTY_OPTION