Step 7 of 8 · lab · 25 min
Write a healthcheck to a contract
The deploy needs a script that tells whether an address is ready for traffic. The answer is an OK or FAIL line and an exit status, even when the server stays silent.
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 · on your own
No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.
Goals
0 of 6-
~/bash-lab/healthcheck.sh runs by its path as a command — not done yet
-
A 200 response gives OK on stdout, exit status 0, empty stderr — not done yet
-
Any other server response gives FAIL, exit status 1, empty stderr — not done yet
-
A server that refuses the connection gives FAIL, exit status 1 — not done yet
-
No response for 2 seconds gives FAIL, exit status 1, and the script ends by itself within 3 seconds — not done yet
-
No address or two arguments give Usage on stderr, empty stdout, exit status 2 — not done yet
The machine is starting
Hints
0 of 3Lab goals
0 of 6-
~/bash-lab/healthcheck.sh runs by its path as a command — not done yet
-
A 200 response gives OK on stdout, exit status 0, empty stderr — not done yet
-
Any other server response gives FAIL, exit status 1, empty stderr — not done yet
-
A server that refuses the connection gives FAIL, exit status 1 — not done yet
-
No response for 2 seconds gives FAIL, exit status 1, and the script ends by itself within 3 seconds — not done yet
-
No address or two arguments give Usage on stderr, empty stdout, exit status 2 — not done yet
Goals are checked on the machine after every command.