diff --git a/Dockerfile-debian b/Dockerfile-debian index 4a9fe7d..50883e0 100644 --- a/Dockerfile-debian +++ b/Dockerfile-debian @@ -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"] diff --git a/README.md b/README.md index b52ed5e..4bdc98d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/init.sh b/init.sh index dcd9b44..6d45898 100755 --- a/init.sh +++ b/init.sh @@ -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 @@ -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=' " sudo api-gateway -p /usr/local/api-gateway/ -c /etc/api-gateway/api-gateway.conf -g "daemon off; error_log /dev/stderr ${log_level};"