[elbe-devel] [PATCH] elbepack: daemon: use service type notify
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Thu Jun 27 09:09:44 CEST 2024
Make it easier to recognize startup errors.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
debian/python3-elbe-daemon.service | 2 +-
elbepack/commands/daemon.py | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/debian/python3-elbe-daemon.service b/debian/python3-elbe-daemon.service
index 97fea26d2b24..18165ba35ec1 100644
--- a/debian/python3-elbe-daemon.service
+++ b/debian/python3-elbe-daemon.service
@@ -3,7 +3,7 @@ Description=ELBE Daemon
Documentation=man:elbe-daemon(1)
[Service]
-Type=simple
+Type=notify
ExecStart=/usr/bin/elbe daemon --port=7588
[Install]
diff --git a/elbepack/commands/daemon.py b/elbepack/commands/daemon.py
index 04bc1a6c6987..3703147a057f 100644
--- a/elbepack/commands/daemon.py
+++ b/elbepack/commands/daemon.py
@@ -2,7 +2,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2014, 2017 Linutronix GmbH
+import errno
import importlib
+import os
+import socket
from optparse import OptionParser
from pkgutil import iter_modules
@@ -15,6 +18,24 @@ def get_daemonlist():
return [x for _, x, _ in iter_modules(elbepack.daemons.__path__)]
+# From sd_notify(3).
+def _sd_notify(message):
+ socket_path = os.environ.get('NOTIFY_SOCKET')
+ if not socket_path:
+ return
+
+ if socket_path[0] not in ('/', '@'):
+ raise OSError(errno.EAFNOSUPPORT, 'Unsupported socket type')
+
+ # Handle abstract socket.
+ if socket_path[0] == '@':
+ socket_path = '\0' + socket_path[1:]
+
+ with socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM | socket.SOCK_CLOEXEC) as sock:
+ sock.connect(socket_path)
+ sock.sendall(message)
+
+
def run_command(argv):
daemons = get_daemonlist()
@@ -55,4 +76,6 @@ def run_command(argv):
server.subscribe()
cherrypy.engine.start()
+ _sd_notify(b'READY=1\n'
+ b'STATUS=Serving requests\n')
cherrypy.engine.block()
---
base-commit: 9eaf3ec03cc51e78edb40d4a6c4e149753f2472a
change-id: 20240627-sd-notify-11455bd4daa0
Best regards,
--
Thomas Weißschuh <thomas.weissschuh at linutronix.de>
More information about the elbe-devel
mailing list