Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Guard agent installs against tight disks and rotate appliance agent logs
[email protected]0b9385f2f2cb
diff --git a/docs/UNIFIED_AGENT.md b/docs/UNIFIED_AGENT.mdindex 8e7a9ee19b..6353eec69b 100644--- a/docs/UNIFIED_AGENT.md+++ b/docs/UNIFIED_AGENT.md@@ -420,6 +420,30 @@ Set `--health-addr=""` or `PULSE_HEALTH_ADDR=off` to disable the health/metrics## Troubleshooting+### Installer Fails With "Not enough free disk space"++The installer stages the agent binary (~34 MiB) in a temporary directory before+moving it to the install directory, and checks free space in both before+downloading. On appliances whose root filesystem is a small RAM disk (QNAP QTS,+Unraid), `/tmp` and `/usr/local/bin` share that filesystem, so both the staged+and installed copy must fit at once.++If the check fails because `/tmp` is on a constrained root, point `TMPDIR` at a+directory on a data volume and re-run the installer:++```bash+TMPDIR=/share/CACHEDEV1_DATA/tmp bash install.sh --url http://pulse --token <token>+```++(`mktemp` honours `TMPDIR`, so this moves the staging copy off the RAM root.+Create the directory first if it does not exist.)++On QNAP the agent's rotating log is written to the data volume+(`<data-volume>/.pulse-agent/logs/pulse-agent.log`); on Unraid it is written to+`/var/log/pulse-agent/pulse-agent.log` with size-capped rotation. If an older+install filled `/var/log/pulse-agent.log` on the root filesystem, delete that+file and re-run the installer to pick up the rotating configuration.+### Agent Not Updating- Check logs: `journalctl -u pulse-agent -f`- Verify network connectivity to Pulse serverdiff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 5cdb0d8a15..5ce5035db0 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -4917,6 +4917,15 @@ that waits for the persistent data volume before launching the stored wrapper,and `internal/agentupdate/update.go` keeps the persisted QNAP binary copy insync on self-update so reboot does not roll the runtime back to an olderbinary.+That appliance lifecycle must remain bounded by available storage. Before+downloading or replacing an agent, `scripts/install.sh` checks the effective+temporary and installation filesystems for enough free space, coalesces the+check when both paths share a filesystem, honors an operator-selected+`TMPDIR`, and exposes the same check through `--preflight-only`. QNAP and+Unraid watchdogs must route agent output through the agent's rotating+`--log-file` writer instead of an unbounded shell append; their own watchdog+messages must also be size-bounded so either logging path cannot exhaust a+RAM-backed appliance root.Unified Agent lifecycle truth is agent-authored. The host report contract nowcarries the non-secret applied managed-config fingerprint, self-updater statediff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.mdindex 57948d15c7..2899c690ae 100644--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md@@ -2565,6 +2565,14 @@ for that volume before launching the wrapper, recover the same state duringuninstall, and keep the persisted boot copy aligned with updater-owned runtimebinary replacements instead of assuming `/usr/local/bin` survives reboot onQTS/QuTS hero.+Before any agent artifact download or replacement, that boundary must also+prove adequate space on the effective temporary and install filesystems,+deduplicating the requirement when both paths share a filesystem and honoring+an operator-supplied `TMPDIR`. `--preflight-only` must exercise the same+storage check and report an actionable alternate-temporary-directory hint.+Generated QNAP and Unraid watchdogs must use the agent's rotating `--log-file`+path rather than an unbounded stdout append, while keeping watchdog-owned+messages independently size-bounded.The in-app updater's apply pipeline now owns a downgrade guard on the normalapply path. A syntactically valid release asset URL can name a release olderdiff --git a/scripts/install.sh b/scripts/install.shindex f1efbcb427..60dacff3dc 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -95,6 +95,7 @@ KUBECONFIG_PATH="" # Path to kubeconfig file for Kubernetes monitoringKUBE_INCLUDE_ALL_PODS="false"KUBE_INCLUDE_ALL_DEPLOYMENTS="false"DISK_EXCLUDES=() # Array for multiple --disk-exclude values+AGENT_LOG_FILE="" # When set, pass --log-file so the agent's rotating log writer engages (set per platform)DEFAULT_STATE_DIR="/var/lib/pulse-agent"STATE_DIR="$DEFAULT_STATE_DIR" # Persistent state directory (overridden per platform)STATE_DIR_SOURCE="default" # default, explicit, recovered, or platform@@ -254,6 +255,116 @@ redact_token() {echo "$msg"}+# Minimum free space to stage (download to temp) and install the agent binary.+# The 6.x agent binary is ~34MiB; keep margin for growth. On appliances with a+# RAM-backed root (QNAP, Unraid) temp and install dir share one small filesystem.+AGENT_MIN_TEMP_FREE_BYTES=$((48 * 1024 * 1024))+AGENT_MIN_INSTALL_FREE_BYTES=$((48 * 1024 * 1024))++bytes_to_human() {+ local bytes="${1:-0}"++ if [[ ! "$bytes" =~ ^[0-9]+$ ]]; then+ printf '%s\n' "$bytes"+ return 0+ fi++ local units=("B" "KB" "MB" "GB" "TB")+ local value="$bytes"+ local unit_index=0++ while (( value >= 1024 && unit_index < ${#units[@]} - 1 )); do+ value=$((value / 1024))+ ((unit_index += 1))+ done++ printf '%s%s\n' "$value" "${units[$unit_index]}"+}++nearest_existing_dir() {+ local path="$1"++ while [[ -n "$path" && "$path" != "/" && ! -d "$path" ]]; do+ path=$(dirname "$path")+ done++ printf '%s\n' "${path:-/}"+}++get_available_bytes_for_path() {+ local path="$1"+ local available_kb=""++ available_kb=$(df -Pk "$path" 2>/dev/null | awk 'NR==2 {print $4}')+ if [[ ! "$available_kb" =~ ^[0-9]+$ ]]; then+ return 1+ fi++ printf '%s\n' $((available_kb * 1024))+}++get_filesystem_device_for_path() {+ local path="$1"+ local filesystem=""++ filesystem=$(df -Pk "$path" 2>/dev/null | awk 'NR==2 {print $1}')+ if [[ -z "$filesystem" ]]; then+ return 1+ fi++ printf '%s\n' "$filesystem"+}++ensure_agent_disk_headroom() {+ local temp_path="${1:-${TMPDIR:-/tmp}}"+ local install_path="${2:-$INSTALL_DIR}"+ local temp_fs=""+ local install_fs=""+ local temp_free_bytes=""+ local install_free_bytes=""+ local combined_required_bytes=$((AGENT_MIN_TEMP_FREE_BYTES + AGENT_MIN_INSTALL_FREE_BYTES))++ temp_path=$(nearest_existing_dir "$temp_path")+ install_path=$(nearest_existing_dir "$install_path")++ temp_fs=$(get_filesystem_device_for_path "$temp_path" 2>/dev/null || true)+ install_fs=$(get_filesystem_device_for_path "$install_path" 2>/dev/null || true)+ temp_free_bytes=$(get_available_bytes_for_path "$temp_path" 2>/dev/null || true)+ install_free_bytes=$(get_available_bytes_for_path "$install_path" 2>/dev/null || true)++ if [[ -z "$temp_free_bytes" || -z "$install_free_bytes" ]]; then+ log_warn "Could not determine available disk space for the install preflight; continuing anyway"+ return 0+ fi++ if [[ -n "$temp_fs" && "$temp_fs" == "$install_fs" ]]; then+ if (( temp_free_bytes < combined_required_bytes )); then+ log_error "Not enough free disk space to stage and install the Pulse agent"+ log_info "The same filesystem backs $temp_path and $install_path"+ log_info "Available: $(bytes_to_human "$temp_free_bytes"), required: $(bytes_to_human "$combined_required_bytes")"+ log_info "If this filesystem is a small RAM-backed root (common on QNAP/Unraid), set TMPDIR to a directory on a data volume before re-running, e.g. TMPDIR=/share/CACHEDEV1_DATA/tmp"+ return 1+ fi+ return 0+ fi++ if (( temp_free_bytes < AGENT_MIN_TEMP_FREE_BYTES )); then+ log_error "Not enough free disk space in $temp_path to stage the Pulse agent download"+ log_info "Available: $(bytes_to_human "$temp_free_bytes"), required: $(bytes_to_human "$AGENT_MIN_TEMP_FREE_BYTES")"+ log_info "Free disk space under $temp_path, or set TMPDIR to a directory with more space, and retry"+ return 1+ fi++ if (( install_free_bytes < AGENT_MIN_INSTALL_FREE_BYTES )); then+ log_error "Not enough free disk space in $install_path to install the Pulse agent"+ log_info "Available: $(bytes_to_human "$install_free_bytes"), required: $(bytes_to_human "$AGENT_MIN_INSTALL_FREE_BYTES")"+ log_info "Free disk space under $install_path and retry"+ return 1+ fi++ return 0+}+has_pinned_installer_signature_key() {[[ -n "$PINNED_INSTALLER_SSH_PUBLIC_KEY" && "$PINNED_INSTALLER_SSH_PUBLIC_KEY" != "__PULSE_INSTALLER_SSH_PUBLIC_KEY__" ]]}@@ -482,7 +593,7 @@ verify_agent_started() {local max_iterations=8local interval=2local iteration=0- local log_file="${TRUENAS_LOG_FILE:-$LOG_FILE}"+ local log_file="${AGENT_LOG_FILE:-${TRUENAS_LOG_FILE:-$LOG_FILE}}"log_info "Verifying agent started successfully..."@@ -1186,6 +1297,7 @@ write_qnap_wrapper_script() {local wrapper_script="$1"local runtime_binary="$2"local stored_binary="$3"+ local log_dir="$4"local service_env_lines="$SHELL_EXPORT_LINES"cat > "$wrapper_script" <<EOF@@ -1193,6 +1305,8 @@ write_qnap_wrapper_script() {# Pulse Agent startup script for QNAP# Auto-generated by Pulse installer.+WATCHDOG_LOG="${log_dir}/${AGENT_NAME}-watchdog.log"+wait_for_file() {path="\$1"while [ ! -f "\$path" ]; do@@ -1200,8 +1314,20 @@ wait_for_file() {done}+# The watchdog log lives on the data volume but has no rotation, so cap it.+trim_watchdog_log() {+ [ -f "\$WATCHDOG_LOG" ] || return 0+ _size=\$(wc -c < "\$WATCHDOG_LOG" 2>/dev/null | tr -d ' \t')+ case "\$_size" in ''|*[!0-9]*) return 0 ;; esac+ if [ "\$_size" -gt 5242880 ]; then+ tail -c 1048576 "\$WATCHDOG_LOG" > "\${WATCHDOG_LOG}.tmp" 2>/dev/null && mv "\${WATCHDOG_LOG}.tmp" "\$WATCHDOG_LOG"+ fi+}+wait_for_file "${stored_binary}"+mkdir -p "${log_dir}" 2>/dev/null || true+# Kill any existing pulse-agent processes before refreshing the runtime copy.pkill -x "pulse-agent" 2>/dev/null || truesleep 2@@ -1215,11 +1341,14 @@ RESTART_DELAY=5MAX_RESTART_DELAY=60while true; do- echo "\$(date '+%Y-%m-%d %H:%M:%S') [watchdog] Starting pulse-agent..." >> /var/log/${AGENT_NAME}.log- ${runtime_binary} ${EXEC_ARGS} >> /var/log/${AGENT_NAME}.log 2>&1+ trim_watchdog_log+ echo "\$(date '+%Y-%m-%d %H:%M:%S') [watchdog] Starting pulse-agent (agent log: ${log_dir}/${AGENT_NAME}.log)..." >> "\$WATCHDOG_LOG"+ # The agent writes its own rotating log via --log-file; discard the stdout+ # mirror so nothing accumulates on the RAM-backed root filesystem.+ ${runtime_binary} ${EXEC_ARGS} > /dev/null 2>> "\$WATCHDOG_LOG"EXIT_CODE=\$?- echo "\$(date '+%Y-%m-%d %H:%M:%S') [watchdog] pulse-agent exited with code \$EXIT_CODE, restarting in \${RESTART_DELAY}s..." >> /var/log/${AGENT_NAME}.log+ echo "\$(date '+%Y-%m-%d %H:%M:%S') [watchdog] pulse-agent exited with code \$EXIT_CODE, restarting in \${RESTART_DELAY}s..." >> "\$WATCHDOG_LOG"sleep \$RESTART_DELAYRESTART_DELAY=\$((RESTART_DELAY * 2))@@ -1534,6 +1663,7 @@ build_exec_arg_items() {if [[ -n "$HOSTNAME_OVERRIDE" ]]; then EXEC_ARG_ITEMS+=(--hostname "$HOSTNAME_OVERRIDE"); fiif [[ -n "$REPORT_IP" ]]; then EXEC_ARG_ITEMS+=(--report-ip "$REPORT_IP"); fiif [[ -n "$STATE_DIR" ]]; then EXEC_ARG_ITEMS+=(--state-dir "$STATE_DIR"); fi+ if [[ -n "${AGENT_LOG_FILE:-}" ]]; then EXEC_ARG_ITEMS+=(--log-file "$AGENT_LOG_FILE"); fi# Add disk exclude patterns (use ${arr[@]+"${arr[@]}"} for bash 3.2 compatibility with set -u)for pattern in ${DISK_EXCLUDES[@]+"${DISK_EXCLUDES[@]}"}; doEXEC_ARG_ITEMS+=(--disk-exclude "$pattern")@@ -3060,9 +3190,17 @@ if [[ "$PREFLIGHT_ONLY" == "true" ]]; thenAGENT_STATUS="already_installed"fijson_event "preflight" "$AGENT_STATUS" "Agent status: ${AGENT_STATUS}"-- # Check 3: Pulse URL reachability and agent binary availabilityPREFLIGHT_EXIT="$EXIT_OK"++ # Check 3: Disk headroom for staging and installing the agent binary+ if ensure_agent_disk_headroom "${TMPDIR:-/tmp}" "$INSTALL_DIR"; then+ json_event "preflight" "disk_ok" "Sufficient disk space for agent install"+ else+ json_event "preflight" "disk_low" "Not enough free disk space to stage and install the agent" "$EXIT_PREFLIGHT_FAILED"+ PREFLIGHT_EXIT="$EXIT_PREFLIGHT_FAILED"+ fi++ # Check 4: Pulse URL reachability and agent binary availabilityif [[ -n "$PULSE_URL" ]]; thenCURL_TEST_ARGS=(-sf --connect-timeout 5 -o /dev/null)if [[ "$INSECURE" == "true" ]]; then CURL_TEST_ARGS+=(-k); fi@@ -3130,6 +3268,12 @@ esac# Construct arch param in format expected by download endpoint (e.g., linux-amd64)ARCH_PARAM="${OS}-${ARCH}"+# Fail before downloading if the temp and install filesystems cannot hold the+# staged plus installed binary (mktemp below honours TMPDIR).+if ! ensure_agent_disk_headroom "${TMPDIR:-/tmp}" "$INSTALL_DIR"; then+ fail "Not enough free disk space to install the Pulse agent" "$EXIT_PREFLIGHT_FAILED"+fi+# Create temp file and register for cleanupTMP_BIN=$(mktemp)TMP_FILES+=("$TMP_BIN")@@ -3387,6 +3531,12 @@ if [[ -f /etc/unraid-version ]]; thenlog_info "Installed binary to ${UNRAID_STORED_BINARY} (persistent) and ${RUNTIME_BINARY} (runtime)..."+ # Unraid's /var/log is a small tmpfs and /boot is flash (unsuitable for+ # logs), so use the agent's rotating writer to cap log growth (issue #1617).+ # A subdirectory is required: the rotating writer chmods its log directory.+ UNRAID_LOG_DIR="/var/log/${AGENT_NAME}"+ AGENT_LOG_FILE="${UNRAID_LOG_DIR}/${AGENT_NAME}.log"+# Build command line args (string for wrapper script, array for direct execution)ensure_runtime_token_file "$STATE_DIR"clear_proxmox_state_if_needed@@ -3410,6 +3560,18 @@ if [[ -f /etc/unraid-version ]]; then# Auto-generated by Pulse installer# Includes watchdog loop to restart agent on failure+WATCHDOG_LOG="/var/log/${AGENT_NAME}-watchdog.log"++# The watchdog log has no rotation, so cap it (it lives on a small tmpfs).+trim_watchdog_log() {+ [ -f "\$WATCHDOG_LOG" ] || return 0+ _size=\$(wc -c < "\$WATCHDOG_LOG" 2>/dev/null | tr -d ' \t')+ case "\$_size" in ''|*[!0-9]*) return 0 ;; esac+ if [ "\$_size" -gt 5242880 ]; then+ tail -c 1048576 "\$WATCHDOG_LOG" > "\${WATCHDOG_LOG}.tmp" 2>/dev/null && mv "\${WATCHDOG_LOG}.tmp" "\$WATCHDOG_LOG"+ fi+}+# Kill any existing pulse-agent processespkill -f "^${RUNTIME_BINARY}" 2>/dev/null || truesleep 2@@ -3424,13 +3586,16 @@ RESTART_DELAY=5MAX_RESTART_DELAY=60while true; do- echo "\$(date '+%Y-%m-%d %H:%M:%S') [watchdog] Starting pulse-agent..." >> /var/log/${AGENT_NAME}.log- ${RUNTIME_BINARY} ${EXEC_ARGS} >> /var/log/${AGENT_NAME}.log 2>&1+ trim_watchdog_log+ echo "\$(date '+%Y-%m-%d %H:%M:%S') [watchdog] Starting pulse-agent (agent log: ${AGENT_LOG_FILE})..." >> "\$WATCHDOG_LOG"+ # The agent writes its own rotating log via --log-file; discard the stdout+ # mirror so unrotated output cannot fill the tmpfs-backed /var/log.+ ${RUNTIME_BINARY} ${EXEC_ARGS} > /dev/null 2>> "\$WATCHDOG_LOG"EXIT_CODE=\$?-- echo "\$(date '+%Y-%m-%d %H:%M:%S') [watchdog] pulse-agent exited with code \$EXIT_CODE, restarting in \${RESTART_DELAY}s..." >> /var/log/${AGENT_NAME}.log++ echo "\$(date '+%Y-%m-%d %H:%M:%S') [watchdog] pulse-agent exited with code \$EXIT_CODE, restarting in \${RESTART_DELAY}s..." >> "\$WATCHDOG_LOG"sleep \$RESTART_DELAY-+# Exponential backoff (cap at MAX_RESTART_DELAY)RESTART_DELAY=\$((RESTART_DELAY * 2))if [ \$RESTART_DELAY -gt \$MAX_RESTART_DELAY ]; then@@ -3468,10 +3633,11 @@ EOFbash "${WRAPPER_SCRIPT}" >> "/var/log/${AGENT_NAME}.log" 2>&1 &disown 2>/dev/null || true # Disown if available to prevent SIGHUP- complete_installation_flow "$UNRAID_STORAGE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f /var/log/${AGENT_NAME}.log"+ complete_installation_flow "$UNRAID_STORAGE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f ${AGENT_LOG_FILE}"log_info "The agent will start automatically on boot."log_info "To check status: pgrep -a pulse-agent"- log_info "To view logs: tail -f /var/log/${AGENT_NAME}.log"+ log_info "To view logs: tail -f ${AGENT_LOG_FILE}"+ log_info "Watchdog log: /var/log/${AGENT_NAME}-watchdog.log"exit 0fi@@ -3500,6 +3666,11 @@ if [[ -f /sbin/getcfg ]] || [[ -f /etc/config/qpkg.conf ]]; thenlog_info "Installed binary to ${QNAP_STORED_BINARY} (persistent) and ${RUNTIME_BINARY} (runtime)..."+ # Log to the data volume with the agent's rotating writer; the RAM-backed+ # root (/var/log) must not accumulate agent output (issue #1617).+ QNAP_LOG_DIR="${STATE_DIR}/logs"+ AGENT_LOG_FILE="${QNAP_LOG_DIR}/${AGENT_NAME}.log"+ensure_runtime_token_file "$STATE_DIR"clear_proxmox_state_if_neededbuild_exec_args@@ -3509,7 +3680,7 @@ if [[ -f /sbin/getcfg ]] || [[ -f /etc/config/qpkg.conf ]]; thenpkill -f "start-pulse-agent.sh" 2>/dev/null || truesleep 2- write_qnap_wrapper_script "$WRAPPER_SCRIPT" "$RUNTIME_BINARY" "$QNAP_STORED_BINARY"+ write_qnap_wrapper_script "$WRAPPER_SCRIPT" "$RUNTIME_BINARY" "$QNAP_STORED_BINARY" "$QNAP_LOG_DIR"AUTORUN_CONFIGURED=falseif [[ -x /etc/init.d/init_disk.sh ]]; then@@ -3534,7 +3705,7 @@ if [[ -f /sbin/getcfg ]] || [[ -f /etc/config/qpkg.conf ]]; thensh "${WRAPPER_SCRIPT}" >> "/var/log/${AGENT_NAME}.log" 2>&1 &disown 2>/dev/null || true- complete_installation_flow "$STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f /var/log/${AGENT_NAME}.log"+ complete_installation_flow "$STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f ${AGENT_LOG_FILE}"log_info "Persistent state: $STATE_DIR"if [[ "$AUTORUN_CONFIGURED" == true ]]; thenlog_info "The agent will start automatically after the QNAP data volume becomes available."@@ -3542,7 +3713,8 @@ if [[ -f /sbin/getcfg ]] || [[ -f /etc/config/qpkg.conf ]]; thenlog_info " in QNAP Control Panel > Hardware > General."filog_info "To check status: pgrep -a pulse-agent"- log_info "To view logs: tail -f /var/log/${AGENT_NAME}.log"+ log_info "To view logs: tail -f ${AGENT_LOG_FILE}"+ log_info "Watchdog log: ${QNAP_LOG_DIR}/${AGENT_NAME}-watchdog.log"exit 0fidiff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.goindex 0b48daff23..50e0038830 100644--- a/scripts/installtests/install_sh_test.go+++ b/scripts/installtests/install_sh_test.go@@ -1459,9 +1459,9 @@ func TestInstallSHUsesCanonicalQNAPBootstrapRenderer(t *testing.T) {`write_qnap_wrapper_script() {`,`append_qnap_autorun_block() {`,`select_platform_state_dir "${QNAP_VOL}/.pulse-agent"`,- `write_qnap_wrapper_script "$WRAPPER_SCRIPT" "$RUNTIME_BINARY" "$QNAP_STORED_BINARY"`,+ `write_qnap_wrapper_script "$WRAPPER_SCRIPT" "$RUNTIME_BINARY" "$QNAP_STORED_BINARY" "$QNAP_LOG_DIR"`,`append_qnap_autorun_block "$AUTORUN_PATH" "$WRAPPER_SCRIPT" "$STATE_DIR"`,- `complete_installation_flow "$STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f /var/log/${AGENT_NAME}.log"`,+ `complete_installation_flow "$STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f ${AGENT_LOG_FILE}"`,}for _, needle := range required {if !strings.Contains(script, needle) {@@ -1490,6 +1490,176 @@ func TestInstallSHUsesQNAPStateForUninstallRecovery(t *testing.T) {}}+func TestInstallSHAgentDiskHeadroomRejectsSharedLowSpaceFilesystem(t *testing.T) {+ script := `+ set -euo pipefail+ log_error() { :; }+ log_info() { :; }+ log_warn() { :; }+ INSTALL_DIR="/usr/local/bin"+ AGENT_MIN_TEMP_FREE_BYTES=$((100 * 1024))+ AGENT_MIN_INSTALL_FREE_BYTES=$((80 * 1024))+` + extractInstallShellFunction(t, "bytes_to_human") + `+` + extractInstallShellFunction(t, "nearest_existing_dir") + `+` + extractInstallShellFunction(t, "get_available_bytes_for_path") + `+` + extractInstallShellFunction(t, "get_filesystem_device_for_path") + `+` + extractInstallShellFunction(t, "ensure_agent_disk_headroom") + `+ df() {+ if [[ "$1" == "-Pk" ]]; then+ printf 'Filesystem 1024-blocks Used Available Capacity Mounted on\n'+ printf '/dev/shared 1000 0 150 0%% /\n'+ return 0+ fi+ command df "$@"+ }+ if ensure_agent_disk_headroom /tmp /usr/local/bin; then+ echo "ensure_agent_disk_headroom unexpectedly passed on a shared full filesystem" >&2+ exit 1+ fi+ `++ out, err := exec.Command("bash", "-c", script).CombinedOutput()+ if err != nil {+ t.Fatalf("bash: %v\n%s", err, out)+ }+}++func TestInstallSHAgentDiskHeadroomAcceptsSeparateFilesystems(t *testing.T) {+ script := `+ set -euo pipefail+ log_error() { :; }+ log_info() { :; }+ log_warn() { :; }+ INSTALL_DIR="/usr/local/bin"+ AGENT_MIN_TEMP_FREE_BYTES=$((100 * 1024))+ AGENT_MIN_INSTALL_FREE_BYTES=$((80 * 1024))+` + extractInstallShellFunction(t, "bytes_to_human") + `+` + extractInstallShellFunction(t, "nearest_existing_dir") + `+` + extractInstallShellFunction(t, "get_available_bytes_for_path") + `+` + extractInstallShellFunction(t, "get_filesystem_device_for_path") + `+` + extractInstallShellFunction(t, "ensure_agent_disk_headroom") + `+ df() {+ if [[ "$1" == "-Pk" ]]; then+ case "$2" in+ /tmp)+ printf 'Filesystem 1024-blocks Used Available Capacity Mounted on\n'+ printf '/dev/tmp 1000 0 120 0%% /tmp\n'+ return 0+ ;;+ *)+ printf 'Filesystem 1024-blocks Used Available Capacity Mounted on\n'+ printf '/dev/root 1000 0 90 0%% /\n'+ return 0+ ;;+ esac+ fi+ command df "$@"+ }+ ensure_agent_disk_headroom /tmp /usr/local/bin+ `++ out, err := exec.Command("bash", "-c", script).CombinedOutput()+ if err != nil {+ t.Fatalf("bash: %v\n%s", err, out)+ }+}++func TestInstallSHAgentDiskHeadroomResolvesMissingDirectories(t *testing.T) {+ script := `+ set -euo pipefail+ log_error() { :; }+ log_info() { :; }+ log_warn() { :; }+ INSTALL_DIR="/usr/local/bin"+ AGENT_MIN_TEMP_FREE_BYTES=$((100 * 1024))+ AGENT_MIN_INSTALL_FREE_BYTES=$((80 * 1024))+` + extractInstallShellFunction(t, "nearest_existing_dir") + `+ resolved=$(nearest_existing_dir /definitely/not/a/real/path/anywhere)+ if [[ "$resolved" != "/" ]]; then+ echo "nearest_existing_dir resolved to $resolved, want /" >&2+ exit 1+ fi+ resolved=$(nearest_existing_dir /tmp)+ if [[ "$resolved" != "/tmp" ]]; then+ echo "nearest_existing_dir resolved to $resolved, want /tmp" >&2+ exit 1+ fi+ `++ out, err := exec.Command("bash", "-c", script).CombinedOutput()+ if err != nil {+ t.Fatalf("bash: %v\n%s", err, out)+ }+}++// TestInstallSHChecksDiskHeadroomBeforeDownload pins the ENOSPC preflight from+// issue #1617: the installer must verify temp and install-dir headroom before+// the agent binary download stages anything, and the --preflight-only mode must+// report the same check.+func TestInstallSHChecksDiskHeadroomBeforeDownload(t *testing.T) {+ content, err := os.ReadFile(repoFile("scripts", "install.sh"))+ if err != nil {+ t.Fatalf("read install.sh: %v", err)+ }++ script := string(content)+ headroomCall := `if ! ensure_agent_disk_headroom "${TMPDIR:-/tmp}" "$INSTALL_DIR"; then`+ stagingCall := `TMP_BIN=$(mktemp)`++ headroomPos := strings.Index(script, headroomCall)+ if headroomPos < 0 {+ t.Fatalf("install.sh does not gate the download on ensure_agent_disk_headroom")+ }+ stagingPos := strings.Index(script, stagingCall)+ if stagingPos < 0 {+ t.Fatalf("install.sh no longer stages the download via mktemp; update this test")+ }+ if headroomPos > stagingPos {+ t.Fatalf("disk headroom check happens after the download staging mktemp")+ }++ for _, needle := range []string{+ `json_event "preflight" "disk_ok" "Sufficient disk space for agent install"`,+ `json_event "preflight" "disk_low"`,+ } {+ if !strings.Contains(script, needle) {+ t.Fatalf("install.sh preflight-only mode missing disk headroom reporting: %s", needle)+ }+ }+}++// TestInstallSHWatchdogPathsUseRotatingAgentLog pins the logging half of issue+// #1617: the QNAP and Unraid watchdog loops must not shell-append agent stdout+// to an unrotated file on the RAM-backed root; the agent's own rotating writer+// (--log-file) owns the agent log instead.+func TestInstallSHWatchdogPathsUseRotatingAgentLog(t *testing.T) {+ content, err := os.ReadFile(repoFile("scripts", "install.sh"))+ if err != nil {+ t.Fatalf("read install.sh: %v", err)+ }++ script := string(content)+ required := []string{+ `if [[ -n "${AGENT_LOG_FILE:-}" ]]; then EXEC_ARG_ITEMS+=(--log-file "$AGENT_LOG_FILE"); fi`,+ `QNAP_LOG_DIR="${STATE_DIR}/logs"`,+ `AGENT_LOG_FILE="${QNAP_LOG_DIR}/${AGENT_NAME}.log"`,+ `UNRAID_LOG_DIR="/var/log/${AGENT_NAME}"`,+ `AGENT_LOG_FILE="${UNRAID_LOG_DIR}/${AGENT_NAME}.log"`,+ }+ for _, needle := range required {+ if !strings.Contains(script, needle) {+ t.Fatalf("install.sh missing rotating agent log wiring: %s", needle)+ }+ }++ if got := strings.Count(script, `${EXEC_ARGS} > /dev/null 2>> "\$WATCHDOG_LOG"`); got != 2 {+ t.Fatalf("expected both watchdog loops (QNAP, Unraid) to discard the stdout mirror and capture stderr in the watchdog log, found %d", got)+ }+ if strings.Contains(script, `${EXEC_ARGS} >> /var/log/${AGENT_NAME}.log`) {+ t.Fatalf("a watchdog loop still shell-appends agent output to the unrotated /var/log/${AGENT_NAME}.log")+ }+}+func TestInstallSHUsesSharedServiceRenderers(t *testing.T) {content, err := os.ReadFile(repoFile("scripts", "install.sh"))if err != nil {@@ -1657,8 +1827,8 @@ func TestInstallSHUsesCanonicalCompletionHelper(t *testing.T) {`json_event "complete" "updated_unhealthy" "Agent updated but not responding"`,`json_event "complete" "installed_unhealthy" "Agent installed but not responding"`,`complete_installation_flow "$STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent restarted with new configuration." "tail -f $LOG_FILE"`,- `complete_installation_flow "$UNRAID_STORAGE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f /var/log/${AGENT_NAME}.log"`,- `complete_installation_flow "$STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f /var/log/${AGENT_NAME}.log"`,+ `complete_installation_flow "$UNRAID_STORAGE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f ${AGENT_LOG_FILE}"`,+ `complete_installation_flow "$STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." "tail -f ${AGENT_LOG_FILE}"`,`complete_installation_flow "$TRUENAS_STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent is running." ""`,`complete_installation_flow "$STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent restarted with new configuration." "tail -f /var/log/messages"`,`complete_installation_flow "$STATE_DIR" "Installation complete! Agent is running." "Upgrade complete! Agent restarted with new configuration." "journalctl -u ${AGENT_NAME} --no-pager -n 20"`,