Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile-debian
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ RUN mkdir -p /usr/local/api-gateway \
&& chmod 755 -R /etc/api-gateway /var/log/api-gateway /usr/local \
&& echo "nginx-api-gateway ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

RUN apt-get update && apt-get install -y inotify-tools

USER nginx-api-gateway

ENTRYPOINT ["/etc/init-container.sh"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ There are a few things to take into consideration when changing this value:
* Cost. Some tools may make 1 API request per file to compare it. I.e. in S3 72 config files checked every `10s` costs `$7.46` but when checked every `30s` it's only `$2.4`, times number of GW nodes.
* Average time for an API Request. When reloading the GW the existing NGINX processes handling active connections are kept in the background until the request completes. So reloading the Gateway too fast may have the side effect of keeping too many processes running at the same time. This may, or may not be a problem but it's good to be aware of it.

In case there are occasional issues with tracking config changes `FORCE_RELOAD_INTERVAL_S` variable can be used to enable regular force-reloads of the config.

#### Customizing the sync command

The sync command used for downloading the configuration files can be controlled via `REMOTE_CONFIG_SYNC_CMD` as well. This ENV VAR overrides the `REMOTE_CONFIG` one.
Expand Down
15 changes: 15 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ debug_mode=${DEBUG}
log_level=${LOG_LEVEL:-warn}
marathon_host=${MARATHON_HOST}
sleep_duration=${MARATHON_POLL_INTERVAL:-5}
force_reload_interval_s=${FORCE_RELOAD_INTERVAL_S:--1}
#
# location for a remote /etc/api-gateway folder.
# i.e s3://api-gateway-config
Expand Down Expand Up @@ -107,5 +108,19 @@ while true; do \
fi; \
done &

echo " ... starting inotify-tools watcher "
inotifywait -m -r -e modify -e attrib -e move -e move_self -e create -e delete -e delete_self --format "%T %w (%f) %:e" --timefmt "%Y-%m-%d %H:%M:%S %z" /etc/api-gateway &

if [ $force_reload_interval_s -gt 0 ]; then
echo " ... starting regular api-gateway force reload (every ${force_reload_interval_s} seconds)"
while true; do \
sleep ${force_reload_interval_s}; \
echo " ... reloading api-gateway "; \
sudo api-gateway -s reload
done &
else
echo " ... skipping regular api-gateway force reloads (FORCE_RELOAD_INTERVAL_S is set to ${force_reload_interval_s})"
fi

echo " ... using log level: '${log_level}'. Override it with -e 'LOG_LEVEL=<level>' "
sudo api-gateway -p /usr/local/api-gateway/ -c /etc/api-gateway/api-gateway.conf -g "daemon off; error_log /dev/stderr ${log_level};"