mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-02 09:30:36 +00:00
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.
This commit is contained in:
parent
5212d7f24c
commit
15b9e68a78
82
src/cli.c
82
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;
|
||||
|
66
src/proxy.c
66
src/proxy.c
@ -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 },
|
||||
|
Loading…
Reference in New Issue
Block a user