]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: Add enable and disable agent unix socket commands
authorSimon Horman <horms@verge.net.au>
Mon, 25 Nov 2013 01:46:39 +0000 (10:46 +0900)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Nov 2013 06:31:16 +0000 (07:31 +0100)
The syntax of this new commands are:

enable agent <backend>/<server>
disable agent <backend>/<server>

These commands allow temporarily stopping and subsequently
re-starting an auxiliary agent check. The effect of this is as follows:

New checks are only initialised when the agent is in the enabled. Thus,
disable agent will prevent any new agent checks from begin initiated until
the agent re-enabled using enable agent.

When an agent is disabled the processing of an auxiliary agent check that
was initiated while the agent was set as enabled is as follows: All
results that would alter the weight, specifically "drain" or a weight
returned by the agent, are ignored. The processing of agent check is
otherwise unchanged.

The motivation for this feature is to allow the weight changing effects
of the agent checks to be paused to allow the weight of a server to be
configured using set weight without being overridden by the agent.

Signed-off-by: Simon Horman <horms@verge.net.au>
doc/configuration.txt
include/types/server.h
src/checks.c
src/dumpstats.c

index 8094babaef3ca4ca03789fd58ccef466bd219933..f54dbd225d855714b5c8cdc788bfec10c68e4087 100644 (file)
@@ -12051,6 +12051,28 @@ clear table <table> [ data.<type> <operator> <value> ] | [ key <key> ]
         $ echo "show table http_proxy" | socat stdio /tmp/sock1
     >>> # table: http_proxy, type: ip, size:204800, used:1
 
+enable agent <backend>/<server>
+  Mark the auxiliary agent check as temporarily stopped.
+
+  In the case where an agent check is being run as a auxiliary check, due
+  to the agent-check parameter of a server directive, new checks are only
+  initialised when the agent is in the enabled. Thus, disable agent will
+  prevent any new agent checks from begin initiated until the agent
+  re-enabled using enable agent.
+
+  When an agent is disabled the processing of an auxiliary agent check that
+  was initiated while the agent was set as enabled is as follows: All
+  results that would alter the weight, specifically "drain" or a weight
+  returned by the agent, are ignored. The processing of agent check is
+  otherwise unchanged.
+
+  The motivation for this feature is to allow the weight changing effects
+  of the agent checks to be paused to allow the weight of a server to be
+  configured using set weight without being overridden by the agent.
+
+  This command is restricted and can only be issued on sockets configured for
+  level "admin".
+
 disable frontend <frontend>
   Mark the frontend as temporarily stopped. This corresponds to the mode which
   is used during a soft restart : the frontend releases the port but can be
@@ -12082,6 +12104,15 @@ disable server <backend>/<server>
   This command is restricted and can only be issued on sockets configured for
   level "admin".
 
+enable agent <backend>/<server>
+  Resume auxiliary agent check that was temporarily stopped.
+
+  See "disable agent" for details of the effect of temporarily starting
+  and stopping an auxiliary agent.
+
+  This command is restricted and can only be issued on sockets configured for
+  level "admin".
+
 enable frontend <frontend>
   Resume a frontend which was temporarily stopped. It is possible that some of
   the listening ports won't be able to bind anymore (eg: if another process
index 51f70de3febe5729a5d0ab4cd1814672edec2899..96c4318fff2105cae2d0c128e57490ac4259a7bf 100644 (file)
@@ -74,6 +74,7 @@
 
 /* check flags */
 #define CHK_STATE_RUNNING      0x0001  /* this check is currently running */
+#define CHK_STATE_DISABLED     0x0002  /* this check is currently administratively disabled */
 
 /* various constants */
 #define SRV_UWGHT_RANGE 256
index 2113c8c36276d66d7b8a2c32c119d20395373bd6..eb8ce81c165362392ee3200a9cccadf55ab589e1 100644 (file)
@@ -836,7 +836,6 @@ static void event_srv_chk_w(struct connection *conn)
        goto out_wakeup;
 }
 
-
 /*
  * This function is used only for server health-checks. It handles the server's
  * reply to an HTTP request, SSL HELLO or MySQL client Auth. It calls
@@ -992,19 +991,36 @@ static void event_srv_chk_r(struct connection *conn)
                short status = HCHK_STATUS_L7RSP;
                const char *desc = "Unknown feedback string";
                const char *down_cmd = NULL;
+               int disabled;
 
                if (!done)
                        goto wait_more_data;
 
                cut_crlf(check->bi->data);
 
+               /*
+                * The agent may have been disabled after a check was
+                * initialised.  If so, ignore weight changes and drain
+                * settings from the agent.  Note that the setting is
+                * always present in the state of the agent the server,
+                * regardless of if the agent is being run as a primary or
+                * secondary check. That is, regardless of if the check
+                * parameter of this function is the agent or check field
+                * of the server.
+                */
+               disabled = check->server->agent.state & CHK_STATE_DISABLED;
+
                if (strchr(check->bi->data, '%')) {
+                       if (disabled)
+                               break;
                        desc = server_parse_weight_change_request(s, check->bi->data);
                        if (!desc) {
                                status = HCHK_STATUS_L7OKD;
                                desc = check->bi->data;
                        }
                } else if (!strcasecmp(check->bi->data, "drain")) {
+                       if (disabled)
+                               break;
                        desc = server_parse_weight_change_request(s, "0%");
                        if (!desc) {
                                desc = "drain";
@@ -1315,10 +1331,14 @@ static struct task *process_chk(struct task *t)
                if (!expired) /* woke up too early */
                        return t;
 
-               /* we don't send any health-checks when the proxy is stopped or when
-                * the server should not be checked.
+               /* we don't send any health-checks when the proxy is
+                * stopped, the server should not be checked or the check
+                * is disabled.
                 */
-               if (!(s->state & SRV_CHECKED) || s->proxy->state == PR_STSTOPPED || (s->state & SRV_MAINTAIN))
+               if (!(s->state & SRV_CHECKED) ||
+                   s->proxy->state == PR_STSTOPPED ||
+                   (s->state & SRV_MAINTAIN) ||
+                   (check->state & CHK_STATE_DISABLED))
                        goto reschedule;
 
                /* we'll initiate a new check */
index 3d60b09e03fb68b560a7c5ae3ed19d4b17c626d0..adac8346fe2616f054a63ccb172543363930281b 100644 (file)
@@ -1294,6 +1294,17 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                }
        }
        else if (strcmp(args[0], "enable") == 0) {
+               if (strcmp(args[1], "agent") == 0) {
+                       struct server *sv;
+
+                       sv = expect_server_admin(s, si, args[2]);
+                       if (!sv)
+                               return 1;
+
+                       sv->agent.state &= ~CHK_STATE_DISABLED;
+
+                       return 1;
+               }
                if (strcmp(args[1], "server") == 0) {
                        struct server *sv;
 
@@ -1355,7 +1366,18 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                }
        }
        else if (strcmp(args[0], "disable") == 0) {
-               if (strcmp(args[1], "server") == 0) {
+               if (strcmp(args[1], "agent") == 0) {
+                       struct server *sv;
+
+                       sv = expect_server_admin(s, si, args[2]);
+                       if (!sv)
+                               return 1;
+
+                       sv->agent.state |= CHK_STATE_DISABLED;
+
+                       return 1;
+               }
+               else if (strcmp(args[1], "server") == 0) {
                        struct server *sv;
 
                        sv = expect_server_admin(s, si, args[2]);