Skip to content

Commit 1e56fb0

Browse files
authored
feat: added force-reloads of config and inotify-watcher (#86)
1 parent 2950745 commit 1e56fb0

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Dockerfile-debian

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ RUN mkdir -p /usr/local/api-gateway \
290290
&& chmod 755 -R /etc/api-gateway /var/log/api-gateway /usr/local \
291291
&& echo "nginx-api-gateway ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
292292

293+
RUN apt-get update && apt-get install -y inotify-tools
294+
293295
USER nginx-api-gateway
294296

295297
ENTRYPOINT ["/etc/init-container.sh"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ There are a few things to take into consideration when changing this value:
100100
* 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.
101101
* 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.
102102

103+
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.
104+
103105
#### Customizing the sync command
104106

105107
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.

init.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ debug_mode=${DEBUG}
2525
log_level=${LOG_LEVEL:-warn}
2626
marathon_host=${MARATHON_HOST}
2727
sleep_duration=${MARATHON_POLL_INTERVAL:-5}
28+
force_reload_interval_s=${FORCE_RELOAD_INTERVAL_S:--1}
2829
#
2930
# location for a remote /etc/api-gateway folder.
3031
# i.e s3://api-gateway-config
@@ -107,5 +108,19 @@ while true; do \
107108
fi; \
108109
done &
109110

111+
echo " ... starting inotify-tools watcher "
112+
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 &
113+
114+
if [ $force_reload_interval_s -gt 0 ]; then
115+
echo " ... starting regular api-gateway force reload (every ${force_reload_interval_s} seconds)"
116+
while true; do \
117+
sleep ${force_reload_interval_s}; \
118+
echo " ... reloading api-gateway "; \
119+
sudo api-gateway -s reload
120+
done &
121+
else
122+
echo " ... skipping regular api-gateway force reloads (FORCE_RELOAD_INTERVAL_S is set to ${force_reload_interval_s})"
123+
fi
124+
110125
echo " ... using log level: '${log_level}'. Override it with -e 'LOG_LEVEL=<level>' "
111126
sudo api-gateway -p /usr/local/api-gateway/ -c /etc/api-gateway/api-gateway.conf -g "daemon off; error_log /dev/stderr ${log_level};"

0 commit comments

Comments
 (0)