]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: cli: move "{enable|disable} frontend" to proxy.c
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 10:55:28 +0000 (11:55 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 15:59:28 +0000 (16:59 +0100)
These are the last frontend-specific actions on the CLI. The function
expect_frontend_admin() which is not used anymore was removed.

src/cli.c
src/proxy.c

index 796287c5ae71bc4d276d418dc21c257f0a02c44b..09e2520513936c9263e7f9f9bdad7248a7077921 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -394,36 +394,6 @@ int cli_has_level(struct appctx *appctx, int level)
 }
 
 
-/* Expects to find a frontend named <arg> and returns it, otherwise displays various
- * adequate error messages and returns NULL. This function also expects the stream
- * level to be admin.
- */
-static struct proxy *expect_frontend_admin(struct stream *s, struct stream_interface *si, const char *arg)
-{
-       struct appctx *appctx = __objt_appctx(si->end);
-       struct proxy *px;
-
-       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;
-       }
-
-       if (!*arg) {
-               appctx->ctx.cli.msg = "A frontend name is expected.\n";
-               appctx->st0 = STAT_CLI_PRINT;
-               return NULL;
-       }
-
-       px = proxy_fe_by_name(arg);
-       if (!px) {
-               appctx->ctx.cli.msg = "No such frontend.\n";
-               appctx->st0 = STAT_CLI_PRINT;
-               return NULL;
-       }
-       return px;
-}
-
 /* Expects to find a backend and a server in <arg> under the form <backend>/<server>,
  * 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:
@@ -731,32 +701,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                        srv_adm_set_ready(sv);
                        return 1;
                }
-               else 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 previously shut down, cannot enable.\n";
-                               appctx->st0 = STAT_CLI_PRINT;
-                               return 1;
-                       }
-
-                       if (px->state != PR_STPAUSED) {
-                               appctx->ctx.cli.msg = "Frontend is already enabled.\n";
-                               appctx->st0 = STAT_CLI_PRINT;
-                               return 1;
-                       }
-
-                       if (!resume_proxy(px)) {
-                               appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
-                               appctx->st0 = STAT_CLI_PRINT;
-                               return 1;
-                       }
-                       return 1;
-               }
                else { /* unknown "enable" parameter */
                        appctx->ctx.cli.msg = "'enable' only supports 'agent', 'frontend', 'health', and 'server'.\n";
                        appctx->st0 = STAT_CLI_PRINT;
@@ -794,32 +738,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                        srv_adm_set_maint(sv);
                        return 1;
                }
-               else 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 previously shut down, cannot disable.\n";
-                               appctx->st0 = STAT_CLI_PRINT;
-                               return 1;
-                       }
-
-                       if (px->state == PR_STPAUSED) {
-                               appctx->ctx.cli.msg = "Frontend is already disabled.\n";
-                               appctx->st0 = STAT_CLI_PRINT;
-                               return 1;
-                       }
-
-                       if (!pause_proxy(px)) {
-                               appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
-                               appctx->st0 = STAT_CLI_PRINT;
-                               return 1;
-                       }
-                       return 1;
-               }
                else { /* unknown "disable" parameter */
                        appctx->ctx.cli.msg = "'disable' only supports 'agent', 'frontend', 'health', and 'server'.\n";
                        appctx->st0 = STAT_CLI_PRINT;
index 1f5a347a6789b62bfe1b51641b70aef9766c7bd9..6343ac33aa3e1565cdcc17eee4d637b86c98c8b4 100644 (file)
@@ -1488,8 +1488,74 @@ static int cli_parse_shutdown_frontend(char **args, struct appctx *appctx, void
        return 1;
 }
 
+/* Parses the "disable frontend" directive, it always returns 1 */
+static int cli_parse_disable_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 previously shut down, cannot disable.\n";
+               appctx->st0 = STAT_CLI_PRINT;
+               return 1;
+       }
+
+       if (px->state == PR_STPAUSED) {
+               appctx->ctx.cli.msg = "Frontend is already disabled.\n";
+               appctx->st0 = STAT_CLI_PRINT;
+               return 1;
+       }
+
+       if (!pause_proxy(px)) {
+               appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
+               appctx->st0 = STAT_CLI_PRINT;
+               return 1;
+       }
+       return 1;
+}
+
+/* Parses the "enable frontend" directive, it always returns 1 */
+static int cli_parse_enable_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 previously shut down, cannot enable.\n";
+               appctx->st0 = STAT_CLI_PRINT;
+               return 1;
+       }
+
+       if (px->state != PR_STPAUSED) {
+               appctx->ctx.cli.msg = "Frontend is already enabled.\n";
+               appctx->st0 = STAT_CLI_PRINT;
+               return 1;
+       }
+
+       if (!resume_proxy(px)) {
+               appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
+               appctx->st0 = STAT_CLI_PRINT;
+               return 1;
+       }
+       return 1;
+}
+
 /* register cli keywords */
 static struct cli_kw_list cli_kws = {{ },{
+       { { "disable", "frontend",  NULL }, "disable frontend : temporarily disable specific frontend", cli_parse_disable_frontend, NULL, NULL },
+       { { "enable", "frontend",  NULL }, "enable frontend : re-enable specific frontend", cli_parse_enable_frontend, NULL, NULL },
        { { "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 },