From: Willy Tarreau Date: Thu, 24 Nov 2016 10:13:06 +0000 (+0100) Subject: REORG: cli: move "shutdown frontend" to proxy.c X-Git-Tag: v1.7.0~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5212d7f24c378bc2f2cd7b50493d7073e0a5a700;p=thirdparty%2Fhaproxy.git REORG: cli: move "shutdown frontend" to proxy.c Now we don't have any "shutdown" commands left in cli.c. --- diff --git a/src/cli.c b/src/cli.c index ea9765c897..796287c5ae 100644 --- a/src/cli.c +++ b/src/cli.c @@ -76,7 +76,6 @@ static const char stats_sock_usage_msg[] = " 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" - " shutdown : kill a session or a frontend (eg:to release listening ports)\n" ""; static const char stats_permission_denied_msg[] = @@ -827,33 +826,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line) return 1; } } - else if (strcmp(args[0], "shutdown") == 0) { - if (strcmp(args[1], "frontend") == 0) { - struct proxy *px; - - px = expect_frontend_admin(s, si, args[2]); - if (!px) - return 1; - - if (px->state == PR_STSTOPPED) { - appctx->ctx.cli.msg = "Frontend was already shut down.\n"; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - - Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", - px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); - send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", - px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); - stop_proxy(px); - return 1; - } - else { /* unknown "disable" parameter */ - appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\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/proxy.c b/src/proxy.c index 7d33442d4e..1f5a347a67 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1462,11 +1462,38 @@ static int cli_parse_set_maxconn_frontend(char **args, struct appctx *appctx, vo return 1; } +/* Parses the "shutdown frontend" directive, it always returns 1 */ +static int cli_parse_shutdown_frontend(char **args, struct appctx *appctx, void *private) +{ + struct proxy *px; + + if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) + return 1; + + px = cli_find_frontend(appctx, args[2]); + if (!px) + return 1; + + if (px->state == PR_STSTOPPED) { + appctx->ctx.cli.msg = "Frontend was already shut down.\n"; + appctx->st0 = STAT_CLI_PRINT; + return 1; + } + + Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", + px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); + send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", + px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); + stop_proxy(px); + return 1; +} + /* register cli keywords */ static struct cli_kw_list cli_kws = {{ },{ { { "set", "maxconn", "frontend", NULL }, "set maxconn frontend : change a frontend's maxconn setting", cli_parse_set_maxconn_frontend, NULL }, { { "show","servers", "state", NULL }, "show servers state [id]: dump volatile server information (for backend )", cli_parse_show_servers, cli_io_handler_servers_state }, { { "show", "backend", NULL }, "show backend : list backends in the current running config", cli_parse_show_backend, cli_io_handler_show_backend }, + { { "shutdown", "frontend", NULL }, "shutdown frontend : stop a specific frontend", cli_parse_shutdown_frontend, NULL, NULL }, {{},} }};