From e852b0b2c26816334ad5b488f53a0424f9e37105 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Wed, 26 Feb 2020 17:36:09 +0100 Subject: [PATCH] Moved cron tasks to another stack. --- README | 1 - crontab-example | 13 ------------- docker-compose.yml | 8 -------- start_or_update.sh | 16 +++++++--------- 4 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 crontab-example diff --git a/README b/README index b33678c..faeee15 100644 --- a/README +++ b/README @@ -13,5 +13,4 @@ chcon -Rt svirt_sandbox_file_t /var/lib/docker-latest/volumes/mysql-server_dumps Utilisation : Les droits des fichiers doivent ĂȘtre corrigĂ©s avant de lancer la stack avec docker-compose up -d : -chcon -u system_u -r object_r -t svirt_sandbox_file_t crontab chcon -u system_u -r object_r -t svirt_sandbox_file_t nettoyer_quotas.sh diff --git a/crontab-example b/crontab-example deleted file mode 100644 index 71130a0..0000000 --- a/crontab-example +++ /dev/null @@ -1,13 +0,0 @@ -# /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 index 15f3bf9..a182db7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,14 +15,6 @@ services: - ./nettoyer_quotas.sh:/root/nettoyer_quotas.sh:Z - ./debian.cnf:/etc/mysql/debian.cnf:Z - cron: - image: cron:$VERSION_CRON - #build: "https://git.scimetis.net/yohan/docker-cron.git" - restart: always - network_mode: "host" - volumes: - - ./crontab:/etc/crontab:Z - networks: mysqlnet: diff --git a/start_or_update.sh b/start_or_update.sh index 9796252..861674d 100755 --- a/start_or_update.sh +++ b/start_or_update.sh @@ -2,15 +2,15 @@ test -z $1 || HOST="_$1" test -z $2 || INSTANCE="_$2" test -f ~/secrets.tar.gz.enc || { echo "ERROR: ~/secrets.tar.gz.enc not found, exiting."; exit 1; } -openssl enc -aes-256-cbc -d -in ~/secrets.tar.gz.enc | tar -zxv --strip 2 secrets/docker-mysql-stack${HOST}${INSTANCE}/crontab secrets/docker-mysql-stack${HOST}${INSTANCE}/debian.cnf -sudo chown root. crontab debian.cnf -sudo chmod 644 crontab +openssl enc -aes-256-cbc -d -in ~/secrets.tar.gz.enc | tar -zxv --strip 2 secrets/docker-mysql-stack${HOST}${INSTANCE}/debian.cnf +sudo chown root. debian.cnf test -f ~/openrc.sh || { echo "ERROR: ~/openrc.sh not found, exiting."; exit 1; } source ~/openrc.sh INSTANCE=$(/home/yohan/env_py3/bin/openstack server show -c id --format value $(hostname)) for VOLUME in mysql-server_data mysql-server_dumps do + mkdir -p /mnt/volumes/${VOLUME} if ! mountpoint -q /mnt/volumes/${VOLUME} then VOLUME_ID=$(/home/yohan/env_py3/bin/openstack volume show ${VOLUME} -c id --format value) @@ -29,7 +29,7 @@ sudo docker image inspect duplicity:latest &> /dev/null ||{ echo "ERROR: duplici rm -rf ~/build mkdir -p ~/build -for name in docker-cron docker-mysql +for name in docker-mysql do sudo -E docker run --rm -e SWIFT_USERNAME=$OS_USERNAME \ -e SWIFT_PASSWORD=$OS_PASSWORD \ @@ -43,16 +43,14 @@ do tar -xzf ~/build/${name}.tar.gz -C ~/build/ done -unset VERSION_MYSQL VERSION_CRON +unset VERSION_MYSQL DIRECTORY=$(pwd) cd ~/build/docker-mysql; export VERSION_MYSQL=$(git show-ref --head| head -1 | cut -f 1|cut -c -10); cd $DIRECTORY -cd ~/build/docker-cron; export VERSION_CRON=$(git show-ref --head| head -1 | cut -f 1|cut -c -10); cd $DIRECTORY sudo docker build -t mysql-server:$VERSION_MYSQL ~/build/docker-mysql -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 +# --force-recreate is used to recreate container when a file has changed # We cannot remove the secrets files or restarting the container would become impossible -# rm -f crontab debian.cnf +# rm -f debian.cnf rm -rf ~/build