Skip to content

Commit

Permalink
healthcheck doublecheck and tm server zip checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
felacek committed Nov 25, 2024
1 parent b5e3054 commit 0ab6ff4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
FROM node:lts-alpine
# create directory, install xml editing tool and setup non-root user
RUN adduser -h /app/server -s /bin/sh -D -u 1001 server && \
apk add xmlstarlet su-exec
apk add xmlstarlet su-exec && \
npm i -g npm@10.9.1
USER server
WORKDIR /app/server
# copy useful trakman files and entrypoint command
Expand All @@ -13,6 +14,7 @@ COPY --chown=1001:1001 ./Plugins.ts ./package.json ./tsconfig.json ./CHANGELOG.m
COPY --chown=1001:1001 --chmod=0755 ./docker_run.sh ./docker_run.sh
# download dedicated server and remove unnecessary files
RUN wget -O serv.zip http://files2.trackmaniaforever.com/TrackmaniaServer_2011-02-21.zip && \
if [ "$(sha256sum serv.zip | cut -d ' ' -f 1)" != "dd021f49c3d58d45ee09f333015bdb35b19243a38fa65f202ca8a88fb6550c0b" ]; then exit 1; fi && \
unzip serv.zip && \
rm -r serv.zip CommandLine.html ListCallbacks.html ListMethods.html \
Readme_Dedicated.html RemoteControlExamples TrackmaniaServer.exe manialink_dedicatedserver.txt
Expand Down
9 changes: 8 additions & 1 deletion src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,17 @@ process.on('SIGINT', () => {
process.exit(0)
})

let failedHealthChecks = 0

setInterval(async () => {
Logger.debug('Checking if the dedicated server is alive...')
const status = await Client.call('GetStatus')
let status = await Client.call('GetStatus')
if (status instanceof Error) {
failedHealthChecks++
Logger.warn('Server did not respond to healthcheck')
}
// Surely checking two times is enough
if (failedHealthChecks > 1) {
// We don't need to wait to restart here since the timeout is 10s anyway - plenty of time for serv to start
await Logger.fatal(`Healthcheck failed - no connection to the server. Game state was: ${GameService.state}`)
}
Expand Down

0 comments on commit 0ab6ff4

Please sign in to comment.