mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
loadbalancer
This commit is contained in:
@@ -3,20 +3,18 @@
|
|||||||
import click
|
import click
|
||||||
from fabric import Config, Connection
|
from fabric import Config, Connection
|
||||||
|
|
||||||
from ssh_lib import SCRIPTS_DIR, TILE_GEN_BIN, VENV_BIN, dotenv_val
|
from ssh_lib import SCRIPTS_DIR, TILE_GEN_BIN, dotenv_val
|
||||||
from ssh_lib.planetiler import planetiler
|
|
||||||
from ssh_lib.tasks import (
|
from ssh_lib.tasks import (
|
||||||
prepare_http_host,
|
prepare_http_host,
|
||||||
prepare_shared,
|
prepare_shared,
|
||||||
prepare_tile_gen,
|
prepare_tile_gen,
|
||||||
run_http_host_sync,
|
run_http_host_sync,
|
||||||
setup_ledns_writer,
|
setup_ledns_writer,
|
||||||
|
setup_loadbalancer,
|
||||||
upload_http_host_config,
|
upload_http_host_config,
|
||||||
upload_http_host_files,
|
|
||||||
)
|
)
|
||||||
from ssh_lib.utils import (
|
from ssh_lib.utils import (
|
||||||
put,
|
put,
|
||||||
sudo_cmd,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -111,6 +109,18 @@ def ledns_writer(hostname, user, port):
|
|||||||
setup_ledns_writer(c)
|
setup_ledns_writer(c)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@common_options
|
||||||
|
def loadbalancer(hostname, user, port):
|
||||||
|
if not click.confirm(f'Run script on {hostname}?'):
|
||||||
|
return
|
||||||
|
|
||||||
|
c = get_connection(hostname, user, port)
|
||||||
|
prepare_shared(c)
|
||||||
|
|
||||||
|
setup_loadbalancer(c)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@common_options
|
@common_options
|
||||||
def debug(hostname, user, port):
|
def debug(hostname, user, port):
|
||||||
|
|||||||
13
scripts/loadbalancer/setup.py
Normal file
13
scripts/loadbalancer/setup.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
|
|
||||||
|
requirements = [
|
||||||
|
'click',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
setup(
|
||||||
|
python_requires='>=3.10',
|
||||||
|
install_requires=requirements,
|
||||||
|
packages=find_packages(),
|
||||||
|
)
|
||||||
@@ -29,8 +29,6 @@ def prepare_shared(c):
|
|||||||
pkg_base(c)
|
pkg_base(c)
|
||||||
rclone(c)
|
rclone(c)
|
||||||
|
|
||||||
kernel_tweaks_ofm(c)
|
|
||||||
|
|
||||||
c.sudo(f'mkdir -p {REMOTE_CONFIG}')
|
c.sudo(f'mkdir -p {REMOTE_CONFIG}')
|
||||||
c.sudo(f'chown ofm:ofm {REMOTE_CONFIG}')
|
c.sudo(f'chown ofm:ofm {REMOTE_CONFIG}')
|
||||||
c.sudo(f'chown ofm:ofm {OFM_DIR}')
|
c.sudo(f'chown ofm:ofm {OFM_DIR}')
|
||||||
@@ -118,6 +116,8 @@ def upload_http_host_config(c):
|
|||||||
|
|
||||||
|
|
||||||
def prepare_http_host(c):
|
def prepare_http_host(c):
|
||||||
|
kernel_tweaks_ofm(c)
|
||||||
|
|
||||||
nginx(c)
|
nginx(c)
|
||||||
certbot(c)
|
certbot(c)
|
||||||
|
|
||||||
@@ -172,6 +172,7 @@ def setup_ledns_writer(c):
|
|||||||
assert le_email
|
assert le_email
|
||||||
assert domain_ledns
|
assert domain_ledns
|
||||||
assert (CONFIG_DIR / 'rclone.conf').exists()
|
assert (CONFIG_DIR / 'rclone.conf').exists()
|
||||||
|
assert (CONFIG_DIR / 'cloudflare.ini').exists()
|
||||||
|
|
||||||
rclone(c)
|
rclone(c)
|
||||||
certbot(c)
|
certbot(c)
|
||||||
@@ -218,3 +219,25 @@ def setup_ledns_writer(c):
|
|||||||
f'--deploy-hook /data/ofm/ledns/rclone_write.sh '
|
f'--deploy-hook /data/ofm/ledns/rclone_write.sh '
|
||||||
f'-d {domain_ledns}',
|
f'-d {domain_ledns}',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_loadbalancer(c):
|
||||||
|
load_balance_host_list = [
|
||||||
|
h.strip() for h in dotenv_val('LOAD_BALANCE_HOST_LIST').split(',') if h.strip()
|
||||||
|
]
|
||||||
|
assert (CONFIG_DIR / 'cloudflare.ini').exists()
|
||||||
|
|
||||||
|
c.sudo(f'mkdir -p {REMOTE_CONFIG}')
|
||||||
|
|
||||||
|
put(
|
||||||
|
c,
|
||||||
|
CONFIG_DIR / 'cloudflare.ini',
|
||||||
|
f'{REMOTE_CONFIG}/cloudflare.ini',
|
||||||
|
permissions=400,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
c.sudo('rm -rf /data/ofm/loadbalancer')
|
||||||
|
put_dir(c, SCRIPTS_DIR / 'loadbalancer', '/data/ofm/loadbalancer')
|
||||||
|
|
||||||
|
c.sudo(f'{VENV_BIN}/pip install -e /data/ofm/loadbalancer')
|
||||||
|
|||||||
Reference in New Issue
Block a user