William Lallemand
some mworker + pidfile patches
November 06, 2017 11:10AM
A few patches which help using the pidfile in master-worker mode.
William Lallemand
[PATCH 2/3] MINOR: mworker: allow pidfile in mworker + foreground
November 06, 2017 11:10AM
This patch allows the use of the pidfile in master-worker mode without
using the background option.
---
src/haproxy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/haproxy.c b/src/haproxy.c
index bbd26b82d..f12e903b2 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2499,7 +2499,7 @@ int main(int argc, char **argv)
}

/* open log & pid files before the chroot */
- if (global.mode & MODE_DAEMON && global.pidfile != NULL) {
+ if ((global.mode & MODE_DAEMON || global.mode & MODE_MWORKER) && global.pidfile != NULL) {
unlink(global.pidfile);
pidfd = open(global.pidfile, O_CREAT | O_WRONLY | O_TRUNC, 0644);
if (pidfd < 0) {
--
2.13.6
William Lallemand
[PATCH 3/3] MINOR: mworker: write parent pid in the pidfile
November 06, 2017 11:10AM
The first pid in the pidfile is now the parent, it's more convenient for
supervising the processus.

You can now reload haproxy in master-worker mode with convenient command
like: kill -USR2 $(head -1 /tmp/haproxy.pid)
---
src/haproxy.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/src/haproxy.c b/src/haproxy.c
index f12e903b2..bcbbad4a1 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2631,6 +2631,13 @@ int main(int argc, char **argv)
}
}

+ /* if in master-worker mode, write the PID of the father */
+ if (global.mode & MODE_MWORKER) {
+ char pidstr[100];
+ snprintf(pidstr, sizeof(pidstr), "%d\n", getpid());
+ shut_your_big_mouth_gcc(write(pidfd, pidstr, strlen(pidstr)));
+ }
+
/* the father launches the required number of processes */
for (proc = 0; proc < global.nbproc; proc++) {
ret = fork();
--
2.13.6
William Lallemand
[PATCH 1/3] MINOR: add master-worker in the warning about nbproc
November 06, 2017 11:10AM
---
src/haproxy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/haproxy.c b/src/haproxy.c
index 68b5e427b..bbd26b82d 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1749,7 +1749,7 @@ static void init(int argc, char **argv)

if ((global.nbproc > 1) && !(global.mode & (MODE_DAEMON | MODE_MWORKER))) {
if (!(global.mode & (MODE_FOREGROUND | MODE_DEBUG)))
- Warning("<nbproc> is only meaningful in daemon mode. Setting limit to 1 process.\n");
+ Warning("<nbproc> is only meaningful in daemon mode or master-worker mode. Setting limit to 1 process.\n");
global.nbproc = 1;
}

--
2.13.6
Sorry, only registered users may post in this forum.

Click here to login