From a7d6b85f0e5064383d9d80921e6332e0954175b7 Mon Sep 17 00:00:00 2001 From: pgianotto Date: Wed, 9 Sep 2026 07:55:21 -0400 Subject: [PATCH 1/2] Make fpp_uninstall.sh actually clean up plugin artifacts The previous script only printed messages. Per the FPP plugin guidelines, uninstall must reverse every side effect created outside the plugin directory and be safe to run repeatedly. It now: - stops the mqtt_listener.py process started in postStart.sh (FPP does not run preStop.sh on uninstall, so it would otherwise keep running) - removes the SQLite database plus its -journal/-wal/-shm sidecars and the plugin..db.backup-* copies left in config/ by the restore and empty-database actions - removes the plugin log file (both the current name and the plugin-.log name) - removes the plugin settings file All removals use "rm -f" or are guarded, so re-running is safe. python3-paho-mqtt is left installed as a shared dependency. Refs #11 Co-Authored-By: Claude Sonnet 5 --- scripts/fpp_uninstall.sh | 42 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/scripts/fpp_uninstall.sh b/scripts/fpp_uninstall.sh index cd7223f..4e613d9 100755 --- a/scripts/fpp_uninstall.sh +++ b/scripts/fpp_uninstall.sh @@ -1,10 +1,44 @@ -#!/bin/bash +#!/bin/sh -# fpp-pluginAdvancedStats uninstall script +# fpp-plugin-AdvancedStats uninstall script +# +# Reverses every side effect this plugin creates outside its own plugin +# directory. Must be safe to run more than once (all removals are guarded +# or use "rm -f"). + +PLUGIN="fpp-plugin-AdvancedStats" +CONFIGDIR="/home/fpp/media/config" +LOGDIR="/home/fpp/media/logs" echo "Uninstalling Advanced Stats Plugin..." +# 1. Stop the MQTT listener started by scripts/postStart.sh. +# FPP does not run preStop.sh on uninstall, so without this the process +# keeps running (against a since-deleted script) until the next fppd stop. +if pgrep -f "mqtt_listener.py" >/dev/null 2>&1; then + echo "Stopping MQTT listener..." + pkill -f "mqtt_listener.py" 2>/dev/null || true + sleep 1 + pkill -9 -f "mqtt_listener.py" 2>/dev/null || true +fi -echo "" -echo "Advanced Stats Plugin uninstalled successfully" +# 2. SQLite database, its journal/WAL sidecars, and any safety-backup copies +# left in config/ by the restore and empty-database actions. +rm -f "${CONFIGDIR}/plugin.${PLUGIN}.db" \ + "${CONFIGDIR}/plugin.${PLUGIN}.db-journal" \ + "${CONFIGDIR}/plugin.${PLUGIN}.db-wal" \ + "${CONFIGDIR}/plugin.${PLUGIN}.db-shm" +rm -f "${CONFIGDIR}/plugin.${PLUGIN}.db.backup-"* + +# 3. Plugin log file. Both the current name and the guideline-compliant +# plugin-.log name are removed so nothing is orphaned. +rm -f "${LOGDIR}/${PLUGIN}.log" \ + "${LOGDIR}/plugin-${PLUGIN}.log" +# 4. Plugin settings file. +rm -f "${CONFIGDIR}/plugin.${PLUGIN}" + +# Note: python3-paho-mqtt (installed by fpp_install.sh) is a shared system +# dependency and is intentionally left in place. + +echo "Advanced Stats Plugin uninstalled successfully" From c2aaf751770ba8377e913cfc0efc2a38b99bdf09 Mon Sep 17 00:00:00 2001 From: pgianotto Date: Wed, 9 Sep 2026 08:05:04 -0400 Subject: [PATCH 2/2] Match the listener by plugin path, not bare mqtt_listener.py pkill/pgrep -f "mqtt_listener.py" could in principle match an unrelated process of the same name. Scope the pattern to this plugin: - postStart.sh: use the absolute launch path ($MQTT_LISTENER) - preStop.sh / fpp_uninstall.sh: match "fpp-plugin-AdvancedStats/mqtt_listener.py" This does not touch FPP's built-in MQTT (compiled into fppd) or the mosquitto broker service - neither has mqtt_listener.py in its command line. Refs #11 Co-Authored-By: Claude Sonnet 5 --- scripts/fpp_uninstall.sh | 9 ++++++--- scripts/postStart.sh | 4 ++-- scripts/preStop.sh | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/fpp_uninstall.sh b/scripts/fpp_uninstall.sh index 4e613d9..9e237bf 100755 --- a/scripts/fpp_uninstall.sh +++ b/scripts/fpp_uninstall.sh @@ -15,11 +15,14 @@ echo "Uninstalling Advanced Stats Plugin..." # 1. Stop the MQTT listener started by scripts/postStart.sh. # FPP does not run preStop.sh on uninstall, so without this the process # keeps running (against a since-deleted script) until the next fppd stop. -if pgrep -f "mqtt_listener.py" >/dev/null 2>&1; then +# The pattern includes the plugin directory so it cannot match an +# unrelated process that happens to be named mqtt_listener.py. +LISTENER_MATCH="${PLUGIN}/mqtt_listener.py" +if pgrep -f "${LISTENER_MATCH}" >/dev/null 2>&1; then echo "Stopping MQTT listener..." - pkill -f "mqtt_listener.py" 2>/dev/null || true + pkill -f "${LISTENER_MATCH}" 2>/dev/null || true sleep 1 - pkill -9 -f "mqtt_listener.py" 2>/dev/null || true + pkill -9 -f "${LISTENER_MATCH}" 2>/dev/null || true fi # 2. SQLite database, its journal/WAL sidecars, and any safety-backup copies diff --git a/scripts/postStart.sh b/scripts/postStart.sh index da0441c..3caeb80 100755 --- a/scripts/postStart.sh +++ b/scripts/postStart.sh @@ -47,7 +47,7 @@ sys.exit(0 if rc == 0 else 1)' "$mqtt_host" "$mqtt_port" 2>/dev/null; then } # Check if MQTT listener is already running -if pgrep -f "mqtt_listener.py" > /dev/null; then +if pgrep -f "$MQTT_LISTENER" > /dev/null; then echo "MQTT listener already running" >> "$LOG_FILE" else # Make sure the script is executable @@ -59,7 +59,7 @@ else trap '' HUP wait_for_broker # Re-check: another postStart may have won the race while we waited - if pgrep -f "mqtt_listener.py" > /dev/null; then + if pgrep -f "$MQTT_LISTENER" > /dev/null; then echo "MQTT listener already running - not starting a second one" exit 0 fi diff --git a/scripts/preStop.sh b/scripts/preStop.sh index 6fdd824..9631a19 100755 --- a/scripts/preStop.sh +++ b/scripts/preStop.sh @@ -9,7 +9,7 @@ LOG_FILE="/home/fpp/media/logs/fpp-plugin-AdvancedStats.log" echo "Stopping Advanced Stats MQTT listener..." >> "$LOG_FILE" # Find and kill the MQTT listener process -pkill -f "mqtt_listener.py" +pkill -f "fpp-plugin-AdvancedStats/mqtt_listener.py" if [ $? -eq 0 ]; then echo "MQTT listener stopped successfully" >> "$LOG_FILE"