From bf1a6b8565cd9db4e74bf4bca0d8789fbdb1dfd5 Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Mon, 8 Jan 2024 17:47:42 +0100 Subject: [PATCH] use txt file for start cron jobs --- deployment/hetzner_cloud/crontabs.txt | 38 +++++++++++++++++++++++++++ deployment/hetzner_cloud/install.sh | 11 ++++---- 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 deployment/hetzner_cloud/crontabs.txt diff --git a/deployment/hetzner_cloud/crontabs.txt b/deployment/hetzner_cloud/crontabs.txt new file mode 100644 index 000000000..c798b58c4 --- /dev/null +++ b/deployment/hetzner_cloud/crontabs.txt @@ -0,0 +1,38 @@ +# Edit this file to introduce tasks to be run by cron. +# +# Each task to run has to be defined through a single line +# indicating with different fields when the task will be run +# and what command to run for the task +# +# To define the time you can provide concrete values for +# minute (m), hour (h), day of month (dom), month (mon), +# and day of week (dow) or use '*' in these fields (for 'any'). +# +# Notice that tasks will be started based on the cron's system +# daemon's notion of time and timezones. +# +# Output of the crontab jobs (including errors) is sent through +# email to the user the crontab file belongs to (unless redirected). +# +# For example, you can run a backup of all your user accounts +# at 5 a.m every week with: +# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ +# +# For more information see the manual pages of crontab(5) and cron(8) +# +# m h dom mon dow command + +# `yarn` creates output in `/tmp` directory. This output is generated whenever `yarn start` is called. +# This is especially problematic on staging systems where instable versions are automatically deployed which can lead to an ever restarting, +# hence generating a lot of yarn output. +# the following hourly cron clean the /tmp folder +0 * * * * find /tmp -name "yarn--*" -exec rm -r {} \; > /dev/null + +# cronjob for a daily db backup at 3:00am +0 3 * * * ~/gradido/deployment/bare_metal/backup.sh + +# cronjob for a daily logfile clearance at 3:15 +# remove all log files older than 30 days +15 3 * * * ~/gradido/deployment/bare_metal/removeLogFiles.sh + + diff --git a/deployment/hetzner_cloud/install.sh b/deployment/hetzner_cloud/install.sh index 69224223a..f39ce6c32 100755 --- a/deployment/hetzner_cloud/install.sh +++ b/deployment/hetzner_cloud/install.sh @@ -9,6 +9,8 @@ systemctl start systemd-timesyncd set -o allexport SCRIPT_PATH=$(realpath ../bare_metal) SCRIPT_DIR=$(dirname $SCRIPT_PATH) +LOCAL_SCRIPT_PATH=$(realpath $0) +LOCAL_SCRIPT_DIR=$(dirname $SCRIPT_PATH) PROJECT_ROOT=$SCRIPT_DIR/.. set +o allexport @@ -121,12 +123,9 @@ envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/dht-node/.env # Configure federation envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/federation/.env.template > $PROJECT_ROOT/federation/.env -# create cronjob to delete yarn output in /tmp -# crontab -e -# hourly job: 0 * * * * find /tmp -name "yarn--*" -cmin +60 -exec rm -r {} \; > /dev/null -crontab -l | { cat; echo "0 * * * * find /tmp -name "yarn--*" -cmin +60 -exec rm -r {} \; > /dev/null"; } | crontab - -# daily job: 0 4 * * * find /tmp -name "yarn--*" -ctime +1 -exec rm -r {} \; > /dev/null -crontab -l | { cat; echo "0 4 * * * find /tmp -name "yarn--*" -ctime +1 -exec rm -r {} \; > /dev/null"; } | crontab - +# create cronjob to delete yarn output in /tmp and for making backups regulary +sudo -u gradido crontab < $LOCAL_SCRIPT_PATH/crontabs.txt + # Start gradido # Note: on first startup some errors will occur - nothing serious sudo -u gradido $SCRIPT_PATH/start.sh \ No newline at end of file