diff --git a/README.md b/README.md index 33cf3f3..836c92a 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,20 @@ LIFEPO4WERED_FAKE=1 MQTT_HOST=... python3 hassio-addon-lifepo4wered/lifepo4wered `LIFEPO4WERED_FAKE=1` replaces the CLI with embedded sample data. +## Stopping the addon vs. shutting down + +Stopping the addon does **not** power off the Pi: the daemon is killed +without notifying the UPS, so power stays on (`run.sh` traps the stop +signal — the daemon would otherwise report "system shutting down" and the +UPS would cut power seconds later). While the addon is stopped, UPS-side +features (button shutdown, low-battery clean shutdown, boot watchdog +handshake) are inactive until it starts again. + +When the UPS itself commands a shutdown (button press, low battery, +`AUTO_SHDN_TIME` after power loss), the addon performs a clean host +shutdown through the Supervisor, and the UPS cuts power once shutdown +completes. + ## Setup notes diff --git a/hassio-addon-lifepo4wered/config.json b/hassio-addon-lifepo4wered/config.json index f1a646e..8a1d259 100644 --- a/hassio-addon-lifepo4wered/config.json +++ b/hassio-addon-lifepo4wered/config.json @@ -1,7 +1,9 @@ { "name": "LiFePO4wered Addon", - "version": "0.1.3", + "version": "0.1.4", "init": false, + "hassio_api": true, + "hassio_role": "admin", "slug": "lifepo4wered", "description": "Add-on with service and MQTT monitor for LiFePO4wered/Pi+ UPS", "url": "https://github.com/vakius/hassio-addon-lifepo4wered/tree/master/hassio-addon-lifepo4wered", diff --git a/hassio-addon-lifepo4wered/run.sh b/hassio-addon-lifepo4wered/run.sh index 03577f8..a826a45 100644 --- a/hassio-addon-lifepo4wered/run.sh +++ b/hassio-addon-lifepo4wered/run.sh @@ -44,4 +44,27 @@ setup_mqtt_env() { ) & bashio::log.info "Starting lifepo4wered-daemon" -exec lifepo4wered-daemon -f +lifepo4wered-daemon -f & +DAEMON_PID=$! + +# Stopping the addon must not power off the Pi: the daemon interprets +# SIGTERM as "system is shutting down" and tells the UPS to cut power +# (PI_RUNNING=0). SIGKILL it so it cannot signal the UPS; it will pick +# up again when the addon restarts. +trap 'bashio::log.info "Addon stopping; daemon killed without signaling UPS"; \ + kill -9 "$DAEMON_PID" 2>/dev/null; exit 0' TERM INT + +wait "$DAEMON_PID" + +# The daemon exited on its own: either the UPS commanded a shutdown +# (button press, low battery, auto shutdown after power loss) or the +# daemon crashed. Its own shutdown trigger (init 0) is useless inside +# a container, so perform a clean host shutdown via the Supervisor. +if [ "$(lifepo4wered-cli get PI_RUNNING 2>/dev/null)" = "0" ]; then + bashio::log.warning "UPS commanded shutdown; shutting down the host" + bashio::host.shutdown + exit 0 +fi + +bashio::log.error "lifepo4wered-daemon exited unexpectedly" +exit 1