mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
run_http_host_sync
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from dotenv import dotenv_values
|
from dotenv import dotenv_values
|
||||||
@@ -12,7 +11,7 @@ from ssh_lib.nginx import certbot, nginx
|
|||||||
from ssh_lib.pkg_base import pkg_base, pkg_upgrade
|
from ssh_lib.pkg_base import pkg_base, pkg_upgrade
|
||||||
from ssh_lib.planetiler import planetiler
|
from ssh_lib.planetiler import planetiler
|
||||||
from ssh_lib.rclone import rclone
|
from ssh_lib.rclone import rclone
|
||||||
from ssh_lib.utils import add_user, enable_sudo, put, put_dir, reboot, sudo_cmd
|
from ssh_lib.utils import add_user, enable_sudo, put, put_dir, sudo_cmd
|
||||||
|
|
||||||
|
|
||||||
def prepare_shared(c):
|
def prepare_shared(c):
|
||||||
@@ -88,7 +87,7 @@ def prepare_tile_gen(c):
|
|||||||
c.sudo('chown ofm:ofm -R /data/ofm/tile_gen/bin')
|
c.sudo('chown ofm:ofm -R /data/ofm/tile_gen/bin')
|
||||||
|
|
||||||
|
|
||||||
def prepare_http_host(c, skip_cron: bool):
|
def prepare_http_host(c):
|
||||||
nginx(c)
|
nginx(c)
|
||||||
certbot(c)
|
certbot(c)
|
||||||
|
|
||||||
@@ -105,9 +104,15 @@ def prepare_http_host(c, skip_cron: bool):
|
|||||||
|
|
||||||
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
|
|
||||||
if not skip_cron:
|
def add_http_host_cron(c):
|
||||||
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 run_http_host_sync(c):
|
||||||
|
sudo_cmd(
|
||||||
|
c, '/data/ofm/venv/bin/python -u /data/ofm/http_host/bin/host_manager.py sync', user='ofm'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def upload_https_host_files(c):
|
def upload_https_host_files(c):
|
||||||
@@ -134,11 +139,6 @@ def install_benchmark(c):
|
|||||||
wrk(c)
|
wrk(c)
|
||||||
|
|
||||||
|
|
||||||
def debug_tmp(c):
|
|
||||||
upload_https_host_files(c)
|
|
||||||
# put(c, SCRIPTS_DIR / 'http_host' / 'cron.d' / 'ofm_http_host', '/etc/cron.d/')
|
|
||||||
|
|
||||||
|
|
||||||
def get_connection(hostname, user, port):
|
def get_connection(hostname, user, port):
|
||||||
ssh_passwd = dotenv_values(f'{CONFIG_DIR}/.env').get('SSH_PASSWD')
|
ssh_passwd = dotenv_values(f'{CONFIG_DIR}/.env').get('SSH_PASSWD')
|
||||||
|
|
||||||
@@ -180,7 +180,10 @@ def http_host_once(hostname, user, port):
|
|||||||
return
|
return
|
||||||
|
|
||||||
c = get_connection(hostname, user, port)
|
c = get_connection(hostname, user, port)
|
||||||
prepare_http_host(c, True)
|
|
||||||
|
prepare_shared(c)
|
||||||
|
|
||||||
|
prepare_http_host(c)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@@ -190,7 +193,11 @@ def http_host_autoupdate(hostname, user, port):
|
|||||||
return
|
return
|
||||||
|
|
||||||
c = get_connection(hostname, user, port)
|
c = get_connection(hostname, user, port)
|
||||||
prepare_http_host(c, False)
|
|
||||||
|
prepare_shared(c)
|
||||||
|
|
||||||
|
prepare_http_host(c)
|
||||||
|
add_http_host_cron(c)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@@ -200,6 +207,9 @@ def tile_gen(hostname, user, port):
|
|||||||
return
|
return
|
||||||
|
|
||||||
c = get_connection(hostname, user, port)
|
c = get_connection(hostname, user, port)
|
||||||
|
|
||||||
|
prepare_shared(c)
|
||||||
|
|
||||||
prepare_tile_gen(c)
|
prepare_tile_gen(c)
|
||||||
|
|
||||||
|
|
||||||
@@ -207,7 +217,8 @@ def tile_gen(hostname, user, port):
|
|||||||
@common_options
|
@common_options
|
||||||
def debug(hostname, user, port):
|
def debug(hostname, user, port):
|
||||||
c = get_connection(hostname, user, port)
|
c = get_connection(hostname, user, port)
|
||||||
print(c)
|
|
||||||
|
run_http_host_sync(c)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ def append_str(c, remote_path, str_):
|
|||||||
c.sudo(f'rm -f {tmp_path}')
|
c.sudo(f'rm -f {tmp_path}')
|
||||||
|
|
||||||
|
|
||||||
def sudo_cmd(c, cmd, user=None):
|
def sudo_cmd(c, cmd, *, user=None):
|
||||||
cmd = cmd.replace('"', '\\"')
|
cmd = cmd.replace('"', '\\"')
|
||||||
c.sudo(f'bash -c "{cmd}"', user=user)
|
c.sudo(f'bash -c "{cmd}"', user=user)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user