Commit 35024175 authored by Kirill Smelkov's avatar Kirill Smelkov

check-url: Allow to specify expected HTTP code

In gitlab SR a service I need to check - gitlab-workhorse, returns 200
only when request comes to some repository and authentication backend
allows it.

Requiring access to repositories is not very good just to check if the
service is alive, and also auth backend can be not alive, and initially
there are no repositories at all. So gitlab-workhorse is checked to be
alive by pinging it with non-existing URL and expecting 403.

For this to work we need to allow clients to specify expected HTTP code
instead of previously hardcoded 200 (which still remains the default).

/reviewed-by @cedric.leninivin  (on nexedi/slapos!31)
parent 52c3690a
......@@ -37,7 +37,8 @@ class Recipe(GenericBaseRecipe):
'url': self.options['url'],
'shell_path': self.options['dash_path'],
'curl_path': self.options['curl_path'],
'check_secure': self.options.get('check-secure', 0)
'check_secure': self.options.get('check-secure', 0),
'http_code': self.options.get('http_code', '200'),
}
# XXX-Cedric in this script, curl won't check certificate
......
......@@ -38,7 +38,7 @@ if [ %(check_secure)s -eq 1 ]; then
fi
fi
if ! [ $CODE -eq 200 ]; then
echo "$URL is not available (returned $CODE)." >&2
if ! [ $CODE -eq %(http_code)s ]; then
echo "$URL is not available (returned $CODE, expected %(http_code)s)." >&2
exit 2
fi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment