From: Willy Tarreau Date: Thu, 22 May 2014 16:04:49 +0000 (+0200) Subject: MEDIUM: stats: introduce new actions to simplify admin status management X-Git-Tag: v1.5-dev26~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ed7df90068405faa3185982954ca7de4aaf9e07a;p=thirdparty%2Fhaproxy.git MEDIUM: stats: introduce new actions to simplify admin status management Instead of enabling/disabling maintenance mode and drain mode separately using 4 actions, we now offer 3 simplified actions : - set state to READY - set state to DRAIN - set state to MAINT They have the benefit of reporting the same state as displayed on the page, and of doing the double-switch atomically eg when switching from drain to maint. Note that the old actions are still supported for users running scripts. --- diff --git a/include/types/proto_http.h b/include/types/proto_http.h index e1d04d6da0..f5dd9a3972 100644 --- a/include/types/proto_http.h +++ b/include/types/proto_http.h @@ -307,16 +307,6 @@ enum { HTTP_ERR_SIZE }; -/* Actions available for the stats admin forms */ -enum { - ST_ADM_ACTION_NONE = 0, - ST_ADM_ACTION_DISABLE, - ST_ADM_ACTION_ENABLE, - ST_ADM_ACTION_STOP, - ST_ADM_ACTION_START, - ST_ADM_ACTION_SHUTDOWN, -}; - /* status codes available for the stats admin page */ enum { STAT_STATUS_INIT = 0, diff --git a/src/dumpstats.c b/src/dumpstats.c index cca1d123d8..4e4b657c9a 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -86,6 +86,20 @@ enum { STAT_CLI_O_POOLS, /* dump memory pools */ }; +/* Actions available for the stats admin forms */ +enum { + ST_ADM_ACTION_NONE = 0, + ST_ADM_ACTION_READY, + ST_ADM_ACTION_DRAIN, + ST_ADM_ACTION_MAINT, + ST_ADM_ACTION_SHUTDOWN, + /* these are the ancient actions, still available for compatibility */ + ST_ADM_ACTION_DISABLE, + ST_ADM_ACTION_ENABLE, + ST_ADM_ACTION_STOP, + ST_ADM_ACTION_START, +}; + static int stats_dump_info_to_buffer(struct stream_interface *si); static int stats_dump_pools_to_buffer(struct stream_interface *si); static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess); @@ -3446,10 +3460,9 @@ static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px "Choose the action to perform on the checked servers : " "" "" @@ -4206,7 +4219,20 @@ static int stats_process_http_post(struct stream_interface *si) } } else if (!action && (strcmp(key, "action") == 0)) { - if (strcmp(value, "disable") == 0) { + if (strcmp(value, "ready") == 0) { + action = ST_ADM_ACTION_READY; + } + else if (strcmp(value, "drain") == 0) { + action = ST_ADM_ACTION_DRAIN; + } + else if (strcmp(value, "maint") == 0) { + action = ST_ADM_ACTION_MAINT; + } + else if (strcmp(value, "shutdown") == 0) { + action = ST_ADM_ACTION_SHUTDOWN; + } + /* else these are the old supported methods */ + else if (strcmp(value, "disable") == 0) { action = ST_ADM_ACTION_DISABLE; } else if (strcmp(value, "enable") == 0) { @@ -4218,9 +4244,6 @@ static int stats_process_http_post(struct stream_interface *si) else if (strcmp(value, "start") == 0) { action = ST_ADM_ACTION_START; } - else if (strcmp(value, "shutdown") == 0) { - action = ST_ADM_ACTION_SHUTDOWN; - } else { appctx->ctx.stats.st_code = STAT_STATUS_ERRP; goto out; @@ -4268,6 +4291,21 @@ static int stats_process_http_post(struct stream_interface *si) total_servers++; } break; + case ST_ADM_ACTION_READY: + srv_adm_set_ready(sv); + altered_servers++; + total_servers++; + break; + case ST_ADM_ACTION_DRAIN: + srv_adm_set_drain(sv); + altered_servers++; + total_servers++; + break; + case ST_ADM_ACTION_MAINT: + srv_adm_set_maint(sv); + altered_servers++; + total_servers++; + break; case ST_ADM_ACTION_SHUTDOWN: if (px->state != PR_STSTOPPED) { struct session *sess, *sess_bck;