This commit is contained in:
Zsolt Ero
2025-09-18 01:11:07 +02:00
parent a8bcc9c480
commit 8e58957651
3 changed files with 66 additions and 7 deletions

View File

@@ -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')

View File

@@ -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)

View File

@@ -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):