Make daemon stop behavior configurable via signal_ups_on_stop

Off (default): SIGKILL the daemon on addon stop so the UPS keeps power
on. On: SIGTERM it (native behavior) so it saves the RTC and tells the
UPS to cut power. Add translations so the option is documented in the
HA config UI, and document the difference in the README.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
vaku
2026-07-19 01:51:50 +03:00
parent fac31b4d3d
commit ac8a4b88f0
4 changed files with 62 additions and 14 deletions

View File

@@ -32,12 +32,19 @@ LIFEPO4WERED_FAKE=1 MQTT_HOST=... python3 hassio-addon-lifepo4wered/lifepo4wered
## Stopping the addon vs. shutting down ## Stopping the addon vs. shutting down
Stopping the addon does **not** power off the Pi: the daemon is killed The `signal_ups_on_stop` option controls what happens to the daemon when
without notifying the UPS, so power stays on (`run.sh` traps the stop the addon is stopped:
signal — the daemon would otherwise report "system shutting down" and the
UPS would cut power seconds later). While the addon is stopped, UPS-side - **Off (default)** — the daemon is killed (SIGKILL) without notifying the
features (button shutdown, low-battery clean shutdown, boot watchdog UPS, so power stays on. Addon stops, restarts and updates are safe. The
handshake) are inactive until it starts again. system clock is not saved to the UPS RTC on stop (it still is on
UPS-commanded shutdowns), and while the addon is stopped, UPS-side
features (button shutdown, low-battery clean shutdown) are inactive.
- **On** — the daemon is terminated gracefully (SIGTERM), the native
LiFePO4wered behavior: it saves the clock to the UPS RTC and reports
"system shutting down" (`PI_RUNNING = 0`), so the UPS **cuts power to
the Pi a few seconds after the addon stops**. Only use this if you stop
the addon exclusively as part of powering the system down.
When the UPS itself commands a shutdown (button press, low battery, When the UPS itself commands a shutdown (button press, low battery,
`AUTO_SHDN_TIME` after power loss), the addon performs a clean host `AUTO_SHDN_TIME` after power loss), the addon performs a clean host

View File

@@ -1,6 +1,6 @@
{ {
"name": "LiFePO4wered Addon", "name": "LiFePO4wered Addon",
"version": "0.1.4", "version": "0.1.5",
"init": false, "init": false,
"hassio_api": true, "hassio_api": true,
"hassio_role": "admin", "hassio_role": "admin",
@@ -11,10 +11,12 @@
"boot": "auto", "boot": "auto",
"services": ["mqtt:want"], "services": ["mqtt:want"],
"options": { "options": {
"poll_interval": 30 "poll_interval": 30,
"signal_ups_on_stop": false
}, },
"schema": { "schema": {
"poll_interval": "int(5,3600)", "poll_interval": "int(5,3600)",
"signal_ups_on_stop": "bool",
"mqtt_host": "str?", "mqtt_host": "str?",
"mqtt_port": "port?", "mqtt_port": "port?",
"mqtt_user": "str?", "mqtt_user": "str?",

View File

@@ -47,12 +47,23 @@ bashio::log.info "Starting lifepo4wered-daemon"
lifepo4wered-daemon -f & lifepo4wered-daemon -f &
DAEMON_PID=$! DAEMON_PID=$!
# Stopping the addon must not power off the Pi: the daemon interprets # The daemon interprets SIGTERM as "system is shutting down" and tells
# SIGTERM as "system is shutting down" and tells the UPS to cut power # the UPS to cut power (PI_RUNNING=0). By default we SIGKILL it instead
# (PI_RUNNING=0). SIGKILL it so it cannot signal the UPS; it will pick # so stopping the addon leaves the Pi powered; signal_ups_on_stop=true
# up again when the addon restarts. # restores the daemon's native behavior (UPS cuts power after the stop).
trap 'bashio::log.info "Addon stopping; daemon killed without signaling UPS"; \ on_stop() {
kill -9 "$DAEMON_PID" 2>/dev/null; exit 0' TERM INT if bashio::config.true 'signal_ups_on_stop'; then
bashio::log.warning \
"Addon stopping; signaling UPS - power will be cut in seconds"
kill -TERM "$DAEMON_PID" 2>/dev/null
wait "$DAEMON_PID"
else
bashio::log.info "Addon stopping; daemon killed without signaling UPS"
kill -9 "$DAEMON_PID" 2>/dev/null
fi
exit 0
}
trap on_stop TERM INT
wait "$DAEMON_PID" wait "$DAEMON_PID"

View File

@@ -0,0 +1,28 @@
configuration:
poll_interval:
name: Poll interval
description: >-
How often (in seconds) UPS registers are read and published to MQTT.
signal_ups_on_stop:
name: Signal UPS on addon stop
description: >-
Off (default): stopping the addon kills the daemon silently and the
UPS keeps powering the Pi; use this so addon restarts and updates are
safe. On: stopping the addon terminates the daemon gracefully, which
saves the clock to the UPS RTC but tells the UPS the system is
shutting down — the UPS WILL CUT POWER to the Pi a few seconds after
the addon stops.
mqtt_host:
name: MQTT host
description: >-
Optional MQTT broker override. Leave empty to auto-detect the broker
provided by the Mosquitto addon.
mqtt_port:
name: MQTT port
description: Optional broker port override (default 1883).
mqtt_user:
name: MQTT username
description: Optional broker username override.
mqtt_password:
name: MQTT password
description: Optional broker password override.