REORG: cli: move "{enable|disable} frontend" to proxy.c
These are the last frontend-specific actions on the CLI. The function
expect_frontend_admin() which is not used anymore was removed.
diff --git a/src/cli.c b/src/cli.c
index 796287c..09e2520 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -394,36 +394,6 @@
}
-/* 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 @@
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 @@
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;
diff --git a/src/proxy.c b/src/proxy.c
index 1f5a347..6343ac3 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -1488,8 +1488,74 @@
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 },