nix/nixos/hosts/framework-server/cron.nix

83 lines
5.7 KiB
Nix
Raw Normal View History

2023-12-07 10:16:46 +01:00
{ pkgs, ... }: {
2023-12-07 10:20:18 +01:00
services.cron = {
enable = true;
systemCronJobs = [
2023-12-08 11:18:06 +01:00
# Backups to nuc-docker01
2023-12-14 02:35:37 +01:00
''0 0 * * * root rsync --delete -avr /Storage/Data/Docker/sysctl.io/ root@nuc-docker01:/Storage/Data/Docker/sysctl.io/''
2023-12-14 00:26:51 +01:00
''0 3 * * * root rsync -avr /Storage/Data/Docker/sysctl.io/nextcloud/html/data/albert/files/InstantUpload/ root@nuc-docker01:/Storage/Video/Pictures/InstantUpload/''
''0 5 * * * root rsync -avr /Storage/Data/Docker/sysctl.io/nextcloud/html/data/albert/files/Wallpapers/ root@nuc-docker01:/Storage/Video/Pictures/Wallpapers''
2023-12-08 11:18:06 +01:00
# DERP relay certs
''@daily root cp /Storage/Data/Docker/sysctl.io/letsencrypt/certs/certs/\*.sysctl.io.crt /Storage/Data/Docker/sysctl.io/letsencrypt/certs/certs/derp.sysctl.io.crt''
''@daily root cp /Storage/Data/Docker/sysctl.io/letsencrypt/certs/private/\*.sysctl.io.key /Storage/Data/Docker/sysctl.io/letsencrypt/certs/private/derp.sysctl.io.key''
# Back up the docker containers monthly:
''@monthly root ssh nuc-docker01 "rm -rf /Storage/Backups/Docker/sysctl.io/*"; for i in $(docker ps --format '{{.Names}}'); do docker export $i | gzip -cf | ssh root@nuc-docker01 "cat > /Storage/Backups/Docker/sysctl.io/$i.tar.gz"; done''
2023-12-08 11:18:06 +01:00
# Set a random Pi-Hole password
2023-12-10 08:04:28 +01:00
''* * * * * root docker exec pihole sudo pihole -a -p $(openssl rand -hex 128)''
2023-12-08 11:18:06 +01:00
# Run the ClamAV scan
2023-12-10 07:54:22 +01:00
''@monthly root /Storage/Data/docker-compose/sysctl.io/scripts/clamscan-cron.sh''
# Archive Loki logs monthly
2023-12-10 07:54:22 +01:00
''@monthly root /Storage/Data/docker-compose/sysctl.io/scripts/backup-logs.sh >> /Storage/Data/Temporary/log_backups.log''
2023-12-14 08:35:14 +01:00
# Run the ClamAV scan
''@monthly root /Storage/Data/docker-compose/sysctl.io/scripts/clamscan-cron.sh''
2023-12-27 12:46:11 +01:00
# Run the Nextcloud cronjobs hourly
2023-12-27 12:46:54 +01:00
''@hourly root docker exec -uwww-data nextcloud php -f /var/www/html/cron.php''
2023-12-27 12:54:13 +01:00
# Run the Pixelfed scheduler
''* * * * * root docker exec pixelfed-app php artisan schedule:run''
# Update / CLean Mastodon caches
''@daily root docker exec mastodon-web tootctl preview_cards remove --days 7''
''@daily root docker exec mastodon-web tootctl media remove --days 7 --prune-profiles''
''@daily root docker exec mastodon-web tootctl accounts prune''
''@daily root docker exec mastodon-web tootctl statuses remove --days 7''
''@daily root docker exec mastodon-web tootctl media remove --remove-headers --include-follows --days 7''
''@daily root docker exec mastodon-web tootctl preview_cards remove --days 7''
''@daily root docker exec mastodon-web tootctl media remove-orphans''
2023-12-07 10:20:18 +01:00
];
};
2024-01-02 13:26:44 +01:00
}
2023-12-08 11:18:06 +01:00
# Old crontab:
# # At reboot, apply the ip_tables modprobe so Wireguard works
# @reboot /usr/sbin/modprobe ip_tables
#
# # At reboot, restart Docker. Otherwise, iptables / the firewall freaks out
# @reboot /usr/bin/systemctl stop docker; /usr/bin/systemctl start docker
#
# # Every day, get storage space for monitoring
# @daily source ~/.bashrc; for i in `ls /Storage/Data/Docker`; do echo echo "$(date): $(du -s /Storage/Data/Docker/$i)" | sed -e 's/\/Storage\/Data\/Docker\/\$i//' >> /root/sizes/$i.log; done
#
# # Clean up NextCloud files weekly to save space
# @weekly source ~/.bashrc; /usr/bin/docker exec -uwww-data nextcloud php occ versions:cleanup
2023-12-27 12:54:13 +01:00
# DONE # Run the Nextcloud cronjobs hourly
# DONE @hourly source ~/.bashrc; /usr/bin/docker exec -uwww-data nextcloud php -f /var/www/html/cron.php
2023-12-08 11:18:06 +01:00
#
#
# # Clear out Mastodon caches daily
2023-12-27 12:54:13 +01:00
# DONE @daily source ~/.bashrc; /usr/bin/docker exec mastodon-web tootctl preview_cards remove --days 1
# DONE @daily source ~/.bashrc; /usr/bin/docker exec mastodon-web tootctl media remove --days 1 --prune-profiles
# DONE @daily source ~/.bashrc; /usr/bin/docker exec mastodon-web tootctl accounts prune
# DONE @daily source ~/.bashrc; /usr/bin/docker exec mastodon-web tootctl statuses remove --days 1
# DONE @daily source ~/.bashrc; /usr/bin/docker exec mastodon-web tootctl media remove --remove-headers --include-follows --days 0
# DONE @daily source ~/.bashrc; /usr/bin/docker exec mastodon-web tootctl preview_cards remove --days 1
# DONE @daily source ~/.bashrc; /usr/bin/docker exec mastodon-web tootctl media remove-orphans
2023-12-08 11:18:06 +01:00
#
2023-12-27 12:54:13 +01:00
# DONE # Run the Pixelfed scheduler
# DONE * * * * * /usr/bin/docker exec pixelfed-app php artisan schedule:run
2023-12-08 11:18:06 +01:00
#
2023-12-27 12:54:13 +01:00
# DONE # Run the ClamAV scan
# DONE @monthly source ~/.bashrc; /Storage/Data/docker-compose/sysctl.io/scripts/clamscan-cron.sh
2023-12-08 11:18:06 +01:00
#
2023-12-27 12:54:13 +01:00
# DONE # Set a random PiHole password every minute
# DONE * * * * * /usr/bin/docker exec pihole sudo pihole -a -p $(openssl rand -hex 128)
2023-12-08 11:18:06 +01:00
#
2023-12-27 12:54:13 +01:00
# NOT NEEDED # back up crontab:
# NOT NEEDED # 0 0 * * * /usr/bin/crontab -l > /Storage/Data/Temporary/crontab
2023-12-08 11:18:06 +01:00
#
# # Back up and delete local copies of Loki logs monthly
2023-12-27 12:54:13 +01:00
# DONE @monthly source ~/.bashrc; /Storage/Data/docker-compose/sysctl.io/scripts/backup-logs.sh >> /Storage/Data/Temporary/log_backups.log
2023-12-08 11:18:06 +01:00
#
2023-12-27 12:54:13 +01:00
# DONE # Back up the docker containers weekly:
# DONE @weekly source ~/.bashrc; ssh nuc-docker01 "rm -rf /Storage/Backups/Docker/sysctl.io/*"; for i in $(docker ps --format '{{.Names}}'); do docker export $i | gzip -cf | ssh root@nuc-docker01 "cat > /Storage/Backups/Docker/sysctl.io/$i.tar.gz"; done
2023-12-08 11:18:06 +01:00
#
# # Set up DERP relay certs for headscale-derp:
2023-12-27 12:54:13 +01:00
# DONE @hourly cp /Storage/Data/Docker/letsencrypt/certs/certs/\*.sysctl.io.crt /Storage/Data/Docker/letsencrypt/certs/certs/derp.sysctl.io.crt
# DONE @hourly cp /Storage/Data/Docker/letsencrypt/certs/private/\*.sysctl.io.key /Storage/Data/Docker/letsencrypt/certs/private/derp.sysctl.io.key