REORG: cli: move "shutdown frontend" to proxy.c
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 10:13:06 +0000 (11:13 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 15:59:28 +0000 (16:59 +0100)
Now we don't have any "shutdown" commands left in cli.c.

src/cli.c
src/proxy.c

index ea9765c..796287c 100644 (file)
--- 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;
        }
index 7d33442..1f5a347 100644 (file)
@@ -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 <id>)", 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 },
        {{},}
 }};