]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: Add 'no-agent-check' server keyword.
authorFrédéric Lécaille <flecaille@haproxy.com>
Tue, 21 Mar 2017 15:39:15 +0000 (16:39 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 27 Mar 2017 12:37:01 +0000 (14:37 +0200)
This patch adds 'no-agent-check' setting supported both by 'default-server'
and 'server' directives to disable an agent check for a specific server which would
have 'agent-check' set as default value (inherited from 'default-server'
'agent-check' setting), or, on 'default-server' lines, to disable 'agent-check' setting
as default value for any further 'server' declarations.

For instance, provided this configuration:

    default-server agent-check
    server srv1
    server srv2 no-agent-check
    server srv3
    default-server no-agent-check
    server srv4

srv1 and srv3 would have an agent check enabled contrary to srv2 and srv4.

We do not allocate anymore anything when parsing 'default-server' 'agent-check'
setting.

include/types/server.h
src/checks.c
src/server.c

index 781a889ef5745ec537f8378bf3e53ffe93595781..bfaa941159becd18f37b9394a34f8681cbe45638 100644 (file)
@@ -241,6 +241,7 @@ struct server {
        int tcp_ut;                             /* for TCP, user timeout */
 
        int do_check;                           /* temporary variable used during parsing to denote if health checks must be enabled */
+       int do_agent;                           /* temporary variable used during parsing to denote if an auxiliary agent check must be enabled */
        struct check check;                     /* health-check specific configuration */
        struct check agent;                     /* agent specific configuration */
 
index 77d57dc8718b743aaf5bafdd205432f0048f2c58..778fc6acf8c899c29bed38695901ece64cc75956 100644 (file)
@@ -3082,8 +3082,11 @@ const char *init_check(struct check *check, int type)
 void free_check(struct check *check)
 {
        free(check->bi);
+       check->bi = NULL;
        free(check->bo);
+       check->bo = NULL;
        free(check->conn);
+       check->conn = NULL;
 }
 
 void email_alert_free(struct email_alert *alert)
index 8315097ac4dd0e8d23893de3d5ccb8881662575f..eedd8782f0ef8bc6c07ee9cb58a9361629f3d316 100644 (file)
@@ -262,6 +262,14 @@ static int srv_parse_addr(char **args, int *cur_arg,
        return ERR_ALERT | ERR_FATAL;
 }
 
+/* Parse the "agent-check" server keyword */
+static int srv_parse_agent_check(char **args, int *cur_arg,
+                                 struct proxy *curproxy, struct server *newsrv, char **err)
+{
+       newsrv->do_agent = 1;
+       return 0;
+}
+
 /* Parse the "backup" server keyword */
 static int srv_parse_backup(char **args, int *cur_arg,
                             struct proxy *curproxy, struct server *newsrv, char **err)
@@ -401,6 +409,18 @@ static int srv_parse_namespace(char **args, int *cur_arg,
 #endif
 }
 
+/* Parse the "no-agent-check" server keyword */
+static int srv_parse_no_agent_check(char **args, int *cur_arg,
+                                     struct proxy *curproxy, struct server *newsrv, char **err)
+{
+       free_check(&newsrv->agent);
+       newsrv->agent.inter = 0;
+       newsrv->agent.port = 0;
+       newsrv->agent.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED & ~CHK_ST_AGENT;
+       newsrv->do_agent = 0;
+       return 0;
+}
+
 /* Parse the "no-backup" server keyword */
 static int srv_parse_no_backup(char **args, int *cur_arg,
                                struct proxy *curproxy, struct server *newsrv, char **err)
@@ -1341,6 +1361,7 @@ void srv_compute_all_admin_states(struct proxy *px)
  */
 static struct srv_kw_list srv_kws = { "ALL", { }, {
        { "addr",                srv_parse_addr,                1,  1 }, /* IP address to send health to or to probe from agent-check */
+       { "agent-check",         srv_parse_agent_check,         0,  1 }, /* Enable an auxiliary agent check */
        { "backup",              srv_parse_backup,              0,  1 }, /* Flag as backup server */
        { "check",               srv_parse_check,               0,  1 }, /* enable health checks */
        { "check-send-proxy",    srv_parse_check_send_proxy,    0,  1 }, /* enable PROXY protocol for health checks */
@@ -1349,6 +1370,7 @@ static struct srv_kw_list srv_kws = { "ALL", { }, {
        { "enabled",             srv_parse_enabled,             0,  1 }, /* Start the server in 'enabled' state */
        { "id",                  srv_parse_id,                  1,  0 }, /* set id# of server */
        { "namespace",           srv_parse_namespace,           1,  1 }, /* Namespace the server socket belongs to (if supported) */
+       { "no-agent-check",      srv_parse_no_agent_check,      0,  1 }, /* Do not enable any auxiliary agent check */
        { "no-backup",           srv_parse_no_backup,           0,  1 }, /* Flag as non-backup server */
        { "no-check",            srv_parse_no_check,            0,  1 }, /* disable health checks */
        { "no-check-send-proxy", srv_parse_no_check_send_proxy, 0,  1 }, /* disable PROXY protol for health checks */
@@ -1569,7 +1591,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
 
        if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) {  /* server address */
                int cur_arg;
-               int do_agent = 0, defsrv = (*args[0] == 'd');
+               int defsrv = (*args[0] == 'd');
 
                if (!defsrv && curproxy == defproxy) {
                        Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
@@ -1619,7 +1641,6 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                        LIST_INIT(&newsrv->priv_conns);
                        LIST_INIT(&newsrv->idle_conns);
                        LIST_INIT(&newsrv->safe_conns);
-                       do_agent = 0;
                        newsrv->flags = 0;
                        newsrv->admin = 0;
                        newsrv->state = SRV_ST_RUNNING; /* early server setup */
@@ -1746,6 +1767,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                        /* Note: 'flags' field has potentially been already initialized. */
                        newsrv->flags       |= curproxy->defsrv.flags;
                        newsrv->do_check    = curproxy->defsrv.do_check;
+                       newsrv->do_agent    = curproxy->defsrv.do_agent;
                        if (newsrv->check.port)
                                newsrv->flags |= SRV_F_CHECKPORT;
                        newsrv->check.inter     = curproxy->defsrv.check.inter;
@@ -1832,11 +1854,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                }
 
                while (*args[cur_arg]) {
-                       if (!strcmp(args[cur_arg], "agent-check")) {
-                               global.maxsock++;
-                               do_agent = 1;
-                               cur_arg += 1;
-                       } else if (!strcmp(args[cur_arg], "agent-inter")) {
+                       if (!strcmp(args[cur_arg], "agent-inter")) {
                                const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS);
                                if (err) {
                                        Alert("parsing [%s:%d] : unexpected character '%c' in 'agent-inter' argument of server %s.\n",
@@ -2322,7 +2340,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                        global.maxsock++;
                }
 
-               if (do_agent) {
+               if (!defsrv && newsrv->do_agent) {
                        const char *ret;
 
                        if (!newsrv->agent.port) {
@@ -2343,6 +2361,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                        }
 
                        newsrv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT;
+                       global.maxsock++;
                }
 
                if (!defsrv) {