[MEDIUM] add support for health-checks on other addresses
Patch from Fabrice Dulaunoy. Explanation below, and script
merged in examples/.
This patch allow to put a different address in the check part for each
server (and not only a specific port)
I need this feature because I've a complex settings where, when a specific
farm goes down, I need to switch a set of other farm either if these other
farm behave perfectly well.
For that purpose, I've made a small PERL daemon with some REGEX or PORT
test which allow me to test a bunch of thing.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 885a01b..ff1c927 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -1197,6 +1197,7 @@
newsrv->rise = DEF_RISETIME;
newsrv->fall = DEF_FALLTIME;
newsrv->health = newsrv->rise; /* up, but will fall down at first failure */
+ newsrv->set_check_addr = 0;
cur_arg = 3;
while (*args[cur_arg]) {
if (!strcmp(args[cur_arg], "cookie")) {
@@ -1217,6 +1218,11 @@
newsrv->inter = atol(args[cur_arg + 1]);
cur_arg += 2;
}
+ else if (!strcmp(args[cur_arg], "addr")) {
+ newsrv->check_addr = *str2sa(args[cur_arg + 1]);
+ newsrv->set_check_addr = 1;
+ cur_arg += 2;
+ }
else if (!strcmp(args[cur_arg], "port")) {
newsrv->check_port = atol(args[cur_arg + 1]);
cur_arg += 2;
diff --git a/src/checks.c b/src/checks.c
index ed0873a..295be15 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -248,8 +248,18 @@
(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof(one)) != -1)) {
//fprintf(stderr, "process_chk: 3\n");
+
+ if ( s->set_check_addr == 1 )
+ {
+ /* we'll connect to the check addr specified on the server */
+ sa = s->check_addr;
+ }
+ else
+ {
+ /* we'll connect to the addr on the server */
+ sa = s->addr;
+ }
/* we'll connect to the check port on the server */
- sa = s->addr;
sa.sin_port = htons(s->check_port);
/* allow specific binding :