From aad74c13d49912254438307282bbc0ffca94bf86 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Tue, 13 Jul 2021 16:49:57 +0200 Subject: [PATCH] wip --- bundles/systemd-timers/metadata.py | 3 --- bundles/systemd/README.md | 9 ------- bundles/systemd/metadata.py | 43 +++++++++++++++++++++++++----- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/bundles/systemd-timers/metadata.py b/bundles/systemd-timers/metadata.py index cdc0d47..4f2868e 100644 --- a/bundles/systemd-timers/metadata.py +++ b/bundles/systemd-timers/metadata.py @@ -22,9 +22,6 @@ def systemd(metadata): 'Persistent': config.get('persistent', False), 'Unit': f'{name}.service', }, - 'Install': { - 'WantedBy': 'multi-user.target', - }, }, f'{name}.service': { 'Unit':{ diff --git a/bundles/systemd/README.md b/bundles/systemd/README.md index 3adb596..ef73a39 100644 --- a/bundles/systemd/README.md +++ b/bundles/systemd/README.md @@ -7,15 +7,6 @@ 'systemd': { 'units': { 'test.service': { - # optional: will be derived from unit extension - 'path': '/etc/systemd/system/test.service', - # content of the unit file - 'content': { - }, - # bw item data - # applies to unitfile and svc_systemd aswell, if present - 'item': { - }, } } }, diff --git a/bundles/systemd/metadata.py b/bundles/systemd/metadata.py index a6128cb..d358342 100644 --- a/bundles/systemd/metadata.py +++ b/bundles/systemd/metadata.py @@ -8,19 +8,50 @@ defaults = { @metadata_reactor.provides( 'systemd/units', ) -def services(metadata): +def units(metadata): units = {} for name, config in metadata.get('systemd/units').items(): - if name.split('.')[-1] == 'service' and not config.get('Install/WantedBy'): - units[name] = { - 'Install': { - 'WantedBy': ['multi-user.target'], + extension = name.split('.')[-1] + + if extension not in ['timer', 'service', 'network', 'netdev']: + raise Exception(f'unknown extension {extension}') + + if not config.get('Install/WantedBy'): + if extension == 'service': + units[name] = { + 'Install': { + 'WantedBy': ['multi-user.target'], + } + } + elif extension == 'timer': + units[name] = { + 'Install': { + 'WantedBy': ['timers.target'], + } } - } return { 'systemd': { 'units': units, } } + + +@metadata_reactor.provides( + 'systemd/services', +) +def services(metadata): + services = {} + + for name, config in metadata.get('systemd/services').items(): + extension = name.split('.')[-1] + + if extension not in ['timer', 'service']: + raise Exception(f'unknown extension {extension}') + + return { + 'systemd': { + 'services': services, + } + }