71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
defaults = {
|
|
'systemd-timers': {},
|
|
}
|
|
|
|
|
|
@metadata_reactor.provides(
|
|
'systemd/units',
|
|
'systemd/services',
|
|
)
|
|
def systemd(metadata):
|
|
units = {}
|
|
services = {}
|
|
|
|
for name, config in metadata.get('systemd-timers').items():
|
|
units.update({
|
|
f'{name}.timer': {
|
|
'Unit':{
|
|
'Description': f'{name} timer',
|
|
'After': config.get('after', set()),
|
|
},
|
|
'Timer': {
|
|
'OnCalendar': config['when'],
|
|
'Persistent': config.get('persistent', False),
|
|
'Unit': f'{name}.service',
|
|
},
|
|
},
|
|
f'{name}.service': {
|
|
'Unit':{
|
|
'Description': f'{name} timer service',
|
|
},
|
|
'Service': {
|
|
'User': config.get('user', 'root'),
|
|
'ExecStart': config['command'],
|
|
'Environment': config.get('env'),
|
|
'Nice': config.get('nice', 10),
|
|
},
|
|
},
|
|
})
|
|
if config.get('working_dir'):
|
|
units[f'{name}.service']['Service']['WorkingDirectory'] = config['working_dir']
|
|
if config.get('success_exit_status'):
|
|
units[f'{name}.service']['Service']['SuccessExitStatus'] = config['success_exit_status']
|
|
if config.get('kill_mode'):
|
|
units[f'{name}.service']['Service']['KillMode'] = config['kill_mode']
|
|
if config.get('RuntimeMaxSec'):
|
|
units[f'{name}.service']['Service']['RuntimeMaxSec'] = config['RuntimeMaxSec']
|
|
|
|
services[f'{name}.timer'] = {}
|
|
|
|
return {
|
|
'systemd': {
|
|
'units': units,
|
|
'services': services,
|
|
},
|
|
}
|
|
|
|
|
|
@metadata_reactor.provides(
|
|
'monitoring/services',
|
|
)
|
|
def monitoring(metadata):
|
|
return {
|
|
'monitoring': {
|
|
'services': {
|
|
f'{name}.timer': {
|
|
'vars.command': f'/usr/lib/nagios/plugins/check_systemd_timer {name}',
|
|
}
|
|
for name in metadata.get('systemd-timers')
|
|
},
|
|
},
|
|
}
|