Enable online modification of servers

The address, port, monuser and monpw parameters of an existing server can
be changed at runtime. The support for enabling SSL will come in a later
commit.

Allowing servers to be modified could also be done by destroying and
recreating them. Since the servers are never actually destroyed, it is
better to allow the alteration of the existing ones.
This commit is contained in:
Markus Makela
2016-11-09 05:59:10 +02:00
parent b51af51365
commit 35d2959395
5 changed files with 83 additions and 41 deletions

View File

@ -1063,6 +1063,56 @@ struct subcommand destroyoptions[] =
}
};
static void alterServer(DCB *dcb, SERVER *server, char *key, char *value)
{
bool unknown = false;
if (strcmp(key, "address") == 0)
{
server_update_address(server, value);
}
else if (strcmp(key, "port") == 0)
{
server_update_port(server, atoi(value));
}
else if (strcmp(key, "monuser") == 0)
{
server_update_credentials(server, value, server->monpw);
}
else if (strcmp(key, "monpw") == 0)
{
server_update_credentials(server, server->monuser, value);
}
else if (server_is_ssl_parameter(key))
{
server_update_ssl(server, key, value);
}
else
{
unknown = true;
}
if (unknown)
{
dcb_printf(dcb, "Unknown parameter '%s'", key);
}
}
struct subcommand alteroptions[] =
{
{
"server", 3, 3, alterServer,
"Alter server parameters",
"Usage: alter server NAME KEY VALUE\n"
"This will alter an existing parameter of a server. The accepted values\n"
"for KEY are: 'address', 'port', 'monuser', 'monpw'",
{ARG_TYPE_SERVER, ARG_TYPE_STRING, ARG_TYPE_STRING}
},
{
EMPTY_OPTION
}
};
/**
* The debug command table
*/
@ -1076,6 +1126,7 @@ static struct
{ "remove", removeoptions },
{ "create", createoptions },
{ "destroy", destroyoptions },
{ "alter", alteroptions },
{ "set", setoptions },
{ "clear", clearoptions },
{ "disable", disableoptions },