I have added working (for me at least) s6 notification support to
haproxy so it can signal that it's ready when running under the s6
supervision suite.

The process used under s6 is that the daemon signals readiness by
writing a line to an arbitrary FD (that the supervision suite has been
told about), then closing the FD as documented here:

https://skarnet.org/software/s6/notifywhenup.html

This signals the transition from started to ready.

At this stage the FD written to and closed is hard coded as fd@3 as I
have reached the end of my C expertise getting this far...

Although it seems like it's not something that many people are hanging
out for based on the responses to a previous email to the list, I
thought I'd send the patch through as-is anyway.

Regards,

Andrew Heberle

>From 9dddd668e699b85bc5494d1a27e550e987ce43cb Mon Sep 17 00:00:00 2001
From: Andrew Heberle <[email protected]>
Date: Wed, 1 May 2019 09:40:41 +0800
Subject: [PATCH] Add s6 notification support

---
include/types/global.h | 1 +
src/haproxy.c | 12 ++++++++++++
2 files changed, 13 insertions(+)

diff --git a/include/types/global.h b/include/types/global.h
index ba3738b..9481d64 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -72,6 +72,7 @@
#define GTUNE_BUSY_POLLING (1<<11)
#define GTUNE_LISTENER_MQ (1<<12)
#define GTUNE_SET_DUMPABLE (1<<13)
+#define GTUNE_USE_S6_NOTIFY (1<<14)
/* Access level for a stats socket */
#define ACCESS_LVL_NONE 0
diff --git a/src/haproxy.c b/src/haproxy.c
index 4c5c839..99a6f67 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -446,6 +446,7 @@ static void usage(char *name)
#if defined(USE_SYSTEMD)
       " -Ws master-worker mode with systemd notify support.\n"
#endif
+       " -Wn master-worker mode with s6 notify support.\n"
       " -q quiet mode : don't display messages\n"
       " -c check mode : only check config files and exit\n"
       " -n sets the maximum total # of connections (uses ulimit -n)\n"
@@ -652,6 +653,13 @@ static void mworker_loop()
   if (global.tune.options & GTUNE_USE_SYSTEMD)
       sd_notifyf(0, "READY=1\nMAINPID=%lu", (unsigned long)getpid());
#endif
+   /* if -Wn mode was requested then open fd 3, write an arbritrary
line and close the fd */
+   if (global.tune.options & GTUNE_USE_S6_NOTIFY) {
+       FILE *notifyfd;
+       notifyfd = fdopen(3, "w");
+       fprintf(notifyfd, "UP\n");
+       fclose(notifyfd);
+   }
   /* Busy polling makes no sense in the master :-) */
   global.tune.options &= ~GTUNE_BUSY_POLLING;
@@ -1427,6 +1435,10 @@ static void init(int argc, char **argv)
               usage(progname);
#endif
           }
+           else if (*flag == 'W' && flag[1] == 'n') {
+               arg_mode |= MODE_MWORKER | MODE_FOREGROUND;
+               global.tune.options |= GTUNE_USE_S6_NOTIFY;
+           }
           else if (*flag == 'W')
               arg_mode |= MODE_MWORKER;
           else if (*flag == 'q')
-- 
2.9.0.windows.1

Reply via email to