MINOR: cli: change a server health check port through the stats socket
Introduction of a new CLI command "set server <srv> check-port <port>' to
allow admins to change a server's health check port at run time.
This changes the equivalent of the configuration server parameter
called 'port'.
diff --git a/doc/management.txt b/doc/management.txt
index f559ffc..d4670d5 100644
--- a/doc/management.txt
+++ b/doc/management.txt
@@ -1595,6 +1595,9 @@
switch a server's state regardless of some slow health checks for example.
Note that the change is propagated to tracking servers if any.
+set server <backend>/<server> check-port <port>
+ Change the port used for health checking to <port>
+
set server <backend>/<server> state [ ready | drain | maint ]
Force a server's administrative state to a new state. This can be useful to
disable load balancing and/or any traffic to a server. Setting the state to
diff --git a/src/dumpstats.c b/src/dumpstats.c
index b42c07a..fa646c0 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -1779,6 +1779,26 @@
appctx->st0 = STAT_CLI_PRINT;
}
}
+ else if (strcmp(args[3], "check-port") == 0) {
+ int i = 0;
+ if (strl2irc(args[4], strlen(args[4]), &i) != 0) {
+ appctx->ctx.cli.msg = "'set server <srv> check-port' expects an integer as argument.\n";
+ appctx->st0 = STAT_CLI_PRINT;
+ }
+ if ((i < 0) || (i > 65535)) {
+ appctx->ctx.cli.msg = "provided port is not valid.\n";
+ appctx->st0 = STAT_CLI_PRINT;
+ }
+ /* prevent the update of port to 0 if MAPPORTS are in use */
+ if ((sv->flags & SRV_F_MAPPORTS) && (i == 0)) {
+ appctx->ctx.cli.msg = "can't unset 'port' since MAPPORTS is in use.\n";
+ appctx->st0 = STAT_CLI_PRINT;
+ return 1;
+ }
+ sv->check.port = i;
+ appctx->ctx.cli.msg = "health check port updated.\n";
+ appctx->st0 = STAT_CLI_PRINT;
+ }
else if (strcmp(args[3], "addr") == 0) {
warning = server_parse_addr_change_request(sv, args[4], "stats command");
if (warning) {
@@ -1787,7 +1807,7 @@
}
}
else {
- appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state', 'weight' and 'addr'.\n";
+ appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state', 'weight', 'addr' and 'check-port'.\n";
appctx->st0 = STAT_CLI_PRINT;
}
return 1;