mirror of
https://github.com/vakius/hassio-addon-lifepo4wered.git
synced 2026-08-01 20:44:12 +03:00
Make lifepo4wered-daemon the primary process in run.sh
The daemon must contact the UPS within PI_BOOT_TO seconds of power-on or the UPS cuts power. Start it immediately via exec as the container's main process; run the MQTT monitor in a background loop with 30s restart backoff so Supervisor API delays or monitor crashes can never delay or kill the daemon. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -45,10 +45,14 @@ present and one subprocess call reads everything at once.
|
|||||||
|
|
||||||
- Dockerfile: add `python3` + `py3-paho-mqtt` (Alpine packages), copy script
|
- Dockerfile: add `python3` + `py3-paho-mqtt` (Alpine packages), copy script
|
||||||
and `run.sh`, `CMD ["/run.sh"]`.
|
and `run.sh`, `CMD ["/run.sh"]`.
|
||||||
- `run.sh` (bashio): pull MQTT host/port/user/password from Supervisor
|
- `run.sh` (bashio): `lifepo4wered-daemon -f` is the exec'd main process,
|
||||||
services API (works out of the box with the Mosquitto addon), allow
|
started immediately — it must contact the UPS within PI_BOOT_TO seconds of
|
||||||
overrides from addon options, start `lifepo4wered-daemon -f` in the
|
power-on or the UPS cuts power, so nothing (Supervisor API calls included)
|
||||||
background, run the monitor in the foreground.
|
may delay it and monitor failures must never take it down. The monitor runs
|
||||||
|
in a background subshell that pulls MQTT host/port/user/password from the
|
||||||
|
Supervisor services API (works out of the box with the Mosquitto addon,
|
||||||
|
addon options can override) and restarts the monitor with 30 s backoff if
|
||||||
|
it exits.
|
||||||
- `config.json`: add `"services": ["mqtt:need"]`, addon options
|
- `config.json`: add `"services": ["mqtt:need"]`, addon options
|
||||||
(`poll_interval`, optional MQTT overrides), bump version.
|
(`poll_interval`, optional MQTT overrides), bump version.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
#!/usr/bin/with-contenv bashio
|
#!/usr/bin/with-contenv bashio
|
||||||
|
|
||||||
|
# The daemon must contact the UPS within PI_BOOT_TO seconds of power-on,
|
||||||
|
# otherwise the UPS assumes the boot failed and cuts power. It is therefore
|
||||||
|
# the main process, started before any MQTT/Supervisor API calls, and the
|
||||||
|
# monitor runs on the side where its failures can never take the daemon down.
|
||||||
|
|
||||||
|
setup_mqtt_env() {
|
||||||
export POLL_INTERVAL="$(bashio::config 'poll_interval')"
|
export POLL_INTERVAL="$(bashio::config 'poll_interval')"
|
||||||
|
|
||||||
# Manual MQTT settings from addon options win; otherwise use the broker
|
# Manual MQTT settings from addon options win; otherwise use the broker
|
||||||
@@ -25,9 +31,17 @@ else
|
|||||||
"No MQTT broker configured and no mqtt service available;" \
|
"No MQTT broker configured and no mqtt service available;" \
|
||||||
"trying localhost:1883"
|
"trying localhost:1883"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
(
|
||||||
|
setup_mqtt_env
|
||||||
|
bashio::log.info "Starting MQTT monitor (poll interval: ${POLL_INTERVAL}s)"
|
||||||
|
while true; do
|
||||||
|
python3 /usr/bin/lifepo4wered_monitor.py || true
|
||||||
|
bashio::log.warning "MQTT monitor exited; restarting in 30s"
|
||||||
|
sleep 30
|
||||||
|
done
|
||||||
|
) &
|
||||||
|
|
||||||
bashio::log.info "Starting lifepo4wered-daemon"
|
bashio::log.info "Starting lifepo4wered-daemon"
|
||||||
lifepo4wered-daemon -f &
|
exec lifepo4wered-daemon -f
|
||||||
|
|
||||||
bashio::log.info "Starting MQTT monitor (poll interval: ${POLL_INTERVAL}s)"
|
|
||||||
exec python3 /usr/bin/lifepo4wered_monitor.py
|
|
||||||
|
|||||||
Reference in New Issue
Block a user