In Master Workers mode, when the reloading of the configuration fail,
the process is exiting leaving the children without their father.

To handle this, we register an exit function with atexit(3), which is
reexecuting the binary in a special mode. This particular mode of
HAProxy don't reload the configuration, it only loops on wait().
---
 src/haproxy.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/haproxy.c b/src/haproxy.c
index e0b6462..8a815f1 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -553,6 +553,19 @@ static void mworkers_wait()
 }
 
 
+/*
+ * Reexec the process in failure mode, instead of exiting
+ */
+void reexec_on_failure()
+{
+       setenv("WAIT_ONLY", "1", 1);
+
+       Warning("Reexecuting Master process in waitpid mode\n");
+       master_reload();
+
+       Warning("Failed to reexecute the master processs\n");
+}
+
 
 /*
  * upon SIGUSR1, let's have a soft stop. Note that soft_stop() broadcasts
@@ -1205,6 +1218,17 @@ static void init(int argc, char **argv)
                (arg_mode & (MODE_DAEMON | MODE_MWORKER | MODE_FOREGROUND | 
MODE_VERBOSE
                             | MODE_QUIET | MODE_CHECK | MODE_DEBUG));
 
+       /* Master workers wait mode */
+       if ((global.mode & MODE_MWORKER) && (getenv("WAIT_ONLY") != NULL)) {
+
+               unsetenv("WAIT_ONLY");
+               mworkers_wait();
+       }
+
+       if ((global.mode & MODE_MWORKER) && (getenv(REEXEC_FLAG) != NULL)) {
+               atexit(reexec_on_failure);
+       }
+
        if (change_dir && chdir(change_dir) < 0) {
                Alert("Could not change to directory %s : %s\n", change_dir, 
strerror(errno));
                exit(1);
-- 
2.10.2


Reply via email to