From b529baf1907e5854d58a950a06d14c2ca2163262 Mon Sep 17 00:00:00 2001 From: Felix Bouleau Date: Wed, 10 Jul 2019 15:27:53 +0000 Subject: [PATCH 1/6] Adds Healthchecks.io start ping before sync --- sync.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sync.sh b/sync.sh index 937235f..71f419b 100755 --- a/sync.sh +++ b/sync.sh @@ -12,11 +12,18 @@ else echo $$ > /tmp/sync.pid if test "$(rclone ls --max-depth 1 $SYNC_SRC $RCLONE_OPTS)"; then + # Send "start" ping to HC, if set + if [ -n "$CHECK_URL" ] + then + wget "${CHECK_URL}/start" -O /dev/null + fi + # the source directory is not empty # it can be synced without clear data loss echo "INFO: Starting rclone sync $SYNC_SRC $SYNC_DEST $RCLONE_OPTS $SYNC_OPTS" rclone sync $SYNC_SRC $SYNC_DEST $RCLONE_OPTS $SYNC_OPTS - + + # Send "done" ping to HC, if set if [ -z "$CHECK_URL" ] then echo "INFO: Define CHECK_URL with https://healthchecks.io to monitor sync job" From d6f96247eda0132b493a1310a07b9196729e68b4 Mon Sep 17 00:00:00 2001 From: Felix Bouleau Date: Thu, 11 Jul 2019 11:25:00 +0000 Subject: [PATCH 2/6] Parameterize START_URL, and add to readme --- Dockerfile | 1 + README.md | 1 + sync.sh | 11 ++++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 25804ba..89dc049 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ ENV CRON= ENV CRON_ABORT= ENV FORCE_SYNC= ENV CHECK_URL= +ENV START_URL= ENV TZ= RUN apk -U add ca-certificates fuse wget dcron tzdata \ diff --git a/README.md b/README.md index 67880ef..bff071d 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ A few environment variables allow you to customize the behavior of the sync: * `CRON_ABORT` crontab schedule `0 6 * * *` to abort sync at 6am * `FORCE_SYNC` set variable to perform a sync upon boot * `CHECK_URL` [healthchecks.io](https://healthchecks.io) url or similar cron monitoring to perform a `GET` after a successful sync +* `START_URL` same as `CHECK_URL`, but is called before sync starts. If `CHECK_URL` is defined as a healthchecks.io URL, this defaults to [${CHECK_URL}/start](https://healthchecks.io/docs/#start-event). * `SYNC_OPTS` additional options for `rclone sync` command. Defaults to `-v` * `TZ` set the [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) to use for the cron and log `America/Argentina/Buenos_Aires` diff --git a/sync.sh b/sync.sh index 71f419b..51cfcab 100755 --- a/sync.sh +++ b/sync.sh @@ -12,10 +12,15 @@ else echo $$ > /tmp/sync.pid if test "$(rclone ls --max-depth 1 $SYNC_SRC $RCLONE_OPTS)"; then - # Send "start" ping to HC, if set - if [ -n "$CHECK_URL" ] + # Send a start ping if a) START_URL is explicitly set OR b) if Healthchecks.io is used as CHECK_URL provider + if [ -z ${START_URL+x} ] then - wget "${CHECK_URL}/start" -O /dev/null + if echo "$CHECK_URL" | grep "hc-ping" + then + wget "${CHECK_URL}/start" -O /dev/null + fi + else + wget $START_URL -O /dev/null fi # the source directory is not empty From 01162decb8f5af64c75ce46c9f3f19944a5af1ad Mon Sep 17 00:00:00 2001 From: Felix Bouleau Date: Thu, 11 Jul 2019 11:35:40 +0000 Subject: [PATCH 3/6] Don't use +x evaluation in sync.sh --- sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync.sh b/sync.sh index 51cfcab..ceb82a1 100755 --- a/sync.sh +++ b/sync.sh @@ -13,7 +13,7 @@ echo $$ > /tmp/sync.pid if test "$(rclone ls --max-depth 1 $SYNC_SRC $RCLONE_OPTS)"; then # Send a start ping if a) START_URL is explicitly set OR b) if Healthchecks.io is used as CHECK_URL provider - if [ -z ${START_URL+x} ] + if [ -z ${START_URL} ] then if echo "$CHECK_URL" | grep "hc-ping" then From 671ef4c2f636c1530b28e67d14b7e2925ce5af56 Mon Sep 17 00:00:00 2001 From: Felix Bouleau Date: Thu, 11 Jul 2019 11:45:02 +0000 Subject: [PATCH 4/6] Remove some stupid whitespace --- sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync.sh b/sync.sh index ceb82a1..2bd93b3 100755 --- a/sync.sh +++ b/sync.sh @@ -27,7 +27,7 @@ if test "$(rclone ls --max-depth 1 $SYNC_SRC $RCLONE_OPTS)"; then # it can be synced without clear data loss echo "INFO: Starting rclone sync $SYNC_SRC $SYNC_DEST $RCLONE_OPTS $SYNC_OPTS" rclone sync $SYNC_SRC $SYNC_DEST $RCLONE_OPTS $SYNC_OPTS - + # Send "done" ping to HC, if set if [ -z "$CHECK_URL" ] then From b67674fb6d084e2734b2fef1448ad124079e57fe Mon Sep 17 00:00:00 2001 From: Felix Bouleau Date: Thu, 11 Jul 2019 14:58:17 +0000 Subject: [PATCH 5/6] Re-add -x in START_URL eval, but don't define it in Dockerfile --- Dockerfile | 1 - sync.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 89dc049..25804ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,6 @@ ENV CRON= ENV CRON_ABORT= ENV FORCE_SYNC= ENV CHECK_URL= -ENV START_URL= ENV TZ= RUN apk -U add ca-certificates fuse wget dcron tzdata \ diff --git a/sync.sh b/sync.sh index 2bd93b3..662a35d 100755 --- a/sync.sh +++ b/sync.sh @@ -13,7 +13,7 @@ echo $$ > /tmp/sync.pid if test "$(rclone ls --max-depth 1 $SYNC_SRC $RCLONE_OPTS)"; then # Send a start ping if a) START_URL is explicitly set OR b) if Healthchecks.io is used as CHECK_URL provider - if [ -z ${START_URL} ] + if [ -z ${START_URL+x} ] then if echo "$CHECK_URL" | grep "hc-ping" then From dc19e945cab97cf5aa18f53ba126c51145928a1b Mon Sep 17 00:00:00 2001 From: Felix Bouleau Date: Thu, 11 Jul 2019 15:03:17 +0000 Subject: [PATCH 6/6] Remove curly brackets from start URL concat --- sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync.sh b/sync.sh index 662a35d..7e262d7 100755 --- a/sync.sh +++ b/sync.sh @@ -17,7 +17,7 @@ if test "$(rclone ls --max-depth 1 $SYNC_SRC $RCLONE_OPTS)"; then then if echo "$CHECK_URL" | grep "hc-ping" then - wget "${CHECK_URL}/start" -O /dev/null + wget "$CHECK_URL/start" -O /dev/null fi else wget $START_URL -O /dev/null