host_manager

This commit is contained in:
Zsolt Ero
2024-01-03 19:36:52 +01:00
parent e663196013
commit 5ad3987c26
5 changed files with 69 additions and 61 deletions

View File

@@ -107,7 +107,7 @@ def prepare_http_host(c):
c.sudo('/data/ofm/venv/bin/pip install -e /data/ofm/http_host/bin') c.sudo('/data/ofm/venv/bin/pip install -e /data/ofm/http_host/bin')
# always last # always last
# put(c, SCRIPTS_DIR / 'http_host' / 'cron.d' / 'ofm_http_host', '/etc/cron.d/') put(c, SCRIPTS_DIR / 'http_host' / 'cron.d' / 'ofm_http_host', '/etc/cron.d/')
def upload_https_host_files(c): def upload_https_host_files(c):

View File

@@ -1,5 +1,5 @@
PYTHON=/data/ofm/venv/bin/python PYTHON=/data/ofm/venv/bin/python
BIN=/data/ofm/http_host/bin BIN=/data/ofm/http_host/bin
# every minute download_asset.py # every minute sync
* * * * * ofm sudo $PYTHON -u $BIN/host_manager.py sync >> /data/ofm/http_host/logs/host_manager_sync.log 2>&1 * * * * * ofm sudo $PYTHON -u $BIN/host_manager.py sync >> /data/ofm/http_host/logs/host_manager_sync.log 2>&1

View File

@@ -7,11 +7,11 @@ from pathlib import Path
import click import click
import requests import requests
from http_host_lib import DEFAULT_ASSETS_DIR, DEFAULT_RUNS_DIR, MNT_DIR from http_host_lib import DEFAULT_ASSETS_DIR, DEFAULT_RUNS_DIR, MNT_DIR
from http_host_lib.deploy_tileset import deploy_tileset
from http_host_lib.download_fonts import download_fonts from http_host_lib.download_fonts import download_fonts
from http_host_lib.download_tileset import download_and_extract_tileset from http_host_lib.download_tileset import download_and_extract_tileset
from http_host_lib.mount import clean_up_mounts, create_fstab from http_host_lib.mount import clean_up_mounts, create_fstab
from http_host_lib.nginx import write_nginx_config from http_host_lib.nginx import write_nginx_config
from http_host_lib.set_tileset_versions import set_tileset_versions
from http_host_lib.utils import assert_linux, assert_single_process, assert_sudo from http_host_lib.utils import assert_linux, assert_single_process, assert_sudo
@@ -114,13 +114,13 @@ def mount():
@cli.command() @cli.command()
def deploy_tileset_version(): def set_latest_versions():
""" """
Deploys the latest tileset version specified by Sets the latest version of the tilesets to the version specified by
https://assets.openfreemap.com/versions/deployed_planet.txt https://assets.openfreemap.com/versions/deployed_planet.txt
1. Check if the given version is present on the disk and is mounted 1. Checks if the given version is present on the disk and is mounted
2. Write to a version file 2. Writes to a version file
""" """
assert_linux() assert_linux()
@@ -129,7 +129,7 @@ def deploy_tileset_version():
if not MNT_DIR.exists(): if not MNT_DIR.exists():
sys.exit('mount needs to be run first') sys.exit('mount needs to be run first')
return deploy_tileset() return set_tileset_versions()
@cli.command() @cli.command()
@@ -166,7 +166,7 @@ def sync(ctx):
ctx.invoke(download_assets) ctx.invoke(download_assets)
deploy_done = ctx.invoke(deploy_tileset_version) deploy_done = ctx.invoke(set_latest_versions)
if download_done or deploy_done: if download_done or deploy_done:
ctx.invoke(nginx_sync) ctx.invoke(nginx_sync)

View File

@@ -9,7 +9,7 @@ def write_nginx_config():
with open(TEMPLATES_DIR / 'nginx_cf.conf') as fp: with open(TEMPLATES_DIR / 'nginx_cf.conf') as fp:
nginx_template = fp.read() nginx_template = fp.read()
location_block_str = '' location_str = ''
curl_text = '' curl_text = ''
for subdir in MNT_DIR.iterdir(): for subdir in MNT_DIR.iterdir():
@@ -18,17 +18,41 @@ def write_nginx_config():
area, version = subdir.name.split('-') area, version = subdir.name.split('-')
location_str += create_version_location(area, version, subdir)
if not curl_text:
curl_text = (
'\ntest with:\n'
f'curl -H "Host: ofm" -I http://localhost/{area}/{version}/14/8529/5975.pbf\n'
f'curl -I https://tiles.openfreemap.org/{area}/{version}/14/8529/5975.pbf'
)
location_str += create_deployed_location(area, version, subdir)
nginx_template = nginx_template.replace('___LOCATION_BLOCKS___', location_str)
with open('/data/nginx/sites/ofm-tiles-org.conf', 'w') as fp:
fp.write(nginx_template)
print(' nginx config written')
subprocess.run(['nginx', '-t'], check=True)
subprocess.run(['systemctl', 'reload', 'nginx'], check=True)
print(curl_text)
def create_version_location(area: str, version: str, subdir: Path):
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 return ''
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 return ''
url_prefix = f'https://tiles.openfreemap.org/{area}/{version}' url_prefix = f'https://tiles.openfreemap.org/{area}/{version}'
@@ -45,7 +69,7 @@ def write_nginx_config():
) )
# TODO # target 10y # TODO # target 10y
version_str = f""" return 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
default_type application/json; default_type application/json;
@@ -66,22 +90,6 @@ def write_nginx_config():
}} }}
""" """
location_block_str += version_str
if not curl_text: def create_deployed_location(area: str, version: str, subdir: Path):
curl_text = ( pass
'\ntest with:\n'
f'curl -H "Host: ofm" -I http://localhost/{area}/{version}/14/8529/5975.pbf\n'
f'curl -I https://tiles.openfreemap.org/{area}/{version}/14/8529/5975.pbf'
)
nginx_template = nginx_template.replace('___LOCATION_BLOCKS___', location_block_str)
with open('/data/nginx/sites/ofm-tiles-org.conf', 'w') as fp:
fp.write(nginx_template)
print(' nginx config written')
subprocess.run(['nginx', '-t'], check=True)
subprocess.run(['systemctl', 'reload', 'nginx'], check=True)
print(curl_text)

View File

@@ -3,7 +3,7 @@ from pathlib import Path
import requests import requests
def deploy_tileset(): def set_tileset_versions():
need_nginx_sync = False need_nginx_sync = False
for area in ['planet', 'monaco']: for area in ['planet', 'monaco']: