mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
host_manager
This commit is contained in:
@@ -19,11 +19,12 @@ from http_host_lib.utils import assert_linux, assert_single_process, assert_sudo
|
|||||||
def cli():
|
def cli():
|
||||||
"""
|
"""
|
||||||
Manages OpenFreeMap HTTP hosts, including:\n
|
Manages OpenFreeMap HTTP hosts, including:\n
|
||||||
- Downloading tilesets\n
|
|
||||||
- Downloading assets\n
|
|
||||||
- Deploying the correct versions of tilesets\n
|
- Deploying the correct versions of tilesets\n
|
||||||
|
- Downloading assets\n
|
||||||
|
- Downloading tilesets\n
|
||||||
- Mounting directories\n
|
- Mounting directories\n
|
||||||
- Updating nginx config\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
|
runs_dir = DEFAULT_RUNS_DIR
|
||||||
|
|
||||||
if not runs_dir.parent.exists():
|
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)
|
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))
|
print(datetime.datetime.now(tz=datetime.timezone.utc))
|
||||||
|
|
||||||
downloaded = False
|
assert_single_process()
|
||||||
downloaded += ctx.invoke(download_tileset, area='monaco')
|
|
||||||
# d2 = ctx.invoke(download_tileset, area='planet')
|
download_done = False
|
||||||
if downloaded:
|
download_done += ctx.invoke(download_tileset, area='monaco')
|
||||||
|
download_done += ctx.invoke(download_tileset, area='planet')
|
||||||
|
if download_done:
|
||||||
ctx.invoke(mount)
|
ctx.invoke(mount)
|
||||||
|
|
||||||
ctx.invoke(download_assets)
|
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)
|
ctx.invoke(nginx_sync)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# TODO
|
|
||||||
assert_single_process()
|
|
||||||
cli()
|
cli()
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ def write_nginx_config():
|
|||||||
|
|
||||||
run_dir = DEFAULT_RUNS_DIR / area / version
|
run_dir = DEFAULT_RUNS_DIR / area / version
|
||||||
if not run_dir.is_dir():
|
if not run_dir.is_dir():
|
||||||
print(f"{run_dir} doesn't exists, skipping")
|
print(f" {run_dir} doesn't exists, skipping")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
tilejson_path = run_dir / 'tilejson-tiles-org.json'
|
tilejson_path = run_dir / 'tilejson-tiles-org.json'
|
||||||
|
|
||||||
metadata_path = subdir / 'metadata.json'
|
metadata_path = subdir / 'metadata.json'
|
||||||
if not metadata_path.is_file():
|
if not metadata_path.is_file():
|
||||||
print(f"{metadata_path} doesn't exists, skipping")
|
print(f" {metadata_path} doesn't exists, skipping")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
url_prefix = f'https://tiles.openfreemap.org/{area}/{version}'
|
url_prefix = f'https://tiles.openfreemap.org/{area}/{version}'
|
||||||
@@ -44,7 +44,7 @@ def write_nginx_config():
|
|||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO raise the expires times once things are stable
|
# TODO # target 10y
|
||||||
version_str = f"""
|
version_str = f"""
|
||||||
location /{area}/{version} {{ # no trailing hash
|
location /{area}/{version} {{ # no trailing hash
|
||||||
alias {tilejson_path}; # no trailing hash
|
alias {tilejson_path}; # no trailing hash
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -16,9 +17,11 @@ def assert_linux():
|
|||||||
sys.exit('Needs to be run on Linux')
|
sys.exit('Needs to be run on Linux')
|
||||||
|
|
||||||
|
|
||||||
# TODO
|
|
||||||
def assert_single_process():
|
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:
|
def download_if_size_differs(url: str, local_file: Path) -> bool:
|
||||||
|
|||||||
@@ -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')
|
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['attribution'] = metadata.pop('attribution')
|
||||||
tilejson['bounds'] = [float(n) for n in metadata.pop('bounds').split(',')]
|
tilejson['bounds'] = [float(n) for n in metadata.pop('bounds').split(',')]
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ def pkg_base(c):
|
|||||||
'rsync',
|
'rsync',
|
||||||
'unzip',
|
'unzip',
|
||||||
'wget',
|
'wget',
|
||||||
|
'psmisc',
|
||||||
#
|
#
|
||||||
'btrfs-progs',
|
'btrfs-progs',
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user