forked from kamba4/sunders
feat: web healthcheck returns 503 status code if database is unavailable
This commit is contained in:
parent
5ff2918d07
commit
729af9ced9
2 changed files with 4 additions and 4 deletions
|
|
@ -33,12 +33,11 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "8081:80"
|
- "8081:80"
|
||||||
depends_on:
|
depends_on:
|
||||||
data_handler:
|
db:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
# all the way zoomed out, with hamburg at the center, at least one camera should be returned
|
# all the way zoomed out, with hamburg at the center, at least one camera should be returned
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: >
|
test: ["CMD", "curl", "-f", "http://localhost/sync-state.php"]
|
||||||
["CMD", "curl -s 'http://localhost/camera.php?bbox=-92.52991540527346,30.683278176916133,131.7689595947266,72.87186315234298&zoom=4&width=2552&height=867' | grep '^\[.+\]$'"]
|
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
start_period: 30s
|
start_period: 30s
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,9 @@
|
||||||
/* Connect to database */
|
/* Connect to database */
|
||||||
$mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
|
$mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
|
||||||
if($mysqli->connect_errno) {
|
if($mysqli->connect_errno) {
|
||||||
|
http_response_code(503);
|
||||||
header('Content-type: application/json');
|
header('Content-type: application/json');
|
||||||
$result = '{"error":"error while connecting to db : ' . $mysqli->error . '"}';
|
$result = '{"error":"Database unavailable"}';
|
||||||
echo $result;
|
echo $result;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue