From d632fb2460408a1d33882a45bceeb21ce2eb07e8 Mon Sep 17 00:00:00 2001 From: Mobin Aydinfar Date: Thu, 7 May 2026 18:04:34 +0330 Subject: [PATCH] s6-notify: support fd-based s6 notification protocol s6 notification protocol is a simple protocol to notify the supervisor when the daemon is ready to serve its purpose. Just write a newline to the fd specified by the "S6_NOTIFY_FD" env-var and close it, and then the supervisor marks the daemon as ready. Dinit and s6 supervision suite are known to support this protocol. Tested with three cases: 1. "copyparty-sfx.py -c config.conf" and everything works just as before. 2. "copyparty-sfx.py -c config.conf" with S6_NOTIFY_FD when using Dinit and its "ready-notification = pipevar:S6_NOTIFY_FD" option and copyparty notifies the supervisor when it's ready. 3. "copyparty-sfx.py -c config.conf" with S6_NOTIFY_FD=3 but without the fd 3 being open which logs a warning from s6-notify. See https://skarnet.org/software/s6/notifywhenup.html and https://davmac.org/projects/dinit/man-pages-html/dinit-service.5.html#ready for details regarding its usage. Signed-off-by: Mobin Aydinfar --- copyparty/svchub.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/copyparty/svchub.py b/copyparty/svchub.py index fc0a9db9..1e74321d 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -987,6 +987,10 @@ class SvcHub(object): Daemon(self.sd_notify, "sd-notify") + zb = os.environ.get("S6_NOTIFY_FD") + if zb: + Daemon(self.s6_notify, "s6-notify", (zb,)) + def _feature_test(self) -> None: fok = [] fng = [] @@ -1897,6 +1901,17 @@ class SvcHub(object): except: self.log("sd_notify", min_ex()) + def s6_notify(self, zb: bytes) -> None: + try: + fd = int(zb) + if fd < 3: + raise Exception("value < 3") + os.write(fd, b"\n") + os.close(fd) + except: + t = "S6_NOTIFY_FD=%s:\n%s" + self.log("s6-notify", t % (zb, min_ex()), 1) + def log_stacks(self) -> None: td = time.time() - self.tstack if td < 300: