Bash: text processing and scripts / Stage 7 of 9 · step 7 of 8
Write a healthcheck to a contract
Situation
The deploy does not send traffic to a new app version right away: first it asks the
~/bash-lab/healthcheck.sh script whether the address is ready. The deploy looks at the exit
status, the on-call engineer reads the output line. The script does not exist yet — there is a
stub with a shebang line.
A test app runs on the machine for your experiments, http://127.0.0.1:8181:
| Path | Response |
|---|---|
/ready |
200 |
/unready |
503 |
/empty |
204 |
/redirect |
302 to /ready |
/slow |
200, but after 10 seconds |
Nothing listens on port 8182.
Task
Finish ~/bash-lab/healthcheck.sh to the contract with the deploy:
- The deploy runs the script by its path:
~/bash-lab/healthcheck.sh URL. - The server answered 200 — the script prints the line
OKto stdout and exits with 0. - The server answered anything else (503, 204, 302, 404) —
FAILand exit status 1. The script does not follow a redirect. - The server refuses the connection —
FAILand exit status 1. - No response for 2 seconds —
FAILand exit status 1; the script ends by itself within 3 seconds. - No address or two arguments — empty stdout, the line
Usage: healthcheck.sh URLon stderr, exit status 2.
When the server answered — with any code — stderr stays empty: the deploy treats a line there as a failure of the check itself.
The check runs your script as student on these addresses and on its own — with other paths and responses.
The machine has no Internet; everything you need is already installed.
Lab goals
0 of 6-
~/bash-lab/healthcheck.sh runs by its path as a command — not checked yet
-
A 200 response gives OK on stdout, exit status 0, empty stderr — not checked yet
-
Any other server response gives FAIL, exit status 1, empty stderr — not checked yet
-
A server that refuses the connection gives FAIL, exit status 1 — not checked yet
-
No response for 2 seconds gives FAIL, exit status 1, and the script ends by itself within 3 seconds — not checked yet
-
No address or two arguments give Usage on stderr, empty stdout, exit status 2 — not checked yet