]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: server: allow 'enable health' only if check configured
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 21 Sep 2021 08:29:09 +0000 (10:29 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 21 Sep 2021 09:50:22 +0000 (11:50 +0200)
Test that checks have been configured on the server before enabling via
the 'enable health' CLI. This mirrors the 'enable agent' command.

Without this, a user can use the command on the server without checks.
This leaves the server in an undefined state. Notably, the stat page
reports the server in check transition.

This condition was left on the following reorg commit.
  2c04eda8b58636ad2ae44e42b1f50f3b5a24a642
  REORG: cli: move "{enable|disable} health" to server.c

This should be backported up to 1.8.

src/server.c

index 8f92a252734d2c5774a1e389c304126334d0e08b..659805e12376650ba8b53010bffb790f56ec57cb 100644 (file)
@@ -4371,6 +4371,9 @@ static int cli_parse_enable_health(char **args, char *payload, struct appctx *ap
        if (!sv)
                return 1;
 
+       if (!(sv->check.state & CHK_ST_CONFIGURED))
+               return cli_err(appctx, "Health check was not configured on this server, cannot enable.\n");
+
        HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
        sv->check.state |= CHK_ST_ENABLED;
        HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);