Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Healthchecks.io start ping before sync #10

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
12 changes: 12 additions & 0 deletions sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down