From e9ae9dea8c07fb6fde03a2569c330d33fa9cc513 Mon Sep 17 00:00:00 2001 From: Alin Voinea Date: Wed, 27 Apr 2016 11:33:03 +0300 Subject: [PATCH] Add support for multiple cron jobs within rsync client --- Readme.md | 5 +++-- docker-entrypoint.sh | 14 ++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index a02f439..237d52f 100644 --- a/Readme.md +++ b/Readme.md @@ -19,10 +19,11 @@ Get files from `remote server` to a `data container`: ### Client setup -Start client to sync every night at 3AM: +Start client to pack and sync every night: $ docker run --name=rsync_client -v client_vol_to_sync:/data \ - -e CRON_TASK="0 3 * * * rsync -e 'ssh -p 2222 -o StrictHostKeyChecking=no' -avz root@foo.bar.com:/data/ /data/" \ + -e CRON_TASK_1="0 1 * * * /data/pack-db.sh" \ + -e CRON_TASK_2="0 3 * * * rsync -e 'ssh -p 2222 -o StrictHostKeyChecking=no' -avz root@foo.bar.com:/data/ /data/" \ eeacms/rsync client Copy the client SSH public key printed found in console diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 5749260..1ea3bb3 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -13,10 +13,16 @@ if [ ! -z "$SSH_AUTH_KEY" ]; then fi # Provide CRON_TASK via environment variable -if [ ! -z "$CRON_TASK" ]; then - echo "$CRON_TASK" > /etc/crontabs/root - echo "root" > /etc/crontabs/cron.update -fi +echo '' > /etc/crontabs/root +for item in `env`; do + case "$item" in + CRON_TASK*) + ENVVAR=`echo $item | cut -d \= -f 1` + printenv $ENVVAR >> /etc/crontabs/root + echo "root" > /etc/crontabs/cron.update + ;; + esac +done # Generate host SSH keys if [ ! -e /etc/ssh/ssh_host_rsa_key.pub ]; then