X-Git-Url: https://git.openstreetmap.org/chef.git/blobdiff_plain/f29b9ed2427f24b45e3372ff8005f4341e377319..719e3d34b809d86380d6f0d5fc4019cf67afe175:/cookbooks/tilecache/templates/default/nginx_generate_tilecache_qos_map.erb diff --git a/cookbooks/tilecache/templates/default/nginx_generate_tilecache_qos_map.erb b/cookbooks/tilecache/templates/default/nginx_generate_tilecache_qos_map.erb index 9a386a3e7..deec588c3 100755 --- a/cookbooks/tilecache/templates/default/nginx_generate_tilecache_qos_map.erb +++ b/cookbooks/tilecache/templates/default/nginx_generate_tilecache_qos_map.erb @@ -1,14 +1,18 @@ #!/bin/bash # DO NOT EDIT - This file is being maintained by Chef - set -e + NUM_TOKENS=4 # current + 4 VALID_TOKEN=3600 # in seconds -QOS_TOKENS=($(/usr/bin/oathtool --totp --window=${NUM_TOKENS} --time-step-size=${VALID_TOKEN}s -b <%= @totp_key %>)) -# ${qos_tokens[3]/[-1] } = OSM.org exclusive / current -# ${qos_tokens[2]/[-2] } = tile.openstreetmap.org default -# ${qos_tokens[1]/[-3] } = stale ~ 1 hour +SECONDS_AGO=$((${NUM_TOKENS} * ${VALID_TOKEN})) +OLD_TIME=$(/bin/date -u "+%Y-%m-%dT %H:%M:%S %z" -d "${SECONDS_AGO} seconds ago") +QOS_TOKENS=($(/usr/bin/oathtool --totp --now="${OLD_TIME}" --window=${NUM_TOKENS} --time-step-size=${VALID_TOKEN}s -b "<%= @totp_key %>")) + +# ${qos_tokens[4]/[-1] } = OSM.org exclusive / current +# ${qos_tokens[3]/[-2] } = OSM.org exclusive / stale +# ${qos_tokens[2]/[-3] } = tile.openstreetmap.org default +# ${qos_tokens[1]/[-4] } = stale ~ 1 hour # ${qos_tokens[0]} = expired # Test if number of tokens returned by oathtool is expected number @@ -28,7 +32,7 @@ if [ -z "$QOS_TOKEN_OSM" -o -z "$QOS_TOKEN_DEFAULT" -o -z "$QOS_TOKEN_STALE" ]; fi cat </etc/nginx/conf.d/tile_qos_rates.map -default 24576; # Default Rate (No QoS cookie) +default 8192; # Default Rate (No QoS cookie) "${QOS_TOKEN_STALE}" 24576; # Stale "${QOS_TOKEN_DEFAULT}" 24576; # Default "${QOS_TOKEN_OSM_STALE}" 32768; # Exclusive Stale @@ -36,10 +40,11 @@ default 24576; # Default Rate (No QoS cookie) EOF cat </etc/nginx/conf.d/tile_qos_cookies.map -default 'qos_token=${QOS_TOKEN_DEFAULT}; Max-Age=${VALID_TOKEN}; Domain=openstreetmap.org; Path=/'; # Cookie Domain per RFC6265 +default '_osm_totp_token=${QOS_TOKEN_DEFAULT}; Max-Age=${VALID_TOKEN}; Domain=openstreetmap.org; Path=/'; # Cookie Domain per RFC6265 "${QOS_TOKEN_DEFAULT}" ''; # Do not Set-Cookie. # Default +"${QOS_TOKEN_OSM_STALE}" ''; # Do not Set-Cookie. # Exclusive Stale "${QOS_TOKEN_OSM}" ''; # Do not Set-Cookie. # Exclusive EOF # Check config, reload config and fail safe -/etc/init.d/nginx configtest && ( /usr/sbin/service nginx reload || true ) +# /etc/init.d/nginx configtest 2>/dev/null && /bin/systemctl try-reload-or-restart nginx