mirror of
https://github.com/9001/copyparty.git
synced 2026-06-21 05:32:25 -06:00
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 <mobin@mobintestserver.ir>
This commit is contained in:
parent
da6e2ddca9
commit
d632fb2460
|
|
@ -987,6 +987,10 @@ class SvcHub(object):
|
||||||
|
|
||||||
Daemon(self.sd_notify, "sd-notify")
|
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:
|
def _feature_test(self) -> None:
|
||||||
fok = []
|
fok = []
|
||||||
fng = []
|
fng = []
|
||||||
|
|
@ -1897,6 +1901,17 @@ class SvcHub(object):
|
||||||
except:
|
except:
|
||||||
self.log("sd_notify", min_ex())
|
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:
|
def log_stacks(self) -> None:
|
||||||
td = time.time() - self.tstack
|
td = time.time() - self.tstack
|
||||||
if td < 300:
|
if td < 300:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue