]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: change a server health check port through the stats socket
authorBaptiste Assmann <bedis9@gmail.com>
Wed, 31 Aug 2016 21:26:29 +0000 (23:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 6 Sep 2016 05:39:16 +0000 (07:39 +0200)
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'.

doc/management.txt
src/dumpstats.c

index f559ffc8627fee7e0621acdda68b6826940afd47..d4670d58a4cbd2850d0927f1ca228427cb8fe35a 100644 (file)
@@ -1595,6 +1595,9 @@ set server <backend>/<server> health [ up | stopping | down ]
   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
index b42c07aa9bcb41c1ed9b13ed43862e5364bdb047..fa646c09113f1c9eb523a0e5f36a6de9aa86fc1f 100644 (file)
@@ -1779,6 +1779,26 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                                        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 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                                }
                        }
                        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;