Hi List,

Made a patch that makes the master-worker detach from tty when it is also combined with daemon mode to allow a script to start haproxy with daemon mode, closing stdout so the calling process knows when to stop reading from it and allow the master to properly daemonize.

This is intended to solve my previously reported 'issue' : https://www.mail-archive.com/haproxy@formilux.org/msg27963.html

Let me know if something about it needs fixing..

Thanks

PiBa-NL / Pieter



From 06224a3fcf7b39bf1bf0128a5bac3d0209bc2aab Mon Sep 17 00:00:00 2001
From: PiBa-NL <pba_...@yahoo.com>
Date: Tue, 28 Nov 2017 23:26:08 +0100
Subject: [PATCH] [PATCH] BUG/MINOR: when master-worker is in daemon mode,
 detach from tty

This allows a calling script to show the first startup output and know when to 
stop reading from stdout so haproxy can daemonize.
---
 src/haproxy.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/haproxy.c b/src/haproxy.c
index c3c8281..a811577 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2648,6 +2648,13 @@ int main(int argc, char **argv)
        }
 
        if (global.mode & (MODE_DAEMON | MODE_MWORKER)) {
+               if ((!(global.mode & MODE_QUIET) || (global.mode & 
MODE_VERBOSE)) &&
+                       ((global.mode & (MODE_DAEMON | MODE_MWORKER)) == 
(MODE_DAEMON | MODE_MWORKER))) {
+                       /* detach from the tty, this is required to properly 
daemonize. */
+                       fclose(stdin); fclose(stdout); fclose(stderr);
+                       global.mode &= ~MODE_VERBOSE;
+                       global.mode |= MODE_QUIET; /* ensure that we won't say 
anything from now */
+               }
                struct proxy *px;
                struct peers *curpeers;
                int ret = 0;
-- 
2.10.1.windows.1

Reply via email to