mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-22 06:22:16 +00:00
cron fixes
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
# every minute sync, locking so that only one process can run at a time
|
# every minute sync, locking so that only one process can run at a time
|
||||||
* * * * * ofm /usr/bin/flock -n /tmp/hostmanager.lockfile -c \
|
* * * * * ofm /usr/bin/flock -n /tmp/hostmanager.lockfile -c 'sudo /data/ofm/venv/bin/python -u /data/ofm/http_host/bin/host_manager.py sync >> /data/ofm/http_host/logs/host_manager_sync.log 2>&1'
|
||||||
'sudo /data/ofm/venv/bin/python -u /data/ofm/http_host/bin/host_manager.py sync >> /data/ofm/http_host/logs/host_manager_sync.log 2>&1'
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ def download_tileset(area: str, version: str, list_versions: bool, runs_dir: Pat
|
|||||||
Version can also be specified.
|
Version can also be specified.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print('running download_tileset')
|
||||||
|
|
||||||
if area not in {'planet', 'monaco'}:
|
if area not in {'planet', 'monaco'}:
|
||||||
sys.exit('Please specify area: "planet" or "monaco"')
|
sys.exit('Please specify area: "planet" or "monaco"')
|
||||||
|
|
||||||
@@ -83,6 +85,8 @@ def download_assets(assets_dir: Path):
|
|||||||
Downloads and extracts assets
|
Downloads and extracts assets
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print('running download_assets')
|
||||||
|
|
||||||
if not assets_dir:
|
if not assets_dir:
|
||||||
assets_dir = DEFAULT_ASSETS_DIR
|
assets_dir = DEFAULT_ASSETS_DIR
|
||||||
|
|
||||||
@@ -98,6 +102,9 @@ def mount():
|
|||||||
Mounts/unmounts the btrfs images from /data/ofm/http_host/runs automatically.
|
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.
|
When finished, /mnt/ofm dir will have all the present tiles.btrfs files mounted in a read-only way.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print('running mount')
|
||||||
|
|
||||||
assert_linux()
|
assert_linux()
|
||||||
assert_sudo()
|
assert_sudo()
|
||||||
|
|
||||||
@@ -123,6 +130,8 @@ def set_latest_versions():
|
|||||||
2. Writes to a version file
|
2. Writes to a version file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print('running set_latest_versions')
|
||||||
|
|
||||||
assert_linux()
|
assert_linux()
|
||||||
assert_sudo()
|
assert_sudo()
|
||||||
|
|
||||||
@@ -138,6 +147,8 @@ def nginx_sync():
|
|||||||
Syncs the nginx config to the state of the system
|
Syncs the nginx config to the state of the system
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print('running nginx_sync')
|
||||||
|
|
||||||
assert_linux()
|
assert_linux()
|
||||||
assert_sudo()
|
assert_sudo()
|
||||||
|
|
||||||
@@ -154,13 +165,16 @@ def sync(ctx):
|
|||||||
Runs the sync task, normally called by cron every minute
|
Runs the sync task, normally called by cron every minute
|
||||||
On a new server this also takes care of everything, no need to run anything manually.
|
On a new server this also takes care of everything, no need to run anything manually.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print('---')
|
||||||
|
print('running sync')
|
||||||
print(datetime.datetime.now(tz=datetime.timezone.utc))
|
print(datetime.datetime.now(tz=datetime.timezone.utc))
|
||||||
|
|
||||||
assert_single_process()
|
assert_single_process()
|
||||||
|
|
||||||
download_done = False
|
download_done = False
|
||||||
download_done += ctx.invoke(download_tileset, area='monaco')
|
download_done += ctx.invoke(download_tileset, area='monaco')
|
||||||
download_done += ctx.invoke(download_tileset, area='planet')
|
# download_done += ctx.invoke(download_tileset, area='planet')
|
||||||
if download_done:
|
if download_done:
|
||||||
ctx.invoke(mount)
|
ctx.invoke(mount)
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,39 @@ from pathlib import Path
|
|||||||
from http_host_lib import DEFAULT_RUNS_DIR, MNT_DIR
|
from http_host_lib import DEFAULT_RUNS_DIR, MNT_DIR
|
||||||
|
|
||||||
|
|
||||||
|
def create_fstab():
|
||||||
|
fstab_new = []
|
||||||
|
|
||||||
|
for area in ['planet', 'monaco']:
|
||||||
|
area_dir = (DEFAULT_RUNS_DIR / area).resolve()
|
||||||
|
if not area_dir.exists():
|
||||||
|
continue
|
||||||
|
|
||||||
|
versions = sorted(area_dir.iterdir())
|
||||||
|
for version in versions:
|
||||||
|
version_str = version.name
|
||||||
|
btrfs_file = area_dir / version_str / 'tiles.btrfs'
|
||||||
|
if not btrfs_file.is_file():
|
||||||
|
continue
|
||||||
|
|
||||||
|
mnt_folder = MNT_DIR / f'{area}-{version_str}'
|
||||||
|
mnt_folder.mkdir(exist_ok=True, parents=True)
|
||||||
|
|
||||||
|
fstab_new.append(f'{btrfs_file} {mnt_folder} btrfs loop,ro 0 0\n')
|
||||||
|
print(f' created fstab entry for {btrfs_file} -> {mnt_folder}')
|
||||||
|
|
||||||
|
with open('/etc/fstab') as fp:
|
||||||
|
fstab_orig = [l for l in fp.readlines() if f'{MNT_DIR}/' not in l]
|
||||||
|
|
||||||
|
with open('/etc/fstab', 'w') as fp:
|
||||||
|
fp.writelines(fstab_orig + fstab_new)
|
||||||
|
|
||||||
|
|
||||||
def clean_up_mounts(mnt_dir):
|
def clean_up_mounts(mnt_dir):
|
||||||
if not mnt_dir.exists():
|
if not mnt_dir.exists():
|
||||||
return
|
return
|
||||||
|
|
||||||
print('Cleaning up mounts')
|
print(' cleaning up mounts')
|
||||||
|
|
||||||
# handle deleted files
|
# handle deleted files
|
||||||
p = subprocess.run(['mount'], capture_output=True, text=True, check=True)
|
p = subprocess.run(['mount'], capture_output=True, text=True, check=True)
|
||||||
@@ -32,31 +60,3 @@ def clean_up_mounts(mnt_dir):
|
|||||||
print(f' removing old mount {subdir}')
|
print(f' removing old mount {subdir}')
|
||||||
subprocess.run(['umount', subdir], check=True)
|
subprocess.run(['umount', subdir], check=True)
|
||||||
subdir.rmdir()
|
subdir.rmdir()
|
||||||
|
|
||||||
|
|
||||||
def create_fstab():
|
|
||||||
fstab_new = []
|
|
||||||
|
|
||||||
for area in ['planet', 'monaco']:
|
|
||||||
area_dir = (DEFAULT_RUNS_DIR / area).resolve()
|
|
||||||
if not area_dir.exists():
|
|
||||||
continue
|
|
||||||
|
|
||||||
versions = sorted(area_dir.iterdir())
|
|
||||||
for version in versions:
|
|
||||||
version_str = version.name
|
|
||||||
btrfs_file = area_dir / version_str / 'tiles.btrfs'
|
|
||||||
if not btrfs_file.is_file():
|
|
||||||
continue
|
|
||||||
|
|
||||||
mnt_folder = MNT_DIR / f'{area}-{version_str}'
|
|
||||||
mnt_folder.mkdir(exist_ok=True, parents=True)
|
|
||||||
|
|
||||||
fstab_new.append(f'{btrfs_file} {mnt_folder} btrfs loop,ro 0 0\n')
|
|
||||||
print(f'Created fstab entry for {btrfs_file} -> {mnt_folder}')
|
|
||||||
|
|
||||||
with open('/etc/fstab') as fp:
|
|
||||||
fstab_orig = [l for l in fp.readlines() if f'{MNT_DIR}/' not in l]
|
|
||||||
|
|
||||||
with open('/etc/fstab', 'w') as fp:
|
|
||||||
fp.writelines(fstab_orig + fstab_new)
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ def get_remote_file_size(url: str) -> int | None:
|
|||||||
|
|
||||||
|
|
||||||
def download_file_aria2(url: str, local_file: Path):
|
def download_file_aria2(url: str, local_file: Path):
|
||||||
print(f'Downloading: {url} into {local_file}')
|
print(f' downloading: {url} into {local_file}')
|
||||||
|
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user