]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: Make 'default-server' support 'backup' keyword.
authorFrédéric Lécaille <flecaille@haproxy.com>
Fri, 10 Mar 2017 10:51:05 +0000 (11:51 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 27 Mar 2017 12:36:11 +0000 (14:36 +0200)
At this time, only 'server' supported 'backup' keyword.
This patch makes also 'default-server' directive support this keyword.
A new keyword 'no-backup' has been added so that to disable 'backup' setting
both in 'server' and 'default-server' directives.

For instance, provided the following sequence of directives:

default-server backup
server srv1
server srv2 no-backup

default-server no-backup
server srv3
server srv4 backup

srv1 and srv4 are declared as backup servers,
srv2 and srv3 are declared as non-backup servers.

src/server.c

index 563d38dbefa3cee1b62a8a7a6f1ff11bea7cb0e1..2b0a5dae5ba42651da92ec061a7a6958c200a22a 100644 (file)
@@ -213,6 +213,14 @@ void srv_dump_kws(char **out)
        }
 }
 
+/* Parse the "backup" server keyword */
+static int srv_parse_backup(char **args, int *cur_arg,
+                            struct proxy *curproxy, struct server *newsrv, char **err)
+{
+       newsrv->flags |= SRV_F_BACKUP;
+       return 0;
+}
+
 /* parse the "id" server keyword */
 static int srv_parse_id(char **args, int *cur_arg, struct proxy *curproxy, struct server *newsrv, char **err)
 {
@@ -245,6 +253,14 @@ static int srv_parse_id(char **args, int *cur_arg, struct proxy *curproxy, struc
        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)
+{
+       newsrv->flags &= ~SRV_F_BACKUP;
+       return 0;
+}
+
 /* Shutdown all connections of a server. The caller must pass a termination
  * code in <why>, which must be one of SF_ERR_* indicating the reason for the
  * shutdown.
@@ -854,7 +870,9 @@ void srv_compute_all_admin_states(struct proxy *px)
  * not enabled.
  */
 static struct srv_kw_list srv_kws = { "ALL", { }, {
+       { "backup",       srv_parse_backup,       0,  1 }, /* Flag as backup server */
        { "id",           srv_parse_id,           1,  0 }, /* set id# of server */
+       { "no-backup",    srv_parse_no_backup,    0,  1 }, /* Flag as non-backup server */
        { NULL, NULL, 0 },
 }};
 
@@ -1145,6 +1163,8 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                        newsrv->use_ssl         = curproxy->defsrv.use_ssl;
                        newsrv->check.use_ssl   = curproxy->defsrv.check.use_ssl;
                        newsrv->check.port      = curproxy->defsrv.check.port;
+                       /* Note: 'flags' field has potentially been already initialized. */
+                       newsrv->flags       |= curproxy->defsrv.flags;
                        if (newsrv->check.port)
                                newsrv->flags |= SRV_F_CHECKPORT;
                        newsrv->check.inter     = curproxy->defsrv.check.inter;
@@ -1503,10 +1523,6 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                                newsrv->flags |= SRV_F_CHECKPORT;
                                cur_arg += 2;
                        }
-                       else if (!defsrv && !strcmp(args[cur_arg], "backup")) {
-                               newsrv->flags |= SRV_F_BACKUP;
-                               cur_arg ++;
-                       }
                        else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) {
                                newsrv->flags |= SRV_F_NON_STICK;
                                cur_arg ++;