]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stats: add support for soft stop/soft start in the admin interface
authorWilly Tarreau <w@1wt.eu>
Sun, 3 Jun 2012 22:22:44 +0000 (00:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 3 Jun 2012 22:22:44 +0000 (00:22 +0200)
One important missing feature on the web interface is the ability to perform
a soft stop/soft start. This is now possible.

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

index a287c358220502edd6c81af7a122b4fe51e13d59..3457a2a38173544146a4e9c63f80338697580f97 100644 (file)
@@ -262,6 +262,8 @@ enum {
        ST_ADM_ACTION_NONE = 0,
        ST_ADM_ACTION_DISABLE,
        ST_ADM_ACTION_ENABLE,
+       ST_ADM_ACTION_STOP,
+       ST_ADM_ACTION_START,
 };
 
 /* status codes available for the stats admin page */
index 14d50e1c67c76a82d07c67c23a1e8edb7b976a9d..a01c6ed0de81c0b88a1fb56eabe4e6793c99c81e 100644 (file)
@@ -3171,6 +3171,8 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                        "<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>"
                                        "</select>"
                                        "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
                                        "&nbsp;<input type=\"submit\" value=\"Apply\">"
index 7eeb4f64a20664127efdcaf78a0729ff8150e6c4..c0a66879fc165bbd5f4547a89c6770c5a61798b8 100644 (file)
@@ -2605,6 +2605,12 @@ int http_process_req_stat_post(struct stream_interface *si, struct http_txn *txn
                                else if (strcmp(value, "enable") == 0) {
                                        action = ST_ADM_ACTION_ENABLE;
                                }
+                               else if (strcmp(value, "stop") == 0) {
+                                       action = ST_ADM_ACTION_STOP;
+                               }
+                               else if (strcmp(value, "start") == 0) {
+                                       action = ST_ADM_ACTION_START;
+                               }
                                else {
                                        si->applet.ctx.stats.st_code = STAT_STATUS_ERRP;
                                        goto out;
@@ -2642,6 +2648,38 @@ int http_process_req_stat_post(struct stream_interface *si, struct http_txn *txn
                                                        total_servers++;
                                                }
                                                break;
+                                       case ST_ADM_ACTION_STOP:
+                                       case ST_ADM_ACTION_START:
+                                               if (action == ST_ADM_ACTION_START)
+                                                       sv->uweight = sv->iweight;
+                                               else
+                                                       sv->uweight = 0;
+
+                                               if (px->lbprm.algo & BE_LB_PROP_DYN) {
+                                                       /* we must take care of not pushing the server to full throttle during slow starts */
+                                                       if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
+                                                               sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart;
+                                                       else
+                                                               sv->eweight = BE_WEIGHT_SCALE;
+                                                       sv->eweight *= sv->uweight;
+                                               } else {
+                                                       sv->eweight = sv->uweight;
+                                               }
+
+                                               /* static LB algorithms are a bit harder to update */
+                                               if (px->lbprm.update_server_eweight)
+                                                       px->lbprm.update_server_eweight(sv);
+                                               else if (sv->eweight) {
+                                                       if (px->lbprm.set_server_status_up)
+                                                               px->lbprm.set_server_status_up(sv);
+                                               }
+                                               else {
+                                                       if (px->lbprm.set_server_status_down)
+                                                               px->lbprm.set_server_status_down(sv);
+                                               }
+                                               altered_servers++;
+                                               total_servers++;
+                                               break;
                                        }
                                } else {
                                        /* the server name is unknown or ambiguous (duplicate names) */