diff --git a/scripts/ops/rescue-sshd.sh b/scripts/ops/rescue-sshd.sh index 74d8160d..d8315d8d 100644 --- a/scripts/ops/rescue-sshd.sh +++ b/scripts/ops/rescue-sshd.sh @@ -19,7 +19,7 @@ # swapped out to the same NVMe: run server-hang-autoreboot.sh --swapoff too. set -euo pipefail -R=/run/rescue +R=${RESCUE_ROOT:-/run/rescue} PORT=2222 KEY_USER=${RESCUE_KEY_USER:-para} # whose authorized_keys are copied; the login inside the rescue chroot is root mode=""; laptop_ip="" @@ -29,19 +29,20 @@ while [ $# -gt 0 ]; do --install) mode=install ;; --check) mode=check ;; --remove) mode=remove ;; + --copytest) mode=copytest ;; --netconsole) mode=netconsole; laptop_ip=${2:?laptop ip}; shift ;; *) echo "unknown argument: $1" >&2; exit 2 ;; esac shift done if [ -z "$mode" ]; then sed -n '2,20p' "$0"; exit 0; fi -if [ "$(id -u)" -ne 0 ]; then echo "run as root (sudo)" >&2; exit 1; fi +if [ "$mode" != copytest ] && [ "$(id -u)" -ne 0 ]; then echo "run as root (sudo)" >&2; exit 1; fi copy_bin() { # copy a binary and its shared libraries into the chroot, same paths local b; b=$(readlink -f "$1") install -D "$b" "$R$b" [ "$b" = "$1" ] || { install -d "$R$(dirname "$1")"; ln -sf "$b" "$R$1"; } - ldd "$b" 2>/dev/null | awk '/=> \//{print $3} /^[[:space:]]*\//{print $1}' | while read -r l; do + { ldd "$b" 2>/dev/null || true; } | awk '/=> \//{print $3} /^[[:space:]]*\//{print $1}' | while read -r l; do local rl; rl=$(readlink -f "$l"); install -D "$rl" "$R$rl" [ "$rl" = "$l" ] || { install -d "$R$(dirname "$l")"; ln -sf "$rl" "$R$l"; } done @@ -110,6 +111,13 @@ EOF } case "$mode" in + copytest) # no root, no mounts, no daemon: only checks that every needed file can be copied (use RESCUE_ROOT=/some/dir) + rm -rf "$R"; install -d "$R" + for b in /usr/sbin/sshd /usr/bin/bash /usr/bin/busybox /usr/lib/openssh/sftp-server /usr/lib/openssh/sshd-session /usr/lib/openssh/sshd-auth; do + [ -e "$b" ] && copy_bin "$b" && echo "copied $b" + done + for l in $(ldconfig -p 2>/dev/null | awk '/libnss_files\.so/{print $NF}' | head -1); do rl=$(readlink -f "$l"); install -D "$rl" "$R$rl"; echo "copied $rl"; done + echo "copytest ok: $(find "$R" -type f | wc -l) files, $(du -sh "$R" | cut -f1)" ;; build) build ;; install) build diff --git a/scripts/ops/server-hang-autoreboot.sh b/scripts/ops/server-hang-autoreboot.sh index a2a55ff6..b6d87b9e 100644 --- a/scripts/ops/server-hang-autoreboot.sh +++ b/scripts/ops/server-hang-autoreboot.sh @@ -72,7 +72,7 @@ fi if [ "$want_swap" -eq 1 ]; then swapoff -a - cp -n /etc/fstab /etc/fstab.pre-leleka-noswap + [ -e /etc/fstab.pre-leleka-noswap ] || cp /etc/fstab /etc/fstab.pre-leleka-noswap sed -i -E 's|^([^#].*[[:space:]]swap[[:space:]].*)$|# \1 # disabled by server-hang-autoreboot.sh|' /etc/fstab say "swap off; fstab line commented (backup /etc/fstab.pre-leleka-noswap)" say "memory note: without swap a memory shortage ends in the OOM killer instead of a stall; with 121 GB RAM and our ~110 GB resident, keep an eye on MemAvailable." @@ -80,7 +80,7 @@ fi if [ "$want_nvme" -eq 1 ]; then f=/etc/default/grub - cp -n "$f" /etc/default/grub.pre-leleka-nvme + [ -e /etc/default/grub.pre-leleka-nvme ] || cp "$f" /etc/default/grub.pre-leleka-nvme if grep -q 'nvme_core.default_ps_max_latency_us' "$f"; then say "grub already has nvme_core.default_ps_max_latency_us" else