>_ IzzyLab

Hands-on task

This task is step 11 of the course “Shipping a release”

A post-release smoke test via cron

medium~15 min

The release is out — now you need a smoke test for the future. Write an executable script /usr/local/bin/smoke-test that takes a URL as its first argument and exits with code 0 if the URL answered HTTP 200, and 1 in any other case (404, 500, the service not answering). Then add a cron job (any user's crontab or a file in /etc/cron.d/) that runs it every 5 minutes against http://localhost:8090/healthz and appends the output to /var/log/billing-smoke.log.

What you'll practise:
  • curl http_code
  • exit code
  • cron
  • */N
  • appending >>

Topic breakdown

A smoke test is the minimal "is the service alive at all" check right after a rollout and then on a schedule. It reports the result through its exit code: 0 means all good, non-zero means alarm, and every kind of automation, from cron to CI, is built on that. What matters is the HTTP status, not whether the server answered at all: curl without flags exits successfully on a 404 too, so the response code is pulled out with -w '%{http_code}', and the body is thrown into /dev/null. The periodic run is a cron line with a */5 step in the minutes field and the output appended to a log with >>.

What's checked

  1. the smoke-test script is executable
  2. for a live /healthz — code 0
  3. for a 404 answer — code 1
  4. for a service that's down — code 1
  5. cron runs smoke-test every 5 minutes

What it looks like