An error answer is still an answer. A script notices the error by the curl exit code, and whether it is the right site — by the text of the answer.
To curl without options, a 503 answer is a successful exchange: there was a connection, an answer arrived, and the code is 0. With the -f (--fail) option it treats a status of 400 or higher as an error: it prints curl: (22) The requested URL returned error: 503 and exits with code 22. Scripts and monitoring need exactly that code.
Once a status arrives, the network and the port are fine: look in the application itself — its configuration, log, dependencies.
A 200 status is not everything either. Another site or a placeholder might have answered at that address. So a check looks at both the status and the answer's text: for the practice service it is the line ports-lab-ok.
A check from the client printed this line. Where do you look for the cause?
curl: (22) The requested URL returned error: 503
-
The server sent the
503status, so there was a connection and the request arrived. The network did its part. -
A filter dropping packets would give a timeout with no answer. Here an answer arrived.
-
-fonly turns a status of400or higher into code22. Without it,curlgets the same503with code0.
503 is the application's answer status: there is a connection and the request arrived, but the service is not ready to serve it. The cause is in the application itself.
Key points
-
Without
-f,curlexits with code0even on a503answer; with-f, with code22. - A status in the answer means the network and the port are fine, and the error is in the application.
- A service check looks at the status and the answer's text.