mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
nginx sync
This commit is contained in:
19
scripts/http_host/nginx_sync/nginx_site.conf
Normal file
19
scripts/http_host/nginx_sync/nginx_site.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
server {
|
||||
server_name ofm tiles.openfreemaps.org;
|
||||
|
||||
# disabling access log by default
|
||||
# access_log /data/ofm/http_host/logs_nginx/nginx-access.log access_json buffer=32k;
|
||||
access_log off;
|
||||
|
||||
error_log /data/ofm/http_host/logs_nginx/nginx-error.log;
|
||||
|
||||
|
||||
___LOCATION_BLOCKS___
|
||||
|
||||
|
||||
# we need to handle missing tiles as valid request returning empty string
|
||||
location @empty {
|
||||
default_type application/vnd.mapbox-vector-tile;
|
||||
return 200 '';
|
||||
}
|
||||
}
|
||||
61
scripts/http_host/nginx_sync/nginx_sync.py
Executable file
61
scripts/http_host/nginx_sync/nginx_sync.py
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def cli():
|
||||
if not Path('/etc/fstab').exists():
|
||||
sys.exit('Needs to be run on Linux')
|
||||
|
||||
if os.geteuid() != 0:
|
||||
sys.exit('Needs sudo')
|
||||
|
||||
if not Path('/mnt/ofm').exists():
|
||||
sys.exit('mounter.py needs to be run first')
|
||||
|
||||
with open(Path(__file__).parent / 'nginx_site.conf') as fp:
|
||||
nginx_template = fp.read()
|
||||
|
||||
location_block_str = ''
|
||||
help_text = ''
|
||||
|
||||
for subdir in Path('/mnt/ofm').iterdir():
|
||||
if not subdir.is_dir():
|
||||
continue
|
||||
|
||||
area, version = subdir.name.split('-')
|
||||
|
||||
version_str = rf"""
|
||||
location /{area}/{version}/ {{
|
||||
alias {subdir};
|
||||
try_files $uri @empty;
|
||||
}}
|
||||
"""
|
||||
|
||||
location_block_str += version_str
|
||||
|
||||
if not help_text:
|
||||
help_text = (
|
||||
'\ntest with:\n'
|
||||
f'curl -H "Host: ofm" -I http://localhost/{area}/{version}/tiles/14/8529/5975.pbf'
|
||||
)
|
||||
|
||||
nginx_template = nginx_template.replace('___LOCATION_BLOCKS___', location_block_str)
|
||||
|
||||
with open('/data/nginx/sites/ofm.conf', 'w') as fp:
|
||||
fp.write(nginx_template)
|
||||
print('nginx config written')
|
||||
|
||||
subprocess.run(['nginx', '-t'], check=True)
|
||||
subprocess.run(['service', 'nginx', 'reload'], check=True)
|
||||
|
||||
print(help_text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli()
|
||||
Reference in New Issue
Block a user