MEDIUM: peers: add the ability to disable a peers section

Sometimes it's very hard to disable the use of peers because an empty
section is not valid, so it is necessary to comment out all references
to the section, and not to forget to restore them in the same state
after the operation.

Let's add a "disabled" keyword just like for proxies. A ->state member
in the peers struct is even present for this purpose but was never used
at all.

Maybe it would make sense to backport this to 1.5 as it's really cumbersome
there.
This commit is contained in:
Willy Tarreau 2015-05-01 20:02:17 +02:00
parent 6866f3f33f
commit 77e4bd1497
2 changed files with 32 additions and 4 deletions

View File

@ -1244,6 +1244,14 @@ peers <peersect>
Creates a new peer list with name <peersect>. It is an independent section, Creates a new peer list with name <peersect>. It is an independent section,
which is referenced by one or more stick-tables. which is referenced by one or more stick-tables.
disabled
Disables a peers section. It disables both listening and any synchronization
related to this section. This is provided to disable synchronization of stick
tables without having to comment out all "peers" references.
enable
This re-enables a disabled peers section which was previously disabled.
peer <peername> <ip>:<port> peer <peername> <ip>:<port>
Defines a peer inside a peers section. Defines a peer inside a peers section.
If <peername> is set to the local peer name (by default hostname, or forced If <peername> is set to the local peer name (by default hostname, or forced

View File

@ -1794,6 +1794,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
curpeers->conf.line = linenum; curpeers->conf.line = linenum;
curpeers->last_change = now.tv_sec; curpeers->last_change = now.tv_sec;
curpeers->id = strdup(args[1]); curpeers->id = strdup(args[1]);
curpeers->state = PR_STNEW;
} }
else if (strcmp(args[0], "peer") == 0) { /* peer definition */ else if (strcmp(args[0], "peer") == 0) { /* peer definition */
struct sockaddr_storage *sk; struct sockaddr_storage *sk;
@ -1919,6 +1920,12 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
} }
} }
} /* neither "peer" nor "peers" */ } /* neither "peer" nor "peers" */
else if (!strcmp(args[0], "disabled")) { /* disables this peers section */
curpeers->state = PR_STSTOPPED;
}
else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */
curpeers->state = PR_STNEW;
}
else if (*args[0] != 0) { else if (*args[0] != 0) {
Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
err_code |= ERR_ALERT | ERR_FATAL; err_code |= ERR_ALERT | ERR_FATAL;
@ -7007,6 +7014,10 @@ int check_config_validity()
curproxy->table.peers.p = NULL; curproxy->table.peers.p = NULL;
cfgerr++; cfgerr++;
} }
else if (curpeers->state == PR_STSTOPPED) {
/* silently disable this peers section */
curproxy->table.peers.p = NULL;
}
else if (!curpeers->peers_fe) { else if (!curpeers->peers_fe) {
Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
curproxy->id, localpeer, curpeers->id); curproxy->id, localpeer, curpeers->id);
@ -7898,14 +7909,23 @@ int check_config_validity()
last = &peers; last = &peers;
while (*last) { while (*last) {
curpeers = *last; curpeers = *last;
if (curpeers->peers_fe) {
if (curpeers->state == PR_STSTOPPED) {
/* the "disabled" keyword was present */
if (curpeers->peers_fe)
stop_proxy(curpeers->peers_fe);
curpeers->peers_fe = NULL;
}
else if (!curpeers->peers_fe) {
Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
curpeers->id, localpeer);
}
else {
last = &curpeers->next; last = &curpeers->next;
continue; continue;
} }
Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", /* clean what has been detected above */
curpeers->id, localpeer);
p = curpeers->remote; p = curpeers->remote;
while (p) { while (p) {
pb = p->next; pb = p->next;