From b5f5ecfcff3ca73264b2290fbe698b9cb8f1c56d Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Fri, 17 Apr 2020 09:24:59 +0200 Subject: adding wrapper-script for cron --- mkosibuild-cron | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 mkosibuild-cron (limited to 'mkosibuild-cron') diff --git a/mkosibuild-cron b/mkosibuild-cron new file mode 100755 index 0000000..8b45a1a --- /dev/null +++ b/mkosibuild-cron @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# made by Dennis Eriksen in 2020. + +# Exit on error. Append "|| true" if you expect an error. +set -o errexit +# Exit on error inside any functions or subshells. +set -o errtrace +# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR +set -o nounset +# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip` +set -o pipefail + + +LOGDIR=/var/log/mkosibuild/ +BACKUPDIR=/var/lib/machines/.backup +BACKUPNUM=5 +EXEC=mkosibuild # This provides the exec is in your $PATH +CRONSUFFIX="-cron" # Suffix for backups made through cron + +export CRON=true +export CRONSUFFIX + +MACHINES=() + +# Import config to override above config +[[ -r /etc/mkosibuild ]] && . /etc/mkosibuild + +# Check if logdir exists, and create it if not +[[ -d "${LOGDIR}" ]] || mkdir "${LOGDIR}" + +for machine in ${MACHINES[*]}; do + LOG="${LOGDIR}/${machine}.log" + BUILDLOG="${LOGDIR}/${machine}.buildlog.$(date +%Y%m%d%H%M%S)" + touch "${LOG}" && chmod 600 "${LOG}" + #exec >> "${LOG}" + echo "" >> "${LOG}" + echo "Starting build $(date +%Y-%m-%d_%H:%M:%S)" >> "${LOG}" + ${EXEC} "$machine" &>> "${BUILDLOG}" + + # Delete old backups + find "${BACKUPDIR}" -name "${machine}.*${CRONSUFFIX}" | tail -n +$((BACKUPNUM + 1)) | xargs rm -fv -- >> "${LOG}" + +done -- cgit v1.2.3