From 8e589576516a940d47067b633ac34eabacca06ad Mon Sep 17 00:00:00 2001 From: Zsolt Ero Date: Thu, 18 Sep 2025 01:11:07 +0200 Subject: [PATCH] work --- ssh_lib/kernel.py | 15 +++++++++++---- ssh_lib/pkg_base.py | 36 ++++++++++++++++++++++++++++++++++++ ssh_lib/utils.py | 22 +++++++++++++++++++--- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/ssh_lib/kernel.py b/ssh_lib/kernel.py index 5e2c1c7..f317095 100644 --- a/ssh_lib/kernel.py +++ b/ssh_lib/kernel.py @@ -1,4 +1,5 @@ -from ssh_lib.utils import put_str +from ssh_lib import ASSETS_DIR +from ssh_lib.utils import put, put_str def kernel_somaxconn65k(c): @@ -18,6 +19,12 @@ def kernel_limits1m(c): ) -def kernel_tweaks_ofm(c): - kernel_somaxconn65k(c) - kernel_limits1m(c) +def kernel_vmovercommit(c): + put_str(c, '/etc/sysctl.d/60-vmovercommit.conf', 'vm.overcommit_memory = 1') + + +def kernel_thp_fix(c): + # transparent_hugepage + put(c, f'{ASSETS_DIR}/kernel/thp_fix_service', '/etc/systemd/system/thp_fix.service') + c.sudo('systemctl daemon-reload') + c.sudo('systemctl enable thp_fix') diff --git a/ssh_lib/pkg_base.py b/ssh_lib/pkg_base.py index 98c07be..a39ac95 100644 --- a/ssh_lib/pkg_base.py +++ b/ssh_lib/pkg_base.py @@ -33,10 +33,46 @@ def pkg_base(c): # 'python3', 'python3-venv', + # + 'acpid', + 'autojump', + 'bash-completion', + 'btop', + 'ctop', + 'dbus', + 'direnv', + 'fd-find', + 'file', + 'ioping', + 'libffi-dev', + 'libssl-dev', + 'lsof', + 'man-db', + 'mc', + 'nano', + 'ncdu', + 'net-tools', + 'netbase', + 'nethogs', + 'openssh-client', + 'p7zip-full', + 'pkg-config', + 'psmisc', + 'ripgrep', + 'silversearcher-ag', + 'time', + 'tmux', + # + # 'dstat', + # 'iperf3', + # 'iproute2', + # 'nasm', ] apt_get_install(c, ' '.join(pkg_list)) + c.sudo('ln -s $(which fdfind) /usr/local/bin/fd', warn=True) + def pkg_upgrade(c): apt_get_update(c) diff --git a/ssh_lib/utils.py b/ssh_lib/utils.py index 3d2b9d4..01879f6 100644 --- a/ssh_lib/utils.py +++ b/ssh_lib/utils.py @@ -60,20 +60,36 @@ def put_dir( put(c, file, f'{remote_dir}/{file.name}', file_permissions, user, group) -def put_str(c, remote_path, str_): +def put_str(c, remote_path, str_, create_parent_dir=False): tmp_file = 'tmp.txt' with open(tmp_file, 'w') as outfile: outfile.write(str_ + '\n') - put(c, tmp_file, remote_path) + put(c, tmp_file, remote_path, create_parent_dir=create_parent_dir) os.remove(tmp_file) -def append_str(c, remote_path, str_): +def file_contains(c, file_path, search_str): + """Check if a file contains a specific string.""" + if not exists(c, file_path): + return False + + # Use grep -qF for fixed string search (no regex interpretation) + # -q for quiet (no output), -F for fixed string + result = c.sudo(f"grep -qF '{search_str}' '{file_path}'", warn=True, hide=True) + return result.ok + + +def append_str(c, remote_path, str_, check_duplicate=False): + """Append string to file. If check_duplicate=True, only append if string doesn't exist.""" + if check_duplicate and file_contains(c, remote_path, str_.strip()): + return False # String already exists, didn't append + tmp_path = f'/tmp/fabtmp_{random_string(8)}' put_str(c, tmp_path, str_) sudo_cmd(c, f"cat '{tmp_path}' >> '{remote_path}'") c.sudo(f'rm -f {tmp_path}') + return True # Successfully appended def sudo_cmd(c, cmd, *, user=None):