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 937235f..7e262d7 100755 --- a/sync.sh +++ b/sync.sh @@ -12,11 +12,23 @@ else 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} ] + then + 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 # 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"