]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stats: introduce new actions to simplify admin status management
authorWilly Tarreau <w@1wt.eu>
Thu, 22 May 2014 16:04:49 +0000 (18:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 23 May 2014 12:29:11 +0000 (14:29 +0200)
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.

include/types/proto_http.h
src/dumpstats.c

index e1d04d6da096f830226fe47a9e55af0376563914..f5dd9a39721024bfb142848c9929b64cd2d91261 100644 (file)
@@ -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,
index cca1d123d8c2653a0b1df067d0c59ddd3919ef1d..4e4b657c9a5ddc3018b5c774af8443bc5a4c42b9 100644 (file)
@@ -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 : "
                              "<select name=action>"
                              "<option value=\"\"></option>"
-                             "<option value=\"disable\">Disable</option>"
-                             "<option value=\"enable\">Enable</option>"
-                             "<option value=\"stop\">Soft Stop</option>"
-                             "<option value=\"start\">Soft Start</option>"
+                             "<option value=\"ready\">Set state to READY</option>"
+                             "<option value=\"drain\">Set state to DRAIN</option>"
+                             "<option value=\"maint\">set state to MAINT</option>"
                              "<option value=\"shutdown\">Kill Sessions</option>"
                              "</select>"
                              "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
@@ -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;