From a05941eb499f2f0f592233df17fd8e1faf4a1d71 Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Sat, 6 Aug 2022 15:34:15 -0500 Subject: [PATCH] make the sync delay disabled by default, allow setting maximum delay --- client/build/entrypoint.sh | 6 +++--- client/build/sync.sh | 4 ++-- client/docker-compose.yaml | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/client/build/entrypoint.sh b/client/build/entrypoint.sh index 057563e..5133922 100644 --- a/client/build/entrypoint.sh +++ b/client/build/entrypoint.sh @@ -4,10 +4,10 @@ set -e chmod 600 /syncer/.ssh/id_syncer echo -e "\n[$(date +"%Y/%m/%d-%H:%M:%S")] Performing initial sync..." -/syncer/sync.sh now > /proc/self/fd/1 2>/proc/self/fd/2 +/syncer/sync.sh > /proc/self/fd/1 2>/proc/self/fd/2 echo -e "\n[$(date +"%Y/%m/%d-%H:%M:%S")] Creating cron job..." -if [ "$SYNC_DELAY" == "false" ]; then - echo "$SYNC_SCHEDULE /syncer/sync.sh now > /proc/self/fd/1 2>/proc/self/fd/2" >> $CRONTAB_FILE +if [ "$SYNC_DELAY" == "true" ]; then + echo "$SYNC_SCHEDULE /syncer/sync.sh delay > /proc/self/fd/1 2>/proc/self/fd/2" >> $CRONTAB_FILE else echo "$SYNC_SCHEDULE /syncer/sync.sh > /proc/self/fd/1 2>/proc/self/fd/2" >> $CRONTAB_FILE fi diff --git a/client/build/sync.sh b/client/build/sync.sh index 9a9d38f..485a632 100644 --- a/client/build/sync.sh +++ b/client/build/sync.sh @@ -3,9 +3,9 @@ set -e # initial sync is immediate, cron syncs have a random delay unless $CRON_DELAY==false -if [ $1 != "now" ]; then +if [ $1 == "delay" ]; then echo -e "\n[$(date +"%Y/%m/%d-%H:%M:%S")] Waiting for random delay..." - sleep $(( RANDOM )) + sleep $(( RANDOM % SYNC_DELAY_MAX_SECONDS + 1 )) echo -e "[$(date +"%Y/%m/%d-%H:%M:%S")] Sync starts NOW!" else echo -e "\n[$(date +"%Y/%m/%d-%H:%M:%S")] Immediate sync starts NOW!" diff --git a/client/docker-compose.yaml b/client/docker-compose.yaml index 7419d9a..4055156 100644 --- a/client/docker-compose.yaml +++ b/client/docker-compose.yaml @@ -10,6 +10,7 @@ services: - SYNC_PORT=2222 - SYNC_SCHEDULE=0 21 * * 5 - SYNC_DELAY=true + - SYNC_DELAY_MAX_SECONDS=21600 - TLS_NAME=library.lab.bowdre.net - TLS_CUSTOM_CERT=true ports: