bundles/cron: use MAILTO=, rework metadata syntax

This commit is contained in:
Franzi 2022-02-05 11:41:41 +01:00
parent 533f8075ca
commit 0d865c93d4
Signed by: kunsi
GPG key ID: 12E3D2136B818350
22 changed files with 113 additions and 65 deletions

View file

@ -21,8 +21,6 @@ case "$exitcode" in
echo "Upgrades skipped due to active SSH login"
exit 1
;;
reboot)
;;
0)
if [[ -f /var/run/reboot-required ]]
then

View file

@ -18,7 +18,7 @@ defaults = {
@metadata_reactor.provides(
'cron/upgrade-and-reboot'
'cron/jobs/upgrade-and-reboot'
)
def patchday(metadata):
day = metadata.get('apt/unattended-upgrades/day')
@ -26,10 +26,12 @@ def patchday(metadata):
return {
'cron': {
'upgrade-and-reboot': '{minute} {hour} * * {day} root /usr/local/sbin/upgrade-and-reboot'.format(
minute=node.magic_number % 30,
hour=hour,
day=day,
),
'jobs': {
'upgrade-and-reboot': '{minute} {hour} * * {day} root /usr/local/sbin/upgrade-and-reboot'.format(
minute=node.magic_number % 30,
hour=hour,
day=day,
),
},
},
}

View file

@ -10,7 +10,7 @@ defaults = {
@metadata_reactor.provides(
'cron/backup',
'cron/jobs/backup',
'icinga2_api/backup-client/services',
)
def cron(metadata):
@ -19,11 +19,13 @@ def cron(metadata):
return {
'cron': {
'jobs': {
# spread backups between 00:00 and 04:59 UTC
'backup': '{} {} * * * root /usr/local/bin/generate-backup-with-retries'.format(
(node.magic_number % 60),
(node.magic_number % 4),
),
'backup': '{} {} * * * root /usr/local/bin/generate-backup-with-retries'.format(
(node.magic_number % 60),
(node.magic_number % 4),
),
},
},
'icinga2_api': {
'backup-client': {

View file

@ -91,7 +91,7 @@ files = {
},
}
for crontab, content in node.metadata.get('cron', {}).items():
for crontab, content in node.metadata.get('cron/jobs', {}).items():
files['/etc/cron.d/{}'.format(crontab)] = {
'source': 'cron_template',
'content_type': 'mako',

View file

@ -33,11 +33,13 @@ def patchday(metadata):
return {
'cron': {
'upgrade-and-reboot': '{minute} {hour} * * {day} root /usr/local/sbin/upgrade-and-reboot'.format(
minute=node.magic_number % 30,
hour=hour,
day=day,
),
'jobs': {
'upgrade-and-reboot': '{minute} {hour} * * {day} root /usr/local/sbin/upgrade-and-reboot'.format(
minute=node.magic_number % 30,
hour=hour,
day=day,
),
},
},
}

View file

@ -1,5 +1,5 @@
@metadata_reactor.provides(
'cron/check-mail-received',
'cron/jobs/check-mail-received',
'icinga2_api/check-mail-received/services',
)
def process_metadata(metadata):
@ -30,7 +30,9 @@ def process_metadata(metadata):
return {
'cron': {
'check-mail-received': '\n'.join(sorted(cron)),
'jobs': {
'check-mail-received': '\n'.join(sorted(cron)),
},
},
'icinga2_api': {
'check-mail-received': {

View file

@ -3,5 +3,6 @@
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=${node.metadata.get('cron/mail_to', repo.libs.defaults.hostmaster_email)}
${cron}

View file

@ -3,6 +3,7 @@
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=${node.metadata.get('cron/mail_to', repo.libs.defaults.hostmaster_email)}
${min} * * * * root cd / && run-parts --report /etc/cron.hourly
${min} 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

View file

@ -31,7 +31,7 @@ svc_systemd = {
},
}
for crontab, content in node.metadata.get('cron', {}).items():
for crontab, content in node.metadata.get('cron/jobs', {}).items():
files['/etc/cron.d/{}'.format(crontab)] = {
'source': 'cron_template',
'content_type': 'mako',

View file

@ -13,10 +13,6 @@ defaults = {
},
},
},
'cron': {
'letsencrypt_renew': '{} 4 * * * root /usr/bin/dehydrated --cron --accept-terms --challenge http-01 > /dev/null'.format((node.magic_number % 60)),
'letsencrypt_cleanup': '{} 4 * * 0 root /usr/bin/dehydrated --cleanup > /dev/null'.format((node.magic_number % 60)),
},
'pacman': {
'packages': {
'dehydrated': {
@ -27,3 +23,21 @@ defaults = {
},
},
}
@metadata_reactor.provides(
'cron/jobs/letsencrypt',
)
def cron(metadata):
if node.metadata.get('letsencrypt/domains'):
return {
'cron': {
'jobs': {
'letsencrypt': '\n'.join([
'{} 4 * * * root /usr/bin/dehydrated --cron --accept-terms --challenge http-01 > /dev/null'.format((node.magic_number % 60)),
'{} 4 * * 0 root /usr/bin/dehydrated --cleanup > /dev/null'.format((node.magic_number % 60)),
]),
},
},
}
return {}

View file

@ -22,10 +22,12 @@ defaults = {
},
},
'cron': {
'netbox': '{m} {h} * * * netbox /opt/netbox/venv/bin/python /opt/netbox/src/netbox/manage.py housekeeping'.format(
m=node.magic_number%60,
h=node.magic_number%4,
),
'jobs': {
'netbox': '{m} {h} * * * netbox /opt/netbox/venv/bin/python /opt/netbox/src/netbox/manage.py housekeeping'.format(
m=node.magic_number%60,
h=node.magic_number%4,
),
},
},
'postgresql': {
'databases': {

View file

@ -9,7 +9,9 @@ defaults = {
},
},
'cron': {
'restart-pppoe-if-no-public-ip': '*/5 * * * * root /usr/local/bin/restart-pppoe-if-no-public-ip',
'jobs': {
'restart-pppoe-if-no-public-ip': '*/5 * * * * root /usr/local/bin/restart-pppoe-if-no-public-ip',
},
},
'icinga2_api': {
'pppd': {

View file

@ -45,7 +45,9 @@ defaults = {
},
},
'cron': {
'clamav-unofficial-sigs': f'{node.magic_number%60} */4 * * * clamav /usr/sbin/clamav-unofficial-sigs >/dev/null 2>&1',
'jobs': {
'clamav-unofficial-sigs': f'{node.magic_number%60} */4 * * * clamav /usr/sbin/clamav-unofficial-sigs >/dev/null 2>&1',
},
},
'postfix': {
'aliases': {

View file

@ -14,7 +14,9 @@ defaults = {
},
},
'cron': {
# Automatically remove files which are older than 14 days
'scansnap_cleanup': '00 00 * * * root /usr/bin/find /srv/scansnap/ -mindepth 1 -mtime +14 -delete',
'jobs': {
# Automatically remove files which are older than 14 days
'scansnap_cleanup': '00 00 * * * root /usr/bin/find /srv/scansnap/ -mindepth 1 -mtime +14 -delete',
},
},
}

View file

@ -83,7 +83,7 @@ def telegraf(metadata):
@metadata_reactor.provides(
'cron/smartd',
'cron/jobs/smartd',
)
def monthly_long_test(metadata):
lines = set()
@ -96,6 +96,8 @@ def monthly_long_test(metadata):
return {
'cron': {
'smartd': '\n'.join(sorted(lines)),
'jobs': {
'smartd': '\n'.join(sorted(lines)),
},
},
}

View file

@ -8,12 +8,14 @@ defaults = {
},
},
'cron': {
'unbound_refresh_root-hints': '{} {} * * {} root wget -q -O/etc/unbound/root-hints.txt https://www.internic.net/domain/named.root'.format(
node.magic_number%60,
node.magic_number%24,
node.magic_number%7,
),
'unbound-auto-restart': '* * * * * root /usr/local/sbin/unbound-auto-restart',
'jobs': {
'unbound_refresh_root-hints': '{} {} * * {} root wget -q -O/etc/unbound/root-hints.txt https://www.internic.net/domain/named.root'.format(
node.magic_number%60,
node.magic_number%24,
node.magic_number%7,
),
'unbound-auto-restart': '* * * * * root /usr/local/sbin/unbound-auto-restart',
},
},
'nameservers': {
'127.0.0.1',

View file

@ -35,10 +35,12 @@ defaults = {
},
},
'cron': {
'zfs-auto-snapshot-daily': '0 0 * * * root /usr/local/sbin/zfs-auto-snapshot daily',
'zfs-auto-snapshot-hourly': '0 * * * * root /usr/local/sbin/zfs-auto-snapshot hourly',
'zfs-auto-snapshot-monthly': '0 0 1 * * root /usr/local/sbin/zfs-auto-snapshot monthly',
'zfs-auto-snapshot-weekly': '0 0 * * 7 root /usr/local/sbin/zfs-auto-snapshot weekly',
'jobs': {
'zfs-auto-snapshot-daily': '0 0 * * * root /usr/local/sbin/zfs-auto-snapshot daily',
'zfs-auto-snapshot-hourly': '0 * * * * root /usr/local/sbin/zfs-auto-snapshot hourly',
'zfs-auto-snapshot-monthly': '0 0 1 * * root /usr/local/sbin/zfs-auto-snapshot monthly',
'zfs-auto-snapshot-weekly': '0 0 * * 7 root /usr/local/sbin/zfs-auto-snapshot weekly',
},
},
'icinga2_api': {
'zfs': {
@ -103,13 +105,15 @@ if node.has_bundle('telegraf'):
@metadata_reactor.provides(
'cron/zfs-scrub',
'cron/jobs/zfs-scrub',
)
def zfs_scrub_cronjob(metadata):
when = metadata.get('zfs/scrub/cron', '{} 0 * * sun'.format((node.magic_number % 60)))
return {
'cron': {
'zfs-scrub': '{} root /usr/lib/zfs-linux/scrub'.format(when),
'jobs': {
'zfs-scrub': '{} root /usr/lib/zfs-linux/scrub'.format(when),
},
},
}