diff --git a/scripts/http_host/host_manager.py b/scripts/http_host/host_manager.py index b22d941..624ed81 100755 --- a/scripts/http_host/host_manager.py +++ b/scripts/http_host/host_manager.py @@ -19,11 +19,12 @@ from http_host_lib.utils import assert_linux, assert_single_process, assert_sudo def cli(): """ Manages OpenFreeMap HTTP hosts, including:\n - - Downloading tilesets\n - - Downloading assets\n - Deploying the correct versions of tilesets\n + - Downloading assets\n + - Downloading tilesets\n - Mounting directories\n - Updating nginx config\n + - Running the sync cron task every minute """ @@ -66,7 +67,7 @@ def download_tileset(area: str, version: str, list_versions: bool, runs_dir: Pat runs_dir = DEFAULT_RUNS_DIR if not runs_dir.parent.exists(): - sys.exit("run dir's parent doesn't exist") + sys.exit("runs dir's parent doesn't exist") return download_and_extract_tileset(area, selected_version, runs_dir) @@ -155,21 +156,21 @@ def sync(ctx): """ print(datetime.datetime.now(tz=datetime.timezone.utc)) - downloaded = False - downloaded += ctx.invoke(download_tileset, area='monaco') - # d2 = ctx.invoke(download_tileset, area='planet') - if downloaded: + assert_single_process() + + download_done = False + download_done += ctx.invoke(download_tileset, area='monaco') + download_done += ctx.invoke(download_tileset, area='planet') + if download_done: ctx.invoke(mount) ctx.invoke(download_assets) - deployed = ctx.invoke(deploy_tileset_version) + deploy_done = ctx.invoke(deploy_tileset_version) - if downloaded or deployed: + if download_done or deploy_done: ctx.invoke(nginx_sync) if __name__ == '__main__': - # TODO - assert_single_process() cli() diff --git a/scripts/http_host/http_host_lib/nginx.py b/scripts/http_host/http_host_lib/nginx.py index 48b064e..43c7e05 100644 --- a/scripts/http_host/http_host_lib/nginx.py +++ b/scripts/http_host/http_host_lib/nginx.py @@ -20,14 +20,14 @@ def write_nginx_config(): run_dir = DEFAULT_RUNS_DIR / area / version if not run_dir.is_dir(): - print(f"{run_dir} doesn't exists, skipping") + print(f" {run_dir} doesn't exists, skipping") continue tilejson_path = run_dir / 'tilejson-tiles-org.json' metadata_path = subdir / 'metadata.json' if not metadata_path.is_file(): - print(f"{metadata_path} doesn't exists, skipping") + print(f" {metadata_path} doesn't exists, skipping") continue url_prefix = f'https://tiles.openfreemap.org/{area}/{version}' @@ -44,7 +44,7 @@ def write_nginx_config(): check=True, ) - # TODO raise the expires times once things are stable + # TODO # target 10y version_str = f""" location /{area}/{version} {{ # no trailing hash alias {tilejson_path}; # no trailing hash diff --git a/scripts/http_host/http_host_lib/utils.py b/scripts/http_host/http_host_lib/utils.py index 7eefc7c..cb6d987 100644 --- a/scripts/http_host/http_host_lib/utils.py +++ b/scripts/http_host/http_host_lib/utils.py @@ -1,6 +1,7 @@ import os import subprocess import sys +import time from pathlib import Path import requests @@ -16,9 +17,11 @@ def assert_linux(): sys.exit('Needs to be run on Linux') -# TODO def assert_single_process(): - pass + p = subprocess.run(['pgrep', '-fl', sys.argv[0]], capture_output=True, text=True) + lines = [l for l in p.stdout.splitlines() if 'python' in l] + if len(lines) >= 2: + sys.exit('Detected multiple processes, terminating') def download_if_size_differs(url: str, local_file: Path) -> bool: diff --git a/scripts/http_host/metadata_to_tilejson.py b/scripts/http_host/metadata_to_tilejson.py index caa0177..1e63195 100755 --- a/scripts/http_host/metadata_to_tilejson.py +++ b/scripts/http_host/metadata_to_tilejson.py @@ -32,7 +32,7 @@ def cli(metadata_path: Path, tilejson_path: Path, url_prefix: str, minify: bool) '' tilejson['vector_layers'] = metadata_json_key.pop('vector_layers') - assert not metadata_json_key # check that no more keys left + assert not metadata_json_key # check that no more keys are left tilejson['attribution'] = metadata.pop('attribution') tilejson['bounds'] = [float(n) for n in metadata.pop('bounds').split(',')] diff --git a/ssh_lib/pkg_base.py b/ssh_lib/pkg_base.py index 4b7e02c..a59e447 100644 --- a/ssh_lib/pkg_base.py +++ b/ssh_lib/pkg_base.py @@ -17,6 +17,7 @@ def pkg_base(c): 'rsync', 'unzip', 'wget', + 'psmisc', # 'btrfs-progs', #