make the sync delay disabled by default, allow setting maximum delay

This commit is contained in:
John Bowdre 2022-08-06 15:34:15 -05:00
parent 2bce5b0727
commit a05941eb49
3 changed files with 6 additions and 5 deletions

View file

@ -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

View file

@ -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!"

View file

@ -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: