From cef4a6eb0dcac1ad5ce919c61edea25d50b1db1d Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Wed, 15 Mar 2023 14:44:08 -0300 Subject: system.scm: Add daily cronjob for system checks check.sh: sends emails to important RFC aliases, so that one verifies it daily. --- src/infrastructure/guix/system.scm | 2 + src/infrastructure/scripts/check.sh | 79 +++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 src/infrastructure/scripts/check.sh (limited to 'src') diff --git a/src/infrastructure/guix/system.scm b/src/infrastructure/guix/system.scm index 501c136..d744624 100644 --- a/src/infrastructure/guix/system.scm +++ b/src/infrastructure/guix/system.scm @@ -312,6 +312,7 @@ (list (script "r" (file "src/infrastructure/scripts/r.sh")) (script "gc" (file "src/infrastructure/scripts/gc.sh")) + (script "check" (file "src/infrastructure/scripts/check.sh")) (script "backup" (file "src/infrastructure/scripts/backup.sh")) (script "deploy" (file "src/infrastructure/scripts/deploy.sh")) (script "report" (file "src/infrastructure/scripts/report.sh")) @@ -347,6 +348,7 @@ (mcron-configuration (jobs (list + #~(job "0 0 * * *" "cronjob check") #~(job "0 1 * * *" "cronjob env BORG_REPO=/mnt/backup/borg backup -q cron") #~(job "0 2 * * *" "cronjob backup -q cron") #~(job "0 3 * * 0" "cronjob gc") diff --git a/src/infrastructure/scripts/check.sh b/src/infrastructure/scripts/check.sh new file mode 100755 index 0000000..53d088c --- /dev/null +++ b/src/infrastructure/scripts/check.sh @@ -0,0 +1,79 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + check + check -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + + Run system sanity checks, such as email reachability, alarms + reachability, etc. + + + Examples: + + Just run it + + $ check + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + + +if [ "$(id -un)" != 'root' ]; then + printf 'This script must be run as root.\n\n' >&2 + usage >&2 + exit 2 +fi + + +uuid() { + od -xN20 /dev/urandom | + head -n1 | + awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}' +} + +for alias in abuse admin postmaster hostmaster; do + uuid | mail -s "\"$alias\" alias test" "$alias@$(hostname)" +done -- cgit v1.2.3