diff --git a/bundles/gitea/items.py b/bundles/gitea/items.py index 416406a..b2e5fec 100644 --- a/bundles/gitea/items.py +++ b/bundles/gitea/items.py @@ -4,7 +4,7 @@ downloads['/usr/local/bin/gitea'] = { 'url': f'https://dl.gitea.io/gitea/{version}/gitea-{version}-linux-amd64', 'sha256': node.metadata.get('gitea/sha256'), 'triggers': { - 'svc_systemd:gitea.service:restart', + 'svc_systemd:gitea:restart', }, 'preceded_by': { 'action:stop_gitea', @@ -17,7 +17,7 @@ directories['/var/lib/gitea'] = { 'owner': 'git', 'mode': '0700', 'triggers': { - 'svc_systemd:gitea.service:restart', + 'svc_systemd:gitea:restart', }, } @@ -40,6 +40,14 @@ files['/etc/gitea/app.ini'] = { 'owner': 'git', 'context': node.metadata['gitea'], 'triggers': { - 'svc_systemd:gitea.service:restart', + 'svc_systemd:gitea:restart', }, } + +svc_systemd['gitea'] = { + 'needs': [ + 'action:chmod_gitea', + 'download:/usr/local/bin/gitea', + 'file:/etc/gitea/app.ini', + ], +} diff --git a/bundles/gitea/metadata.py b/bundles/gitea/metadata.py index fd4c123..b80b4cf 100644 --- a/bundles/gitea/metadata.py +++ b/bundles/gitea/metadata.py @@ -30,33 +30,24 @@ defaults = { 'systemd': { 'units': { 'gitea.service': { - 'content': { - 'Unit': { - 'Description': 'gitea', - 'After': 'syslog.target', - 'After': 'network.target', - 'Requires': 'postgresql.service', - }, - 'Service': { - 'RestartSec': '2s', - 'Type': 'simple', - 'User': 'git', - 'Group': 'git', - 'WorkingDirectory': '/var/lib/gitea/', - 'ExecStart': '/usr/local/bin/gitea web -c /etc/gitea/app.ini', - 'Restart': 'always', - 'Environment': 'USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea', - }, - 'Install': { - 'WantedBy': 'multi-user.target', - }, + 'Unit': { + 'Description': 'gitea', + 'After': 'syslog.target', + 'After': 'network.target', + 'Requires': 'postgresql.service', }, - 'item': { - 'needs': [ - 'action:chmod_gitea', - 'download:/usr/local/bin/gitea', - 'file:/etc/gitea/app.ini', - ], + 'Service': { + 'RestartSec': '2s', + 'Type': 'simple', + 'User': 'git', + 'Group': 'git', + 'WorkingDirectory': '/var/lib/gitea/', + 'ExecStart': '/usr/local/bin/gitea web -c /etc/gitea/app.ini', + 'Restart': 'always', + 'Environment': 'USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea', + }, + 'Install': { + 'WantedBy': 'multi-user.target', }, }, }, diff --git a/bundles/influxdb2/metadata.py b/bundles/influxdb2/metadata.py index 20e834d..0cb5808 100644 --- a/bundles/influxdb2/metadata.py +++ b/bundles/influxdb2/metadata.py @@ -34,6 +34,7 @@ defaults = { @metadata_reactor.provides( 'influxdb/password', + 'influxdb/admin_token', ) def admin_password(metadata): return { diff --git a/bundles/network/metadata.py b/bundles/network/metadata.py index c579ad8..8df11c7 100644 --- a/bundles/network/metadata.py +++ b/bundles/network/metadata.py @@ -14,26 +14,24 @@ def units(metadata): for type, network in metadata.get('network').items(): units[f'{type}.network'] = { - 'content': { - 'Match': { - 'Name': network['interface'], - }, - 'Network': { - 'DHCP': 'no', - 'IPv6AcceptRA': 'no', - } + 'Match': { + 'Name': network['interface'], + }, + 'Network': { + 'DHCP': 'no', + 'IPv6AcceptRA': 'no', } } for i in [4, 6]: if network.get(f'ipv{i}', None): - units[f'{type}.network']['content'].update({ + units[f'{type}.network'].update({ f'Address#ipv{i}': { 'Address': network[f'ipv{i}'], }, }) if f'gateway{i}' in network: - units[f'{type}.network']['content'].update({ + units[f'{type}.network'].update({ f'Route#ipv{i}': { 'Gateway': network[f'gateway{i}'], 'GatewayOnlink': 'yes', diff --git a/bundles/systemd-networkd/items.py b/bundles/systemd-networkd/items.py index 89f1dc1..51c0ad6 100644 --- a/bundles/systemd-networkd/items.py +++ b/bundles/systemd-networkd/items.py @@ -4,10 +4,9 @@ files = { '/etc/network/interfaces': { 'delete': True, }, -} - -files['/etc/resolv.conf'] = { - 'content_type': 'mako', + '/etc/resolv.conf': { + 'content_type': 'mako', + }, } directories = { @@ -16,21 +15,6 @@ directories = { }, } -# for type, path in { -# 'networks': '/etc/systemd/network/{}.network', -# 'netdevs': '/etc/systemd/network/{}.netdev', -# }.items(): -# for name, config in node.metadata.get(f'systemd-networkd/{type}').items(): -# files[path.format(name)] = { -# 'content': repo.libs.systemd.generate_unitfile(config), -# 'needed_by': { -# 'svc_systemd:systemd-networkd', -# }, -# 'triggers': { -# 'svc_systemd:systemd-networkd:restart', -# }, -# } -# svc_systemd = { 'systemd-networkd': {}, } diff --git a/bundles/systemd-networkd/metadata.py b/bundles/systemd-networkd/metadata.py index e3a857b..936c6c6 100644 --- a/bundles/systemd-networkd/metadata.py +++ b/bundles/systemd-networkd/metadata.py @@ -6,8 +6,4 @@ defaults = { }, }, }, - 'systemd-networkd': { - 'netdevs': {}, - 'networks': {}, - }, } diff --git a/bundles/systemd-timers/metadata.py b/bundles/systemd-timers/metadata.py index 1ef111a..cdc0d47 100644 --- a/bundles/systemd-timers/metadata.py +++ b/bundles/systemd-timers/metadata.py @@ -4,53 +4,42 @@ defaults = { @metadata_reactor.provides( + 'systemd/units', 'systemd/services', ) -def timers(metadata): +def systemd(metadata): + units = {} + services = {} + + for name, config in metadata.get('systemd-timers').items(): + units.update({ + f'{name}.timer': { + 'Unit':{ + 'Description': f'{name} timer', + }, + 'Timer': { + 'OnCalendar': config['when'], + 'Persistent': config.get('persistent', False), + 'Unit': f'{name}.service', + }, + 'Install': { + 'WantedBy': 'multi-user.target', + }, + }, + f'{name}.service': { + 'Unit':{ + 'Description': f'{name} timer service', + }, + 'Service': { + 'ExecStart': config['command'], + }, + }, + }) + services[f'{name}.timer'] = {} + return { 'systemd': { - 'units': { - f'{name}.timer': { - 'content': { - 'Unit':{ - 'Description': f'{name} timer', - }, - 'Timer': { - 'OnCalendar': config['when'], - 'Persistent': config.get('persistent', False), - 'Unit': f'{name}.service', - }, - 'Install': { - 'WantedBy': 'multi-user.target', - } - }, - } for name, config in metadata.get('systemd-timers').items() - }, - }, - } - - -@metadata_reactor.provides( - 'systemd/services', -) -def services(metadata): - return { - 'systemd': { - 'units': { - f'{name}.service': { - 'content': { - 'Unit':{ - 'Description': f'{name} timer service', - }, - 'Service': { - 'ExecStart': config['command'], - }, - }, - 'item': { - 'enabled': False, - 'running': False, - }, - } for name, config in metadata.get('systemd-timers').items() - }, + 'units': units, + 'services': services, }, } diff --git a/bundles/systemd/items.py b/bundles/systemd/items.py index 28f4401..16082c1 100644 --- a/bundles/systemd/items.py +++ b/bundles/systemd/items.py @@ -1,5 +1,4 @@ -timezone = node.metadata.get('timezone', 'UTC') -keymap = node.metadata.get('keymap', 'de') +from bundlewrap.utils.dicts import merge_dict actions = { 'systemd-reload': { @@ -9,15 +8,29 @@ actions = { }, } -for name, config in node.metadata.get('systemd/units').items(): - files[config['path']] = { - 'content': repo.libs.systemd.generate_unitfile(config['content']), - **config['item'], - } - files[config['path']].setdefault('triggers', []).append("action:systemd-reload") +for name, unit in node.metadata.get('systemd/units').items(): + extension = name.split('.')[-1] + + if extension in ['netdev', 'network']: + files[f'/etc/systemd/network/{name}'] = { + 'content': repo.libs.systemd.generate_unitfile(unit), + 'triggers': [ + 'svc_systemd:systemd-networkd:restart', + ], + } + elif extension in ['timer', 'service']: + files[f'/etc/systemd/system/{name}'] = { + 'content': repo.libs.systemd.generate_unitfile(unit), + 'triggers': [ + "action:systemd-reload", + ], + } + else: + raise Exception(f'unknown unit extension: "{extension}"') for name, config in node.metadata.get('systemd/services').items(): - svc_systemd[name] = { - **config, - } - svc_systemd[name].setdefault('needs', []).append("action:systemd-reload") + svc_systemd[name] = merge_dict(config, { + 'needs': [ + 'action:systemd-reload', + ], + }) diff --git a/bundles/systemd/metadata.py b/bundles/systemd/metadata.py index 588082c..a6128cb 100644 --- a/bundles/systemd/metadata.py +++ b/bundles/systemd/metadata.py @@ -5,58 +5,19 @@ defaults = { } } - -# create a svc_sytemd item for each .service and .timer unit -@metadata_reactor#.provides( -# 'systemd/services', -#) -def unit_services(metadata): - services = {} - - for name, config in metadata.get('systemd/units').items(): - if name.split('.')[-1] not in ['timer', 'service']: - continue - - services[name] = config['item'] - services[name].setdefault('needs', []).append(f"file:{config['path']}") - - return { - 'systemd': { - 'services': services, - } - } - - -# add defaults to units @metadata_reactor.provides( 'systemd/units', ) -def unit_defaults(metadata): +def services(metadata): units = {} - for name in metadata.get('systemd/units').keys(): - extension = name.split('.')[-1] - - if extension in ['netdev', 'network']: + for name, config in metadata.get('systemd/units').items(): + if name.split('.')[-1] == 'service' and not config.get('Install/WantedBy'): units[name] = { - 'path': f'/etc/systemd/network/{name}', - 'item': { - 'triggers': [ - 'svc_systemd:systemd-networkd:restart', - ] + 'Install': { + 'WantedBy': ['multi-user.target'], } } - elif extension in ['timer', 'service']: - units[name] = { - 'path': f'/etc/systemd/system/{name}', - 'item': { - 'triggers': [ - f'svc_systemd:{name}:restart', - ] - }, - } - else: - raise Exception(f'unknown unit extension: "{extension}"') return { 'systemd': { diff --git a/bundles/wireguard/metadata.py b/bundles/wireguard/metadata.py index 2c8c9ef..b2d782d 100644 --- a/bundles/wireguard/metadata.py +++ b/bundles/wireguard/metadata.py @@ -62,9 +62,7 @@ def systemd_networkd_networks(metadata): return { 'systemd': { 'units': { - 'wireguard.network': { - 'content': network, - }, + 'wireguard.network': network, }, }, } @@ -103,9 +101,7 @@ def systemd_networkd_netdevs(metadata): return { 'systemd': { 'units': { - 'wireguard.netdev': { - 'content': netdev, - }, + 'wireguard.netdev': netdev, }, }, }