Skip to content

Commit

Permalink
server: Make systemd optional
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nirs committed Oct 4, 2022
1 parent 32855ab commit ffa7337
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions examples/conf.d/daemon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ovirt_imageio/_internal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
11 changes: 8 additions & 3 deletions ovirt_imageio/_internal/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import socket
import sys

import systemd.daemon

from . import auth
from . import config
from . import errors
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions test/conf.d/daemon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/conf/daemon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[daemon]
poll_interval = 0.1
drop_privileges = false
systemd_enable = false

[tls]
key_file = test/pki/system/key.pem
Expand Down
1 change: 1 addition & 0 deletions test/conf/proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[daemon]
poll_interval = 0.1
drop_privileges = false
systemd_enable = false

[tls]
key_file = test/pki/system/key.pem
Expand Down
3 changes: 3 additions & 0 deletions test/conf/user-tls.conf
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ffa7337

Please sign in to comment.