Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

feat(installer): add QNAP QTS/QuTS hero agent support (#1253)

rcourtman82988524834d
diff --git a/scripts/install.sh b/scripts/install.sh
index 4ccc2be739..5f9b671a01 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#
# Pulse Unified Agent Installer
-# Supports: Linux (systemd, OpenRC, SysV init), macOS (launchd), FreeBSD (rc.d), Synology DSM (6.x/7+), Unraid
+# Supports: Linux (systemd, OpenRC, SysV init), macOS (launchd), FreeBSD (rc.d), Synology DSM (6.x/7+), Unraid, QNAP QTS/QuTS
#
# Usage:
# curl -fsSL http://pulse/install.sh | bash -s -- --url http://pulse --token <token> [options]
@@ -638,6 +638,43 @@ if [[ "$UNINSTALL" == "true" ]]; then
rm -rf "$TRUENAS_STATE_DIR"
fi
+ # QNAP QTS/QuTS hero
+ if [[ -f /sbin/getcfg ]] || [[ -f /etc/config/qpkg.conf ]]; then
+ log_info "Removing QNAP installation..."
+ pkill -f "pulse-agent" 2>/dev/null || true
+ sleep 1
+
+ # Remove autorun.sh entry
+ if [[ -x /etc/init.d/init_disk.sh ]]; then
+ if /etc/init.d/init_disk.sh mount_flash_config 2>/dev/null && [[ -d /tmp/nasconfig_tmp ]]; then
+ AUTORUN_PATH="/tmp/nasconfig_tmp/autorun.sh"
+ if [[ -f "$AUTORUN_PATH" ]]; then
+ sed -i '/# Pulse Agent/,/^$/d' "$AUTORUN_PATH" 2>/dev/null || true
+ sed -i '/pulse-agent/d' "$AUTORUN_PATH" 2>/dev/null || true
+ fi
+ fi
+ /etc/init.d/init_disk.sh umount_flash_config 2>/dev/null || true
+ fi
+
+ # Remove persistent state directory
+ # Try getcfg first (same detection as install), then hardcoded fallbacks
+ QNAP_UNINSTALL_VOL=""
+ if command -v getcfg >/dev/null 2>&1; then
+ QNAP_UNINSTALL_VOL=$(getcfg SHARE_DEF defVolMP -f /etc/config/def_share.info 2>/dev/null || echo "")
+ fi
+ if [[ -n "$QNAP_UNINSTALL_VOL" ]] && [[ -d "${QNAP_UNINSTALL_VOL}/.pulse-agent" ]]; then
+ rm -rf "${QNAP_UNINSTALL_VOL}/.pulse-agent"
+ fi
+ # Also clean hardcoded fallback locations
+ for vol in /share/CACHEDEV1_DATA /share/CACHEDEV2_DATA /share/MD0_DATA; do
+ rm -rf "${vol}/.pulse-agent" 2>/dev/null || true
+ done
+
+ rm -f "${INSTALL_DIR}/${BINARY_NAME}"
+ rm -f "/etc/init.d/${AGENT_NAME}"
+ rm -f "/var/run/${AGENT_NAME}.pid"
+ fi
+
# OpenRC (Alpine, Gentoo, Artix, etc.)
if command -v rc-service >/dev/null 2>&1; then
rc-service "${AGENT_NAME}" stop 2>/dev/null || true
@@ -1178,6 +1215,156 @@ EOF
exit 0
fi
+# 3b. QNAP QTS/QuTS hero (ephemeral /etc/init.d — wiped on every reboot)
+# Detect via /sbin/getcfg (QNAP config tool) or /etc/config/qpkg.conf.
+# Binary + wrapper stored on persistent volume; autorun.sh used for boot persistence.
+if [[ -f /sbin/getcfg ]] || [[ -f /etc/config/qpkg.conf ]]; then
+ log_info "Detected QNAP QTS/QuTS hero system..."
+
+ # Find the default data volume (typically /share/CACHEDEV1_DATA)
+ QNAP_VOL=""
+ if command -v getcfg >/dev/null 2>&1; then
+ QNAP_VOL=$(getcfg SHARE_DEF defVolMP -f /etc/config/def_share.info 2>/dev/null || echo "")
+ fi
+ if [[ -z "$QNAP_VOL" ]]; then
+ # Fallback: probe common data volume mount points
+ for candidate in /share/CACHEDEV1_DATA /share/CACHEDEV2_DATA /share/MD0_DATA; do
+ if [[ -d "$candidate" ]] && [[ -w "$candidate" ]]; then
+ QNAP_VOL="$candidate"
+ break
+ fi
+ done
+ fi
+ if [[ -z "$QNAP_VOL" ]]; then
+ fail "Could not find a writable QNAP data volume. Is a storage volume configured?"
+ fi
+
+ QNAP_STATE_DIR="${QNAP_VOL}/.pulse-agent"
+ QNAP_STORED_BINARY="${QNAP_STATE_DIR}/${BINARY_NAME}"
+ RUNTIME_BINARY="${INSTALL_DIR}/${BINARY_NAME}"
+
+ mkdir -p "$QNAP_STATE_DIR"
+
+ # Copy binary to persistent storage and keep in /usr/local/bin for runtime
+ cp "${RUNTIME_BINARY}" "$QNAP_STORED_BINARY"
+ chmod +x "${RUNTIME_BINARY}"
+
+ log_info "Installed binary to ${QNAP_STORED_BINARY} (persistent) and ${RUNTIME_BINARY} (runtime)..."
+
+ # Build command line args
+ build_exec_args
+ build_exec_args_array
+
+ # Kill any existing pulse agents
+ log_info "Stopping any existing pulse agents..."
+ pkill -f "^${RUNTIME_BINARY}" 2>/dev/null || true
+ sleep 2
+
+ # Create a wrapper script (stored persistently)
+ WRAPPER_SCRIPT="${QNAP_STATE_DIR}/start-pulse-agent.sh"
+ cat > "$WRAPPER_SCRIPT" <<EOF
+#!/bin/sh
+# Pulse Agent startup script for QNAP
+# Auto-generated by Pulse installer
+
+# Kill any existing pulse-agent processes
+pkill -f "^${RUNTIME_BINARY}" 2>/dev/null || true
+sleep 2
+
+# Copy binary from persistent storage to /usr/local/bin (RAM disk, wiped on reboot)
+cp "${QNAP_STORED_BINARY}" "${RUNTIME_BINARY}"
+chmod +x "${RUNTIME_BINARY}"${SHELL_EXPORT_LINES}
+
+# Watchdog loop: restart agent if it exits
+RESTART_DELAY=5
+MAX_RESTART_DELAY=60
+
+while 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
+ 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
+ sleep \$RESTART_DELAY
+
+ RESTART_DELAY=\$((RESTART_DELAY * 2))
+ if [ \$RESTART_DELAY -gt \$MAX_RESTART_DELAY ]; then
+ RESTART_DELAY=\$MAX_RESTART_DELAY
+ fi
+done
+EOF
+ chmod +x "$WRAPPER_SCRIPT"
+
+ # Set up autorun.sh for boot persistence
+ # QNAP's flash config partition must be mounted to access autorun.sh
+ AUTORUN_CONFIGURED=false
+ AUTORUN_MARKER="# Pulse Agent"
+
+ # Try the init_disk.sh helper first (works across most QNAP models)
+ if [[ -x /etc/init.d/init_disk.sh ]]; then
+ FLASH_MOUNTED=false
+ if /etc/init.d/init_disk.sh mount_flash_config 2>/dev/null && [[ -d /tmp/nasconfig_tmp ]]; then
+ FLASH_MOUNTED=true
+ fi
+
+ if [[ "$FLASH_MOUNTED" == true ]]; then
+ # Run writes in a subshell; use `if` to capture exit code without
+ # triggering set -e abort, guaranteeing umount always runs after.
+ if (
+ AUTORUN_PATH="/tmp/nasconfig_tmp/autorun.sh"
+
+ # Remove old pulse entries if any
+ if [[ -f "$AUTORUN_PATH" ]]; then
+ sed -i "/${AUTORUN_MARKER}/,/^$/d" "$AUTORUN_PATH" 2>/dev/null || true
+ sed -i '/pulse-agent/d' "$AUTORUN_PATH" 2>/dev/null || true
+ else
+ echo "#!/bin/sh" > "$AUTORUN_PATH"
+ fi
+
+ cat >> "$AUTORUN_PATH" <<AUTORUNEOF
+
+${AUTORUN_MARKER}
+${WRAPPER_SCRIPT} >> /var/log/${AGENT_NAME}.log 2>&1 &
+
+AUTORUNEOF
+ chmod +x "$AUTORUN_PATH"
+ ); then
+ /etc/init.d/init_disk.sh umount_flash_config 2>/dev/null || true
+ AUTORUN_CONFIGURED=true
+ log_info "Configured autorun.sh for boot persistence."
+ else
+ /etc/init.d/init_disk.sh umount_flash_config 2>/dev/null || true
+ log_warn "Failed to write autorun.sh entry."
+ fi
+ else
+ # Mount failed or /tmp/nasconfig_tmp not created — ensure we unmount just in case
+ /etc/init.d/init_disk.sh umount_flash_config 2>/dev/null || true
+ fi
+ fi
+
+ if [[ "$AUTORUN_CONFIGURED" != true ]]; then
+ log_warn "Could not configure autorun.sh automatically."
+ log_warn "To persist across reboots, add the following to your QNAP autorun.sh:"
+ log_warn " ${WRAPPER_SCRIPT} >> /var/log/${AGENT_NAME}.log 2>&1 &"
+ log_warn "See: https://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup"
+ fi
+
+ # Start the agent now
+ log_info "Starting agent with watchdog..."
+ bash "${WRAPPER_SCRIPT}" >> "/var/log/${AGENT_NAME}.log" 2>&1 &
+ disown 2>/dev/null || true
+
+ log_info "Installation complete!"
+ if [[ "$AUTORUN_CONFIGURED" == true ]]; then
+ log_info "The agent will start automatically on boot."
+ log_info "IMPORTANT: Ensure 'Run user defined processes (autorun.sh)' is enabled"
+ log_info " in QNAP Control Panel > Hardware > General."
+ fi
+ log_info "To check status: pgrep -a pulse-agent"
+ log_info "To view logs: tail -f /var/log/${AGENT_NAME}.log"
+ exit 0
+fi
+
# 4. TrueNAS SCALE/CORE (immutable root, uses systemd on SCALE and rc.d on CORE)
# TrueNAS can wipe service registration files on upgrades, so we store the service
# in /data and create an Init/Shutdown task to recreate the symlink on boot.