From: Amaury Denoyelle Date: Mon, 21 Sep 2026 12:04:20 +0000 (+0200) Subject: MINOR: cli: implement wait srv-unknown X-Git-Tag: v3.5-dev9~13 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=3eec34e10f147946d202fedf146d3e9da7810353;p=haproxy.git MINOR: cli: implement wait srv-unknown Define a new CLI wait condition named "srv-unknown". This will report if the server name is currently not used by an instance in a specific backend. An error is immediately reported if a matching instance is found, unless it is flagged for background deletion. Typically, this is useful after CLI "purge server" to detect the deletion completion and before creating a new instance via "add server". --- diff --git a/doc/management.txt b/doc/management.txt index 7d41abd68..fc3270bb0 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -4756,6 +4756,12 @@ wait { -h | } [ [...]] everything is OK before the delay, a success is returned and the operation is terminated. + - srv-unknown / : this will wait for the specified server name + to be available for a new instance to be created. This will fail if the + server already exists, unless if it is flagged for background deletion, in + which case a success will be returned if the deletion is completed before + the delay. + The default unit for the delay is milliseconds, though other units are accepted if suffixed with the usual timer units (us, ms, s, m, h, d). When used with the 'socat' utility, do not forget to extend socat's close timeout diff --git a/include/haproxy/cli-t.h b/include/haproxy/cli-t.h index ddbcd02cc..42bc6ce09 100644 --- a/include/haproxy/cli-t.h +++ b/include/haproxy/cli-t.h @@ -102,6 +102,7 @@ enum cli_wait_err { enum cli_wait_cond { CLI_WAIT_COND_NONE, // no condition to wait on CLI_WAIT_COND_SRV_UNUSED,// wait for server to become unused + CLI_WAIT_COND_SRV_UNKNWN,// wait for server name to be available CLI_WAIT_COND_BE_UNUSED, // wait for backend to become unused }; diff --git a/src/cli.c b/src/cli.c index a2fe4c35b..f61c7d506 100644 --- a/src/cli.c +++ b/src/cli.c @@ -2467,6 +2467,9 @@ static int cli_parse_wait(char **args, char *payload, struct appctx *appctx, voi if (strcmp(args[2], "srv-removable") == 0) { ctx->cond = CLI_WAIT_COND_SRV_UNUSED; } + else if (strcmp(args[2], "srv-unknown") == 0) { + ctx->cond = CLI_WAIT_COND_SRV_UNKNWN; + } else if (strcmp(args[2], "be-removable") == 0) { ctx->cond = CLI_WAIT_COND_BE_UNUSED; } @@ -2480,6 +2483,7 @@ static int cli_parse_wait(char **args, char *payload, struct appctx *appctx, voi " duration. Supported conditions are:\n" " - : by default, just sleep for the specified duration.\n" " - srv-removable / : wait for this server to become removable.\n" + " - srv-unknown / : wait for this server name to be available.\n" " - be-removable : wait for this backend to become removable.\n" ""; @@ -2490,7 +2494,8 @@ static int cli_parse_wait(char **args, char *payload, struct appctx *appctx, voi } switch (ctx->cond) { - case CLI_WAIT_COND_SRV_UNUSED: { + case CLI_WAIT_COND_SRV_UNUSED: + case CLI_WAIT_COND_SRV_UNKNWN: { const char *bename, *svname; if (!*args[3]) @@ -2570,6 +2575,24 @@ static int cli_io_handler_wait(struct appctx *appctx) } /* let's check the timer */ } + else if (ctx->cond == CLI_WAIT_COND_SRV_UNKNWN) { + struct proxy *px; + struct server *srv; + + px = proxy_be_by_name(ctx->args[0]); + srv = px ? server_find(px, ctx->args[1]) : NULL; + if (!px || !srv) { + /* immediate success */ + ctx->error = CLI_WAIT_ERR_DONE; + return 1; + } + else if (!(srv->flags & SRV_F_TO_PURGE)) { + /* unrecoverable failure */ + ctx->error = CLI_WAIT_ERR_FAIL; + ctx->msg = "Server not scheduled for purge.\n"; + return 1; + } + } /* and here we recalculate the new wait time or abort */ left = tick_remain(now_ms, ctx->deadline);