Skip to content

Commit

Permalink
Ignore parallel sighups
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnedo committed Apr 11, 2023
1 parent 0cea813 commit b10884b
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export SYSTEM_RESOLVER

# template the nginx config, format it and test it, printing the config to stdout if there's an error
make_config() {
# Template nginx config
echo "templating..."
mv $CONF_PATH ${CONF_PATH}.old
/usr/local/bin/gomplate -d apps="$APPS_CONFIG_PATH" --file "$TEMPLATE_PATH" --out $CONF_PATH
Expand All @@ -69,23 +68,33 @@ wait_file_changed() {
}

reload_and_wait() {
pid="$(cat $pidfile 2>/dev/null || echo '')"
if [ -z "${pid:-}" ]; then
return
# lock
if {
set -C
2>/dev/null >/tmp/lurchreload.lock
}; then
# have lock
pid="$(cat $pidfile 2>/dev/null || echo '')"
if [ -z "${pid:-}" ]; then
return
fi

make_config
echo "sending HUP..."
kill -HUP "$pid"
# release
rm /tmp/lurchreload.lock
echo "waiting on $pid"
wait "$pid"
fi
make_config
echo "sending HUP..."
kill -HUP "$pid"
echo "waiting on $pid"
wait "$pid"
}

make_config

echo "staring daemon..."
/usr/local/openresty/bin/openresty -c $CONF_PATH -g "daemon off;" &

trap 'echo reload signal received!; reload_and_wait' HUP
trap 'reload_and_wait' HUP

echo 'waiting for pid to appear...'
wait_file_changed $pidfile
Expand Down

0 comments on commit b10884b

Please sign in to comment.