This commit is contained in:
mwiegand 2021-07-13 14:45:27 +02:00
parent 8584484564
commit 7fd587e51a
10 changed files with 208 additions and 109 deletions

View file

@ -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:restart',
'svc_systemd:gitea.service:restart',
},
'preceded_by': {
'action:stop_gitea',
@ -17,7 +17,7 @@ directories['/var/lib/gitea'] = {
'owner': 'git',
'mode': '0700',
'triggers': {
'svc_systemd:gitea:restart',
'svc_systemd:gitea.service:restart',
},
}
@ -40,6 +40,6 @@ files['/etc/gitea/app.ini'] = {
'owner': 'git',
'context': node.metadata['gitea'],
'triggers': {
'svc_systemd:gitea:restart',
'svc_systemd:gitea.service:restart',
},
}

View file

@ -28,8 +28,8 @@ defaults = {
},
},
'systemd': {
'services': {
'gitea': {
'units': {
'gitea.service': {
'content': {
'Unit': {
'Description': 'gitea',
@ -51,12 +51,13 @@ defaults = {
'WantedBy': 'multi-user.target',
},
},
'needs': [
'action:chmod_gitea',
'download:/usr/local/bin/gitea',
'file:/etc/systemd/system/gitea.service',
'file:/etc/gitea/app.ini',
],
'item': {
'needs': [
'action:chmod_gitea',
'download:/usr/local/bin/gitea',
'file:/etc/gitea/app.ini',
],
},
},
},
},

View file

@ -7,31 +7,33 @@ defaults = {
@metadata_reactor.provides(
'systemd-networkd/networks',
'systemd/units',
)
def systemd_networkd(metadata):
def units(metadata):
units = {}
for type, network in metadata.get('network').items():
units[type] = {
'Match': {
'Name': network['interface'],
},
'Network': {
'DHCP': 'no',
'IPv6AcceptRA': 'no',
units[f'{type}.network'] = {
'content': {
'Match': {
'Name': network['interface'],
},
'Network': {
'DHCP': 'no',
'IPv6AcceptRA': 'no',
}
}
}
for i in [4, 6]:
if network.get(f'ipv{i}', None):
units[type].update({
units[f'{type}.network']['content'].update({
f'Address#ipv{i}': {
'Address': network[f'ipv{i}'],
},
})
if f'gateway{i}' in network:
units[type].update({
units[f'{type}.network']['content'].update({
f'Route#ipv{i}': {
'Gateway': network[f'gateway{i}'],
'GatewayOnlink': 'yes',
@ -40,7 +42,7 @@ def systemd_networkd(metadata):
return {
'systemd-networkd': {
'networks': units,
'systemd': {
'units': units,
}
}

View file

@ -16,21 +16,21 @@ 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',
},
}
# 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': {},
}

View file

@ -1,26 +1,27 @@
# svc_systemd['cron'] = {
# 'enabled': False,
# }
for name, config in node.metadata.get('systemd-timers').items():
files[f'/etc/systemd/system/{name}.timer'] = {
'content': repo.libs.systemd.generate_unitfile({
'Unit':{
'Description': f'{name} timer',
},
'Timer': {
'OnCalendar': config['when'],
'Persistent': config.get('persistent', False),
'Unit': f'{name}.service',
},
'Install': {
'WantedBy': 'multi-user.target',
}
}),
'triggers': [
'action:systemd-reload',
f'svc_systemd:{name}:restart',
],
}
svc_systemd[f'{name}.timer'] = {}
# # svc_systemd['cron'] = {
# # 'enabled': False,
# # }
#
# for name, config in node.metadata.get('systemd-timers').items():
# files[f'/etc/systemd/system/{name}.timer'] = {
# 'content': repo.libs.systemd.generate_unitfile({
# 'Unit':{
# 'Description': f'{name} timer',
# },
# 'Timer': {
# 'OnCalendar': config['when'],
# 'Persistent': config.get('persistent', False),
# 'Unit': f'{name}.service',
# },
# 'Install': {
# 'WantedBy': 'multi-user.target',
# }
# }),
# 'triggers': [
# 'action:systemd-reload',
# f'svc_systemd:{name}:restart',
# ],
# }
#
# svc_systemd[f'{name}.timer'] = {}
# #

View file

@ -3,14 +3,41 @@ defaults = {
}
@metadata_reactor.provides(
'systemd/services',
)
def timers(metadata):
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': {
'services': {
name: {
'units': {
f'{name}.service': {
'content': {
'Unit':{
'Description': f'{name} timer service',
@ -19,9 +46,11 @@ def services(metadata):
'ExecStart': config['command'],
},
},
'enabled': False,
'running': False,
} for name, config in metadata.get('systemd-timers').items()
'item': {
'enabled': False,
'running': False,
},
} for name, config in metadata.get('systemd-timers').items()
},
},
}

23
bundles/systemd/README.md Normal file
View file

@ -0,0 +1,23 @@
# SYSTEMD
## metadata
```python
{
'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': {
},
}
}
},
}
```

View file

@ -6,39 +6,18 @@ actions = {
'command': 'systemctl daemon-reload',
'cascade_skip': False,
'triggered': True,
'needed_by': {
'svc_systemd:',
},
},
}
for name, service in node.metadata.get('systemd/services').items():
# dont call a service 'service' explicitly
if name.endswith('.service'):
raise Exception(name)
# split unit file content data from item data
content_data = service.pop('content')
# default WantedBy=multi-user.target
content_data\
.setdefault('Install', {})\
.setdefault('WantedBy', {'multi-user.target'})
# create unit file
unit_path = f'/etc/systemd/system/{name}.service'
files[unit_path] = {
'content': repo.libs.systemd.generate_unitfile(content_data),
'triggers': [
'action:systemd-reload',
f'svc_systemd:{name}:restart',
],
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")
# service depends on unit file
service\
.setdefault('needs', [])\
.append(f'file:{unit_path}')
# service
svc_systemd[name] = service
for name, config in node.metadata.get('systemd/services').items():
svc_systemd[name] = {
**config,
}
svc_systemd[name].setdefault('needs', []).append("action:systemd-reload")

View file

@ -1,5 +1,65 @@
defaults = {
'systemd': {
'units': {},
'services': {},
}
}
# 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.get('path')}")
return {
'systemd': {
'services': services,
}
}
# add defaults to units
@metadata_reactor#.provides(
# 'systemd/units',
#)
def unit_defaults(metadata):
units = {}
for name in metadata.get('systemd/units').keys():
extension = name.split('.')[-1]
if extension in ['netdev', 'network']:
units[name] = {
'path': f'/etc/systemd/network/{name}',
'item': {
'triggers': [
'svc_systemd:systemd-networkd:restart',
]
}
}
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': {
'units': units,
}
}

View file

@ -26,7 +26,7 @@ defaults = {
@metadata_reactor.provides(
'systemd-networkd/networks',
'systemd/units',
)
def systemd_networkd_networks(metadata):
network = {
@ -60,16 +60,18 @@ def systemd_networkd_networks(metadata):
})
return {
'systemd-networkd': {
'networks': {
'wireguard': network,
'systemd': {
'units': {
'wireguard.network': {
'content': network,
},
},
},
}
@metadata_reactor.provides(
'systemd-networkd/netdevs',
'systemd/units',
)
def systemd_networkd_netdevs(metadata):
netdev = {
@ -99,9 +101,11 @@ def systemd_networkd_netdevs(metadata):
})
return {
'systemd-networkd': {
'netdevs': {
'wireguard': netdev,
'systemd': {
'units': {
'wireguard.netdev': {
'content': netdev,
},
},
},
}