diff --git a/README.md b/README.md index 63558a9..68860be 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ Auto-update works! Monaco is generated every hour, set-latest runs every minute. -Planet is generated every Tuesday, set-latest runs every Saturday. +Planet is generated every Wednesday, set-latest runs every Saturday. ##### v0.3 diff --git a/modules/http_host/http_host.py b/modules/http_host/http_host.py index e05a03c..1d92a50 100755 --- a/modules/http_host/http_host.py +++ b/modules/http_host/http_host.py @@ -8,7 +8,7 @@ from http_host_lib.btrfs import ( download_area_version, get_versions_for_area, ) -from http_host_lib.mount import auto_mount_unmount +from http_host_lib.mount import auto_mount from http_host_lib.nginx import write_nginx_config from http_host_lib.sync import auto_clean_btrfs, full_sync from http_host_lib.versions import fetch_version_files @@ -57,7 +57,7 @@ def mount(): When finished, /mnt/ofm dir will have all the present tiles.btrfs files mounted in a read-only way. """ - auto_mount_unmount() + auto_mount() @cli.command(name='fetch-versions') diff --git a/modules/http_host/http_host_lib/mount.py b/modules/http_host/http_host_lib/mount.py index 0870969..9683c1f 100644 --- a/modules/http_host/http_host_lib/mount.py +++ b/modules/http_host/http_host_lib/mount.py @@ -6,7 +6,7 @@ from http_host_lib.config import config from http_host_lib.utils import assert_linux, assert_sudo -def auto_mount_unmount(): +def auto_mount(): """ Mounts/unmounts the btrfs images from /data/ofm/http_host/runs automatically. When finished, /mnt/ofm dir will have all the present tiles.btrfs files mounted in a read-only way. @@ -26,8 +26,6 @@ def auto_mount_unmount(): print(' running mount -a') subprocess.run(['mount', '-a'], check=True) - clean_up_mounts(config.mnt_dir) - def create_fstab(): fstab_new = [] diff --git a/modules/http_host/http_host_lib/nginx.py b/modules/http_host/http_host_lib/nginx.py index 5c627ea..6f96221 100644 --- a/modules/http_host/http_host_lib/nginx.py +++ b/modules/http_host/http_host_lib/nginx.py @@ -121,6 +121,7 @@ def create_location_blocks(*, local, domain): if not subdir.is_dir(): continue area, version = subdir.name.split('-') + location_str += create_version_location( area=area, version=version, subdir=subdir, local=local, domain=domain ) @@ -216,11 +217,13 @@ def create_latest_locations(*, local: str, domain: str) -> str: continue # checking mnt dir - mnt_file = Path(f'/mnt/ofm/{area}-{version}/metadata.json') + mnt_dir = Path(f'/mnt/ofm/{area}-{version}') + mnt_file = mnt_dir / ' metadata.json' if not mnt_file.is_file(): print(f' error with latest: {mnt_file} does not exist') continue + # latest location_str += f""" location = /{area} {{ # no trailing slash alias {tilejson_path}; # no trailing slash @@ -233,6 +236,38 @@ def create_latest_locations(*, local: str, domain: str) -> str: }} """ + # wildcard + # identical to create_version_location + location_str += f""" + + # wildcard JSON + location ~ ^/{area}/([^/]+)$ {{ # no trailing slash + alias {tilejson_path}; # no trailing slash + + expires 1w; + default_type application/json; + + add_header 'Access-Control-Allow-Origin' '*' always; + add_header Cache-Control public; + }} + + # wildcard PBF + location ~ ^/{area}/([^/]+)/ {{ # trailing slash + alias {mnt_dir}/tiles/; # trailing slash + try_files $uri @empty_tile; + add_header Content-Encoding gzip; + + expires 10y; + + types {{ + application/vnd.mapbox-vector-tile pbf; + }} + + add_header 'Access-Control-Allow-Origin' '*' always; + add_header Cache-Control public; + }} + """ + return location_str diff --git a/modules/http_host/http_host_lib/nginx_confs/ledns.conf b/modules/http_host/http_host_lib/nginx_confs/ledns.conf index 8f0ea08..1176ab3 100644 --- a/modules/http_host/http_host_lib/nginx_confs/ledns.conf +++ b/modules/http_host/http_host_lib/nginx_confs/ledns.conf @@ -23,8 +23,8 @@ server { ssl_prefer_server_ciphers off; # access log disabled by default - #access_log /data/ofm/http_host/logs_nginx/ledns-access.jsonl access_json buffer=32k; - access_log off; + access_log /data/ofm/http_host/logs_nginx/ledns-access.jsonl access_json buffer=32k; + #access_log off; error_log /data/ofm/http_host/logs_nginx/ledns-error.log; diff --git a/modules/http_host/http_host_lib/sync.py b/modules/http_host/http_host_lib/sync.py index a2bfd1b..bcb1fd5 100644 --- a/modules/http_host/http_host_lib/sync.py +++ b/modules/http_host/http_host_lib/sync.py @@ -4,7 +4,7 @@ from datetime import datetime, timezone from http_host_lib.assets import download_assets from http_host_lib.btrfs import download_area_version from http_host_lib.config import config -from http_host_lib.mount import auto_mount_unmount +from http_host_lib.mount import auto_mount, clean_up_mounts from http_host_lib.nginx import write_nginx_config from http_host_lib.utils import assert_linux, assert_sudo from http_host_lib.versions import fetch_version_files @@ -42,9 +42,12 @@ def full_sync(force=False): if btrfs_downloaded or versions_changed or force: auto_clean_btrfs() - auto_mount_unmount() + auto_mount() + write_nginx_config() + clean_up_mounts(config.mnt_dir) + def auto_clean_btrfs(): """ diff --git a/modules/tile_gen/cron.d/ofm_tile_gen b/modules/tile_gen/cron.d/ofm_tile_gen index 3d91e47..c9e947f 100644 --- a/modules/tile_gen/cron.d/ofm_tile_gen +++ b/modules/tile_gen/cron.d/ofm_tile_gen @@ -8,8 +8,8 @@ LOG_DIR=/data/ofm/tile_gen/logs # every minute, set monaco to latest * * * * * ofm $CMD set-version monaco >> $LOG_DIR/monaco-set-version.log 2>&1 -# every Tuesday morning at 00:10, make a planet run -10 0 * * 2 ofm $CMD make-tiles planet --upload >> $LOG_DIR/planet-make-tiles.log 2>&1 +# every Wednesday morning at 00:10, make a planet run +10 0 * * 3 ofm $CMD make-tiles planet --upload >> $LOG_DIR/planet-make-tiles.log 2>&1 # every Saturday at 8:00, set planet to latest 0 11 * * 6 ofm $CMD set-version monaco >> $LOG_DIR/monaco-set-version.log 2>&1