commit a94ea0fb19c2b88449e826f6d081eefbc8308277 Author: yohan <783b8c87@scimetis.net> Date: Wed Feb 26 18:11:28 2020 +0100 Initial commit. diff --git a/crontab-example b/crontab-example new file mode 100644 index 0000000..71130a0 --- /dev/null +++ b/crontab-example @@ -0,0 +1,13 @@ +# /etc/crontab: system-wide crontab +# Unlike any other crontab you don't have to run the `crontab' +# command to install the new version when you edit this file +# and files in /etc/cron.d. These files also have username fields, +# that none of the other crontabs do. + +SHELL=/bin/sh +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +# m | h | day of month | month | day of week | user | command +3 0 * * * root docker -H tcp://127.0.0.1:2375 exec mysql-server /root/nettoyer_quotas.sh > /proc/1/fd/2 2>&1 +3 1 * * * root docker -H tcp://127.0.0.1:2375 exec mysql-server sh -c "mysqldump --databases mysql -uroot -pXXXXXXXX > /mnt/dumps/mysql_dump-mysql_`date +\%d-\%m-\%Y`" > /proc/1/fd/2 2>&1 +13 1 * * * root docker -H tcp://127.0.0.1:2375 exec mysql-server sh -c "mysqldump --databases gogs owncloud semanticscuttle -uroot -pXXXXXXXX > /mnt/dumps/mysql_dump_`date +\%d-\%m-\%Y`" > /proc/1/fd/2 2>&1 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0d9fde6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: "2.1" + +services: + + cron: + image: cron:$VERSION_CRON + restart: always + network_mode: "host" + volumes: + - ./crontab:/etc/crontab:Z diff --git a/start_or_update.sh b/start_or_update.sh new file mode 100755 index 0000000..e44a282 --- /dev/null +++ b/start_or_update.sh @@ -0,0 +1,29 @@ +#!/bin/bash +test -z $1 || HOST="_$1" +test -z $2 || INSTANCE="_$2" +if ! test -f ~/secrets.tar.gz.enc +then + curl -o ~/secrets.tar.gz.enc "https://cloud.scimetis.net/s/${KEY}/download?path=%2F&files=secrets.tar.gz.enc" + if ! test -f ~/secrets.tar.gz.enc + then + echo "ERROR: ~/secrets.tar.gz.enc not found, exiting." + exit 1 + fi +fi +openssl enc -aes-256-cbc -d -in ~/secrets.tar.gz.enc | tar -zxv --strip 2 secrets/docker-cron-global-stack${HOST}${INSTANCE}/crontab +sudo chown root. crontab +sudo chmod 644 crontab + +unset VERSION_CRON +export VERSION_CRON=$(git ls-remote https://git.scimetis.net/yohan/docker-cron.git| head -1 | cut -f 1|cut -c -10) + +rm -rf ~/build +mkdir -p ~/build +git clone https://git.scimetis.net/yohan/docker-cron.git ~/build/docker-cron +sudo docker build -t cron:$VERSION_CRON ~/build/docker-cron + +sudo -E bash -c 'docker-compose up -d --force-recreate' +# --force-recreate is used to recreate container when crontab file has changed +# We cannot remove the secrets files or restarting the container would become impossible +# rm -f crontab +rm -rf ~/build