fix: command UPS output shutdown before host poweroff to enable unattended recovery#513
Conversation
When shutdown_host is true, the shutdownhost script was calling bashio::host.shutdown without first issuing upsdrvctl shutdown. This meant the UPS output never cycled off/on, so the host never received a power-restore event and would not reboot after a power outage — including the "power race" case where AC returns while the host is shutting down. Fix: check for the NUT POWERDOWNFLAG (via upsmon -K) and run upsdrvctl shutdown before handing off to bashio::host.shutdown. The UPS offdelay (default 120 s) gives the host sufficient time to complete its shutdown before the UPS cuts output. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add a new opt-in config option that commands the UPS to cycle its output before host shutdown, enabling fully unattended recovery after a power outage. When enabled, upsdrvctl shutdown is called if the NUT POWERDOWNFLAG is set, starting the UPS offdelay countdown before handing off to bashio::host.shutdown. - shutdownhost: gate upsdrvctl shutdown on ups_power_cycle_on_shutdown config - config.yaml: add option (default false) and schema entry - DOCS.md: document the new option, requirements, and how it works - translations/en.yaml: add UI labels and descriptions for all config options Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pinned exact Debian package versions break the build whenever the repository moves to a newer version. Use unpinned package names and suppress the hadolint DL3008 warning explicitly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Need an answer fast? Review this PR in Change Stack to ask focused questions about the PR or a changed range. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds an optional ChangesUPS Power Cycling on Shutdown
Sequence DiagramsequenceDiagram
participant shutdownhost as shutdownhost script
participant upsmon as upsmon
participant upsdrvctl as upsdrvctl
participant Host as Host/BIOS
shutdownhost->>upsmon: run `upsmon -K` (check POWERDOWNFLAG)
upsmon-->>shutdownhost: return POWERDOWNFLAG set / not set
alt POWERDOWNFLAG set
shutdownhost->>upsdrvctl: run `upsdrvctl shutdown` (trigger offdelay/ondelay)
upsdrvctl-->>shutdownhost: exit status (0 or non-zero)
shutdownhost->>Host: call `bashio::host.shutdown`
else POWERDOWNFLAG not set
shutdownhost->>shutdownhost: log skip UPS output shutdown
shutdownhost->>Host: call `bashio::host.shutdown`
end
🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@nut/rootfs/usr/bin/shutdownhost`:
- Line 16: The script currently runs upsdrvctl shutdown without checking its
result; wrap the upsdrvctl shutdown invocation in an error check so failures are
detected, capture stderr/exit code and emit a clear diagnostic (e.g., via
logger/syslog or echo) including the exit status and output, and ensure the
script returns a non‑zero code or takes a compensating action when upsdrvctl
fails; locate the upsdrvctl shutdown call in the shutdownhost script and replace
the unconditional call with a conditional that logs the error and propagates
failure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 07a4f6e9-587e-4e75-9185-a6e8a2364dec
📒 Files selected for processing (5)
nut/DOCS.mdnut/Dockerfilenut/config.yamlnut/rootfs/usr/bin/shutdownhostnut/translations/en.yaml
Capture and log the exit code of `upsdrvctl shutdown` so a failure to cycle UPS output is surfaced in the add-on log. The host shutdown still proceeds regardless, since failing to cut UPS power must not block the host from powering down. Addresses CodeRabbit review feedback on hassio-addons#513. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Friendly ping — this PR is ready for review when a maintainer has a moment. 🙏 Quick status:
@frenck if you could enable the CI workflows to run and take a look when convenient, that would be much appreciated. Happy to make any changes you'd like. |
Summary
Fixes #512
When
shutdown_hostistrue, theshutdownhostscript calledbashio::host.shutdownwithout first issuingupsdrvctl shutdown. This meant the UPS output never cycled off/on after host shutdown, so the host would not reboot automatically after a power outage — including the case where AC returns while the host is shutting down.shutdownhost: add newups_power_cycle_on_shutdownoption that callsupsdrvctl shutdown(via NUT'sPOWERDOWNFLAGcheck) before handing off tobashio::host.shutdown. The UPSoffdelaycountdown gives HAOS sufficient time to complete shutdown before the UPS cuts output.config.yaml: addups_power_cycle_on_shutdownoption (defaultfalsefor backward compatibility) and schema entrytranslations/en.yaml: new file providing UI labels and descriptions for all configuration optionsDOCS.md: document the new option, its requirements (offdelay,ondelay, BIOS power-on-after-AC-restore), and how it worksDockerfile: remove pinned apt package versions that break the build when Debian repository moves to newer versionsBehaviour
shutdown_host: false— unchanged, only the app stopsshutdown_host: true,ups_power_cycle_on_shutdown: false— unchanged, host shuts down but UPS output does not cycle (default)shutdown_host: true,ups_power_cycle_on_shutdown: true— host shuts down, UPS output cycles off then on, host reboots automatically via BIOS AC-restoreTest plan
ups_power_cycle_on_shutdown: false— host shuts down, UPS output does not cycle (backward-compatible behavior preserved)ups_power_cycle_on_shutdown: true— host shuts down cleanly, UPS output cuts afteroffdelay(120s), restores afterondelay(180s) with AC present, host reboots automaticallyPOWERDOWNFLAGcheck (upsmon -K) correctly gates theupsdrvctl shutdowncall🤖 Generated with Claude Code
Summary by CodeRabbit