From 713f65865c0664696516af3af5b8616e837b38e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Sun, 31 Jan 2016 22:39:56 +0200 Subject: [PATCH] Updated cron example. Fixes #37 --- static/css/docs.css | 4 ++ templates/base.html | 1 + templates/front/docs.html | 53 +++++++++++++++++++++++---- templates/front/snippets/bash.html | 2 +- templates/front/snippets/bash.txt | 2 +- templates/front/snippets/crontab.html | 2 +- templates/front/snippets/crontab.txt | 2 +- 7 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 static/css/docs.css diff --git a/static/css/docs.css b/static/css/docs.css new file mode 100644 index 00000000..42f16619 --- /dev/null +++ b/static/css/docs.css @@ -0,0 +1,4 @@ +.curl-opts th { + white-space: nowrap; + font-family: monospace; +} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 3c832476..d96e1ea5 100644 --- a/templates/base.html +++ b/templates/base.html @@ -16,6 +16,7 @@ + diff --git a/templates/front/docs.html b/templates/front/docs.html index 6d13c7d2..8fa84643 100644 --- a/templates/front/docs.html +++ b/templates/front/docs.html @@ -8,7 +8,7 @@

Summary

-Each check you create in My Checks +Each check in My Checks page has an unique "ping" URL. Whenever you access this URL, the "Last Ping" value of corresponding check is updated.

@@ -25,8 +25,7 @@ It is all very simple, really.

  • HTTP and HTTPS protocols both are fine
  • Request method can be GET, POST or HEAD
  • Both IPv4 and IPv6 work
  • -
  • It does not matter what request headers you send
  • -
  • You can leave request body empty or put anything in it, it's all good
  • +
  • It does not matter what request headers you send, or what you put in request body.
  • The response will have status code "200 OK" and response body will be a @@ -39,10 +38,10 @@ short and simple string "OK".

    Crontab

    -When using cron, probably the easiest is to append a curl -or wget call after your command. The scheduled time comes, -and your command runs. After it completes, the healthchecks.io check -gets pinged. +When using cron, probably the easiest is to append a curl +or wget call after your command. The scheduled time comes, +and your command runs. If it completes successfully (exit code 0), +curl or wget runs a HTTP GET call to the ping URL.

    {% include "front/snippets/crontab.html" %} @@ -59,6 +58,46 @@ scenarios:

    Either way, when your task doesn't finish successfully, you will soon know about it.

    +

    The extra options to curl are meant to suppress any output, unless it hits +an error. This is to prevent cron from sending an email every time the +task runs. Feel free to adjust the curl options to your liking. +

    + + + + + + + + + + + + + + + + + + + + + + + + + +
    &&Run curl only if /home/user/backup.sh succeeds
    + -f, --fail + Makes curl treat non-200 responses as errors
    -s, --silentSilent or quiet mode. Don't show progress meter or error messages.
    -S, --show-errorWhen used with -s it makes curl show error message if it fails.
    --retry <num> + If a transient error is returned when curl tries to perform a + transfer, it will retry this number of times before giving up. + Setting the number to 0 makes curl do no retries + (which is the default). Transient error means either: a timeout, + an FTP 4xx response code or an HTTP 5xx response code. +
    > /dev/null + Redirect curl's stdout to /dev/null (error messages go to stderr,) +

    Bash or a shell script

    diff --git a/templates/front/snippets/bash.html b/templates/front/snippets/bash.html index 177caf4c..f3238c16 100644 --- a/templates/front/snippets/bash.html +++ b/templates/front/snippets/bash.html @@ -1,5 +1,5 @@
    # using curl:
    -curl {{ ping_url }}
    +curl --retry 3 {{ ping_url }}
     
     # using wget:
     wget {{ ping_url }} -O /dev/null
    diff --git a/templates/front/snippets/bash.txt b/templates/front/snippets/bash.txt
    index 30d8a114..cdca954f 100644
    --- a/templates/front/snippets/bash.txt
    +++ b/templates/front/snippets/bash.txt
    @@ -1,5 +1,5 @@
     # using curl:
    -curl PING_URL
    +curl --retry 3 PING_URL
     
     # using wget:
     wget PING_URL -O /dev/null
    \ No newline at end of file
    diff --git a/templates/front/snippets/crontab.html b/templates/front/snippets/crontab.html
    index 67581548..07afc5d4 100644
    --- a/templates/front/snippets/crontab.html
    +++ b/templates/front/snippets/crontab.html
    @@ -1,3 +1,3 @@
     
    # m h dom mon dow   command
    -  8 6 *   *   *     /home/user/tasks/backup_all.sh && curl {{ ping_url }}
    +  8 6 *   *   *     /home/user/backup.sh && curl -fsS --retry 3 {{ ping_url }} > /dev/null
     
    diff --git a/templates/front/snippets/crontab.txt b/templates/front/snippets/crontab.txt index c7e8aad3..1ff49e6f 100644 --- a/templates/front/snippets/crontab.txt +++ b/templates/front/snippets/crontab.txt @@ -1,2 +1,2 @@ # m h dom mon dow command - 8 6 * * * /home/user/tasks/backup_all.sh && curl PING_URL \ No newline at end of file + 8 6 * * * /home/user/backup.sh && curl -fsS --retry 3 PING_URL > /dev/null \ No newline at end of file