MINOR: init: add -dr to ignore server address resolution failures
It is very common when validating a configuration out of production not to
have access to the same resolvers and to fail on server address resolution,
making it difficult to test a configuration. This option simply appends the
"none" method to the list of address resolution methods for all servers,
ensuring that even if the libc fails to resolve an address, the startup
sequence is not interrupted.
diff --git a/doc/management.txt b/doc/management.txt
index b5e041a..751621c 100644
--- a/doc/management.txt
+++ b/doc/management.txt
@@ -228,6 +228,14 @@
generally be the "select" poller, which cannot be disabled and is limited
to 1024 file descriptors.
+ -dr : ignore server address resolution failures. It is very common when
+ validating a configuration out of production not to have access to the same
+ resolvers and to fail on server address resolution, making it difficult to
+ test a configuration. This option simply appends the "none" method to the
+ list of address resolution methods for all servers, ensuring that even if
+ the libc fails to resolve an address, the startup sequence is not
+ interrupted.
+
-m <limit> : limit the total allocatable memory to <limit> megabytes across
all processes. This may cause some connection refusals or some slowdowns
depending on the amount of memory needed for normal operations. This is
diff --git a/include/types/global.h b/include/types/global.h
index 9f069ad..a790e74 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -64,6 +64,7 @@
#define GTUNE_USE_SPLICE (1<<4)
#define GTUNE_USE_GAI (1<<5)
#define GTUNE_USE_REUSEPORT (1<<6)
+#define GTUNE_RESOLVE_DONTFAIL (1<<7)
/* Access level for a stats socket */
#define ACCESS_LVL_NONE 0
diff --git a/src/haproxy.c b/src/haproxy.c
index 4806c56..b899c76 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -482,6 +482,7 @@
#if defined(SO_REUSEPORT)
" -dR disables SO_REUSEPORT usage\n"
#endif
+ " -dr ignores server address resolution failures\n"
" -dV disables SSL verify on servers side\n"
" -sf/-st [pid ]* finishes/terminates old pids.\n"
"\n",
@@ -807,6 +808,8 @@
arg_mode |= MODE_FOREGROUND;
else if (*flag == 'd' && flag[1] == 'M')
mem_poison_byte = flag[2] ? strtol(flag + 2, NULL, 0) : 'P';
+ else if (*flag == 'd' && flag[1] == 'r')
+ global.tune.options |= GTUNE_RESOLVE_DONTFAIL;
else if (*flag == 'd')
arg_mode |= MODE_DEBUG;
else if (*flag == 'c')
diff --git a/src/server.c b/src/server.c
index c351707..a1deae8 100644
--- a/src/server.c
+++ b/src/server.c
@@ -3249,6 +3249,13 @@
srv_append_initaddr(&methods, SRV_IADDR_LIBC);
}
+ /* "-dr" : always append "none" so that server addresses resolution
+ * failures are silently ignored, this is convenient to validate some
+ * configs out of their environment.
+ */
+ if (global.tune.options & GTUNE_RESOLVE_DONTFAIL)
+ srv_append_initaddr(&methods, SRV_IADDR_NONE);
+
while (methods) {
err_code = 0;
switch (srv_get_next_initaddr(&methods)) {