From ffa7337ec3bff3064a47cfa5575bb7a9c9bd3163 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Sun, 12 Jun 2022 12:51:11 +0300 Subject: [PATCH] server: Make systemd optional When running without systemd (e.g. in a container) we don't need to notify system. Add new configuration "daemon:systemd_enable" to allow disabling systemd integration. This removes the runtime dependency on the systemd.daemon package, simplifying deployment. Disable systemd integration in all the test and example configurations system they never start the daemon as a systemd service. Signed-off-by: Nir Soffer --- examples/conf.d/daemon.conf | 3 +++ ovirt_imageio/_internal/config.py | 4 ++++ ovirt_imageio/_internal/server.py | 11 ++++++++--- test/conf.d/daemon.conf | 3 +++ test/conf/daemon.conf | 1 + test/conf/proxy.conf | 1 + test/conf/user-tls.conf | 3 +++ 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/conf.d/daemon.conf b/examples/conf.d/daemon.conf index 38faac96..c7a84122 100644 --- a/examples/conf.d/daemon.conf +++ b/examples/conf.d/daemon.conf @@ -2,6 +2,9 @@ # # ./ovirt-imageio -c examples +[daemon] +systemd_enable = false + [tls] key_file = test/pki/system/key.pem cert_file = test/pki/system/cert.pem diff --git a/ovirt_imageio/_internal/config.py b/ovirt_imageio/_internal/config.py index 5f96c97d..0ef5a0ff 100644 --- a/ovirt_imageio/_internal/config.py +++ b/ovirt_imageio/_internal/config.py @@ -54,6 +54,10 @@ class daemon: # configuration. group_name = "ovirtimg" + # Enable systemd integration. Must be enabled when running via the systemd + # daemon and disabled otherwise. + systemd_enable = True + class tls: diff --git a/ovirt_imageio/_internal/server.py b/ovirt_imageio/_internal/server.py index 92abc027..0be863ab 100644 --- a/ovirt_imageio/_internal/server.py +++ b/ovirt_imageio/_internal/server.py @@ -19,8 +19,6 @@ import socket import sys -import systemd.daemon - from . import auth from . import config from . import errors @@ -51,7 +49,7 @@ def main(): server.start() try: - systemd.daemon.notify("READY=1") + notify_systemd(cfg) log.info("Ready for requests") while server.running: signal.pause() @@ -116,6 +114,13 @@ def configure_logger(cfg): logging.config.fileConfig(parser, disable_existing_loggers=False) +def notify_systemd(cfg): + if cfg.daemon.systemd_enable: + log.debug("Notifying systemd") + import systemd.daemon + systemd.daemon.notify("READY=1") + + class Server: def __init__(self, config, ticket=None): diff --git a/test/conf.d/daemon.conf b/test/conf.d/daemon.conf index a41225fe..d273f83c 100644 --- a/test/conf.d/daemon.conf +++ b/test/conf.d/daemon.conf @@ -3,6 +3,9 @@ # # ./ovirt-imageio -c test +[daemon] +systemd_enable = false + [tls] key_file = test/pki/system/key.pem cert_file = test/pki/system/cert.pem diff --git a/test/conf/daemon.conf b/test/conf/daemon.conf index 7217db01..bc503733 100644 --- a/test/conf/daemon.conf +++ b/test/conf/daemon.conf @@ -4,6 +4,7 @@ [daemon] poll_interval = 0.1 drop_privileges = false +systemd_enable = false [tls] key_file = test/pki/system/key.pem diff --git a/test/conf/proxy.conf b/test/conf/proxy.conf index 6ef5db98..aa4f5d41 100644 --- a/test/conf/proxy.conf +++ b/test/conf/proxy.conf @@ -4,6 +4,7 @@ [daemon] poll_interval = 0.1 drop_privileges = false +systemd_enable = false [tls] key_file = test/pki/system/key.pem diff --git a/test/conf/user-tls.conf b/test/conf/user-tls.conf index 85db1fa4..16610339 100644 --- a/test/conf/user-tls.conf +++ b/test/conf/user-tls.conf @@ -1,5 +1,8 @@ # Drop-in configuration for testing user-defined PKI certificates. +[daemon] +systemd_enable = false + [tls] key_file = test/pki/user/key.pem cert_file = test/pki/user/cert.pem