From: Willy Tarreau Date: Thu, 24 Nov 2016 11:56:01 +0000 (+0100) Subject: REORG: cli: move "{enable|disable} agent" to server.c X-Git-Tag: v1.7.0~32 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=58d9cb7d22c1b0d8239543443131e3e3658375d0;p=haproxy.git REORG: cli: move "{enable|disable} agent" to server.c Also mention that "set server" is preferred now. Note that these were the last enable/disable commands in cli.c. Also remove the now unused expect_server_admin() function. --- diff --git a/src/cli.c b/src/cli.c index 1661317ba..060ee2358 100644 --- a/src/cli.c +++ b/src/cli.c @@ -74,8 +74,6 @@ static const char stats_sock_usage_msg[] = " prompt : toggle interactive mode with prompt\n" " quit : disconnect\n" " set rate-limit : change a rate limiting value\n" - " disable : put a server or frontend in maintenance mode\n" - " enable : re-enable a server or frontend which is in maintenance mode\n" ""; static const char stats_permission_denied_msg[] = @@ -394,52 +392,6 @@ int cli_has_level(struct appctx *appctx, int level) } -/* Expects to find a backend and a server in under the form /, - * and returns the pointer to the server. Otherwise, display adequate error messages - * and returns NULL. This function also expects the stream level to be admin. Note: - * the is modified to remove the '/'. - */ -struct server *expect_server_admin(struct stream *s, struct stream_interface *si, char *arg) -{ - struct appctx *appctx = __objt_appctx(si->end); - struct proxy *px; - struct server *sv; - char *line; - - if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { - appctx->ctx.cli.msg = stats_permission_denied_msg; - appctx->st0 = STAT_CLI_PRINT; - return NULL; - } - - /* split "backend/server" and make point to server */ - for (line = arg; *line; line++) - if (*line == '/') { - *line++ = '\0'; - break; - } - - if (!*line || !*arg) { - appctx->ctx.cli.msg = "Require 'backend/server'.\n"; - appctx->st0 = STAT_CLI_PRINT; - return NULL; - } - - if (!get_backend_server(arg, line, &px, &sv)) { - appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; - appctx->st0 = STAT_CLI_PRINT; - return NULL; - } - - if (px->state == PR_STSTOPPED) { - appctx->ctx.cli.msg = "Proxy is disabled.\n"; - appctx->st0 = STAT_CLI_PRINT; - return NULL; - } - - return sv; -} - /* Processes the stats interpreter on the statistics socket. This function is * called from an applet running in a stream interface. The function returns 1 * if the request was understood, otherwise zero. It sets appctx->st0 to a value @@ -658,46 +610,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line) return 0; } } - else if (strcmp(args[0], "enable") == 0) { - if (strcmp(args[1], "agent") == 0) { - struct server *sv; - - sv = expect_server_admin(s, si, args[2]); - if (!sv) - return 1; - - if (!(sv->agent.state & CHK_ST_CONFIGURED)) { - appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - - sv->agent.state |= CHK_ST_ENABLED; - return 1; - } - else { /* unknown "enable" parameter */ - appctx->ctx.cli.msg = "'enable' only supports 'agent', 'frontend', 'health', and 'server'.\n"; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - } - else if (strcmp(args[0], "disable") == 0) { - if (strcmp(args[1], "agent") == 0) { - struct server *sv; - - sv = expect_server_admin(s, si, args[2]); - if (!sv) - return 1; - - sv->agent.state &= ~CHK_ST_ENABLED; - return 1; - } - else { /* unknown "disable" parameter */ - appctx->ctx.cli.msg = "'disable' only supports 'agent', 'frontend', 'health', and 'server'.\n"; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - } else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */ return 0; } diff --git a/src/server.c b/src/server.c index 57119101f..343927b09 100644 --- a/src/server.c +++ b/src/server.c @@ -3583,6 +3583,22 @@ static int cli_parse_set_maxconn_server(char **args, struct appctx *appctx, void return 1; } +/* parse a "disable agent" command. It always returns 1. */ +static int cli_parse_disable_agent(char **args, struct appctx *appctx, void *private) +{ + struct server *sv; + + if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) + return 1; + + sv = cli_find_server(appctx, args[2]); + if (!sv) + return 1; + + sv->agent.state &= ~CHK_ST_ENABLED; + return 1; +} + /* parse a "disable health" command. It always returns 1. */ static int cli_parse_disable_health(char **args, struct appctx *appctx, void *private) { @@ -3615,6 +3631,28 @@ static int cli_parse_disable_server(char **args, struct appctx *appctx, void *pr return 1; } +/* parse a "enable agent" command. It always returns 1. */ +static int cli_parse_enable_agent(char **args, struct appctx *appctx, void *private) +{ + struct server *sv; + + if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) + return 1; + + sv = cli_find_server(appctx, args[2]); + if (!sv) + return 1; + + if (!(sv->agent.state & CHK_ST_CONFIGURED)) { + appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; + appctx->st0 = STAT_CLI_PRINT; + return 1; + } + + sv->agent.state |= CHK_ST_ENABLED; + return 1; +} + /* parse a "enable health" command. It always returns 1. */ static int cli_parse_enable_health(char **args, struct appctx *appctx, void *private) { @@ -3649,8 +3687,10 @@ static int cli_parse_enable_server(char **args, struct appctx *appctx, void *pri /* register cli keywords */ static struct cli_kw_list cli_kws = {{ },{ + { { "disable", "agent", NULL }, "disable agent : disable agent checks (use 'set server' instead)", cli_parse_disable_agent, NULL }, { { "disable", "health", NULL }, "disable health : disable health checks (use 'set server' instead)", cli_parse_disable_health, NULL }, { { "disable", "server", NULL }, "disable server : disable a server for maintenance (use 'set server' instead)", cli_parse_disable_server, NULL }, + { { "enable", "agent", NULL }, "enable agent : enable agent checks (use 'set server' instead)", cli_parse_enable_agent, NULL }, { { "enable", "health", NULL }, "enable health : enable health checks (use 'set server' instead)", cli_parse_enable_health, NULL }, { { "enable", "server", NULL }, "enable server : enable a disabled server (use 'set server' instead)", cli_parse_enable_server, NULL }, { { "set", "maxconn", "server", NULL }, "set maxconn server : change a server's maxconn setting", cli_parse_set_maxconn_server, NULL },