From 231469a1c28956ba57b977350ebfd86270f29082 Mon Sep 17 00:00:00 2001 From: Zsolt Ero Date: Wed, 27 Dec 2023 03:01:16 +0100 Subject: [PATCH] work --- init-server.py | 25 +++++++++++++++++-------- ssh_lib/benchmark.py | 4 ++-- ssh_lib/config.py | 11 ++++++++--- ssh_lib/kernel.py | 6 +++--- ssh_lib/nginx.py | 8 ++++---- ssh_lib/planetiler.py | 3 +-- 6 files changed, 35 insertions(+), 22 deletions(-) diff --git a/init-server.py b/init-server.py index 37a7a59..c453d7a 100755 --- a/init-server.py +++ b/init-server.py @@ -6,11 +6,11 @@ from dotenv import dotenv_values from fabric import Config, Connection from ssh_lib.benchmark import benchmark, c1000k -from ssh_lib.config import assets_dir, config_dir, scripts_dir +from ssh_lib.config import ASSETS_DIR, CONFIG_DIR, REMOTE_CONFIG, SCRIPTS_DIR, TILE_GEN_BIN from ssh_lib.kernel import set_cpu_governor, setup_kernel_settings from ssh_lib.nginx import certbot, nginx from ssh_lib.pkg_base import pkg_base, pkg_upgrade -from ssh_lib.planetiler import TILE_GEN_BIN, install_planetiler +from ssh_lib.planetiler import install_planetiler from ssh_lib.rclone import install_rclone from ssh_lib.utils import add_user, enable_sudo, put, reboot, sudo_cmd @@ -40,14 +40,14 @@ def prepare_tile_gen(c): ]: put( c, - scripts_dir / 'tile_gen' / file, + SCRIPTS_DIR / 'tile_gen' / file, TILE_GEN_BIN, permissions='755', ) put( c, - scripts_dir / 'tile_gen' / 'extract_mbtiles' / 'extract_mbtiles.py', + SCRIPTS_DIR / 'tile_gen' / 'extract_mbtiles' / 'extract_mbtiles.py', f'{TILE_GEN_BIN}/extract_mbtiles/extract_mbtiles.py', permissions='755', create_parent_dir=True, @@ -55,12 +55,21 @@ def prepare_tile_gen(c): put( c, - scripts_dir / 'tile_gen' / 'shrink_btrfs' / 'shrink_btrfs.py', + SCRIPTS_DIR / 'tile_gen' / 'shrink_btrfs' / 'shrink_btrfs.py', f'{TILE_GEN_BIN}/shrink_btrfs/shrink_btrfs.py', permissions='755', create_parent_dir=True, ) + if (CONFIG_DIR / 'rclone.conf').exists(): + put( + c, + CONFIG_DIR / 'rclone.conf', + REMOTE_CONFIG, + permissions='600', + create_parent_dir=True, + ) + c.sudo('chown ofm:ofm /data/ofm') c.sudo('chown -R ofm:ofm /data/ofm/tile_gen') @@ -77,8 +86,8 @@ def debug_tmp(c): c.sudo('rm -rf /data/ofm/logs') c.sudo('mkdir -p /data/ofm/logs') c.sudo('rm -f /data/nginx/logs/*') - put(c, f'{assets_dir}/nginx/nginx.conf', '/etc/nginx/') - put(c, f'{scripts_dir}/http_host/nginx_site.conf', '/data/nginx/sites') + put(c, f'{ASSETS_DIR}/nginx/nginx.conf', '/etc/nginx/') + put(c, f'{SCRIPTS_DIR}/http_host/nginx_site.conf', '/data/nginx/sites') c.sudo('nginx -t') c.sudo('service nginx restart') @@ -106,7 +115,7 @@ def main(hostname, user, port, tile_gen, http_host, skip_shared, do_reboot, debu if not tile_gen and not http_host: return - ssh_passwd = dotenv_values(f'{config_dir}/.env').get('SSH_PASSWD') + ssh_passwd = dotenv_values(f'{CONFIG_DIR}/.env').get('SSH_PASSWD') if ssh_passwd: c = Connection( diff --git a/ssh_lib/benchmark.py b/ssh_lib/benchmark.py index 4a572c2..6a793ea 100644 --- a/ssh_lib/benchmark.py +++ b/ssh_lib/benchmark.py @@ -1,4 +1,4 @@ -from ssh_lib.config import scripts_dir +from ssh_lib.config import SCRIPTS_DIR from ssh_lib.utils import apt_get_install, put @@ -17,6 +17,6 @@ def c1000k(c): def benchmark(c): apt_get_install(c, 'wrk') c.sudo('mkdir -p /data/ofm/benchmark') - put(c, f'{scripts_dir}/http_host/benchmark/wrk_custom_list.lua', '/data/ofm/benchmark') + put(c, f'{SCRIPTS_DIR}/http_host/benchmark/wrk_custom_list.lua', '/data/ofm/benchmark') # wrk -c10 -d10s -t1 -s /data/ofm/benchmark/wrk_custom_list.lua http://localhost diff --git a/ssh_lib/config.py b/ssh_lib/config.py index 0d60c71..468177a 100644 --- a/ssh_lib/config.py +++ b/ssh_lib/config.py @@ -2,6 +2,11 @@ from pathlib import Path base = Path(__file__).parent.parent -config_dir = base / 'config' -scripts_dir = base / 'scripts' -assets_dir = Path(__file__).parent / 'assets' + +CONFIG_DIR = base / 'config' +SCRIPTS_DIR = base / 'scripts' +ASSETS_DIR = Path(__file__).parent / 'assets' + + +TILE_GEN_BIN = '/data/ofm/tile_gen/bin' +REMOTE_CONFIG = '/data/ofm/config' diff --git a/ssh_lib/kernel.py b/ssh_lib/kernel.py index 1e09546..499903c 100644 --- a/ssh_lib/kernel.py +++ b/ssh_lib/kernel.py @@ -1,10 +1,10 @@ -from ssh_lib.config import assets_dir +from ssh_lib.config import ASSETS_DIR from ssh_lib.utils import apt_get_install, apt_get_purge, put, put_str def setup_kernel_settings(c): - put(c, f'{assets_dir}/kernel/60-ofm.conf', '/etc/sysctl.d/') - put(c, f'{assets_dir}/kernel/limits-ofm.conf', '/etc/security/limits.d/') + put(c, f'{ASSETS_DIR}/kernel/60-ofm.conf', '/etc/sysctl.d/') + put(c, f'{ASSETS_DIR}/kernel/limits-ofm.conf', '/etc/security/limits.d/') def set_cpu_governor(c): diff --git a/ssh_lib/nginx.py b/ssh_lib/nginx.py index a34c629..a5da223 100644 --- a/ssh_lib/nginx.py +++ b/ssh_lib/nginx.py @@ -1,4 +1,4 @@ -from ssh_lib.config import assets_dir +from ssh_lib.config import ASSETS_DIR from ssh_lib.utils import ( apt_get_install, apt_get_purge, @@ -46,9 +46,9 @@ def nginx(c): hide=True, ) - put(c, f'{assets_dir}/nginx/nginx.conf', '/etc/nginx/') - put(c, f'{assets_dir}/nginx/default_disable.conf', '/data/nginx/sites') - put(c, f'{assets_dir}/nginx/cloudflare.conf', '/data/nginx/config') + put(c, f'{ASSETS_DIR}/nginx/nginx.conf', '/etc/nginx/') + put(c, f'{ASSETS_DIR}/nginx/default_disable.conf', '/data/nginx/sites') + put(c, f'{ASSETS_DIR}/nginx/cloudflare.conf', '/data/nginx/config') c.sudo('service nginx restart') diff --git a/ssh_lib/planetiler.py b/ssh_lib/planetiler.py index a7b34b8..60f112f 100644 --- a/ssh_lib/planetiler.py +++ b/ssh_lib/planetiler.py @@ -1,9 +1,8 @@ +from ssh_lib.config import TILE_GEN_BIN from ssh_lib.utils import apt_get_install, apt_get_update PLANETILER_VERSION = '0.7.0' - -TILE_GEN_BIN = '/data/ofm/tile_gen/bin' PLANETILER_PATH = f'{TILE_GEN_BIN}/planetiler.jar'