Skip to content

Commit

Permalink
healthcheck: use jq to parse json
Browse files Browse the repository at this point in the history
The use of `grep` requires the HTTP server to return the JSON body
in one line. This could change with an update (either intended or not)
and would break the healthcheck.

Instead, we should parse the JSON and exit with code 1 if the health
is not healthy.

Signed-off-by: Tan Siewert <[email protected]>
  • Loading branch information
sinuscosinustan authored Sep 11, 2024
1 parent c570e65 commit 428570c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM steamcmd/steamcmd:ubuntu-22
# hadolint ignore=DL3008
RUN set -x \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y gosu xdg-user-dirs curl --no-install-recommends\
&& DEBIAN_FRONTEND=noninteractive apt-get install -y gosu xdg-user-dirs curl jq --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& useradd -ms /bin/bash steam \
&& gosu nobody true
Expand Down
4 changes: 2 additions & 2 deletions healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

curl -k -f -X POST "https://127.0.0.1:${SERVERGAMEPORT}/api/v1" \
-H "Content-Type: application/json" \
-d '{"function":"HealthCheck","data":{"clientCustomData":""}}' \
| grep -q '{"data":{"health":"healthy"'
-d '{"function":"HealthCheck","data":{"clientCustomData":""}}' |
jq -e '.data.health == "healthy"'

0 comments on commit 428570c

Please sign in to comment.