This commit is contained in:
mwiegand 2021-07-13 16:17:38 +02:00
parent dfc262aea1
commit 65ef24f403
10 changed files with 105 additions and 168 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.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',
],
}

View file

@ -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',
},
},
},

View file

@ -34,6 +34,7 @@ defaults = {
@metadata_reactor.provides(
'influxdb/password',
'influxdb/admin_token',
)
def admin_password(metadata):
return {

View file

@ -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',

View file

@ -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': {},
}

View file

@ -6,8 +6,4 @@ defaults = {
},
},
},
'systemd-networkd': {
'netdevs': {},
'networks': {},
},
}

View file

@ -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,
},
}

View file

@ -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',
],
})

View file

@ -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': {

View file

@ -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,
},
},
}