Skip to content

Commit

Permalink
fix signals being ignored (#113)
Browse files Browse the repository at this point in the history
Previously when running the Valhalla service with e.g.:

    $ docker run -v $PWD/data:/data ghcr.io/gis-ops/docker-valhalla/valhalla
    ...
    INFO: Found config file. Starting valhalla service!
    ....

You couldn't stop it with Ctrl+C (SIGINT) or `kill $!` (SIGTERM) when
run in the background, because the run.sh shell script didn't use `exec`
for the `valhalla_service` command, which resulted in an intermediary
shell process (that didn't pass the signals to child processes because
Docker gives it PID 1, which is special[1]).  This is a well-known
pitfall of Docker ENTRYPOINT shell scripts.[2][3]

This commit fixes that oversight.

Sidenote: It still takes ~30 seconds for a SIGTERM to shutdown
the server because valhalla_service has configured such a graceful
shutdown period for the prime_server HTTP server.

[1]: https://docs.docker.com/engine/reference/builder/#entrypoint
[2]: https://hynek.me/articles/docker-signals/
[3]: https://petermalmgren.com/signal-handling-docker/
  • Loading branch information
not-my-profile committed Jun 20, 2023
1 parent 7615064 commit 997e11b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ run_cmd() {
if [[ $(id --user) == "59999" ]] && [[ $(id --group) == "59999" ]]; then
# -E preserves the env vars, but some are still nulled for security reasons
# use "env" to preserve them
sudo -E env LD_LIBRARY_PATH=$LD_LIBRARY_PATH $1 || exit 1
$cmd_prefix sudo -E env LD_LIBRARY_PATH=$LD_LIBRARY_PATH $1 || exit 1
else
$1 || exit 1
$cmd_prefix $1 || exit 1
fi
}

Expand Down Expand Up @@ -75,7 +75,7 @@ if [[ $1 == "build_tiles" ]]; then
if [[ ${serve_tiles} == "True" ]]; then
if test -f ${CONFIG_FILE}; then
echo "INFO: Found config file. Starting valhalla service!"
run_cmd "valhalla_service ${CONFIG_FILE} ${server_threads}"
cmd_prefix=exec run_cmd "valhalla_service ${CONFIG_FILE} ${server_threads}"
else
echo "WARNING: No config found!"
fi
Expand Down

0 comments on commit 997e11b

Please sign in to comment.