battery: van-battery daemon (low-charge Pushover alerts + safe shutdown)
While on battery (AC0/online=0), sends escalating Pushover alerts at 25/20/15% and at 10% sends a final alert then `systemctl poweroff` (after shutdown_grace so the alert flushes first). Edge-triggered per discharge episode; re-arms when mains returns; plug-out already-low collapses to a single alert (no burst). Pushover token+user live only in /etc/van-battery/pushover.json (0600), seeded from pushover.json.example on first deploy and never committed. Missing/ placeholder creds disable sending but NOT the shutdown — running flat must always power down safely. Publishes /run/van-battery/state.json. Stdlib only. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ef6c1ce182
commit
b75b5b16c7
@@ -40,6 +40,7 @@ This directory is the source of truth. The live system files live under `/etc`,
|
||||
| NAT + forwarding | **nftables** + sysctl |
|
||||
| WAN health + failover | **van-failover** daemon |
|
||||
| Temperature monitor / alert / log | **van-thermal** daemon |
|
||||
| Battery monitor / low-charge alert + shutdown | **van-battery** daemon |
|
||||
| ZeroTier DNS → resolved | **zerotier-systemd-manager** + systemd-networkd |
|
||||
| Web UI | **Cockpit** + `vanrouter` plugin |
|
||||
|
||||
@@ -98,6 +99,10 @@ This directory is the source of truth. The live system files live under `/etc`,
|
||||
| `van-thermal` | `/usr/local/sbin/van-thermal` | temperature daemon (Python): publishes state, alerts, logs history |
|
||||
| `thermal-config.json` | `/etc/van-thermal/config.json` | sensors + warn/crit thresholds + sample/log intervals |
|
||||
| `van-thermal.service` | `/etc/systemd/system/van-thermal.service` | `Restart=always` |
|
||||
| `van-battery` | `/usr/local/sbin/van-battery` | battery daemon (Python): Pushover low-charge alerts + safe shutdown |
|
||||
| `battery-config.json` | `/etc/van-battery/config.json` | warn levels, shutdown level, poll interval, paths |
|
||||
| `van-battery.service` | `/etc/systemd/system/van-battery.service` | `Restart=always` |
|
||||
| `pushover.json.example` | → `/etc/van-battery/pushover.json` (seeded if absent) | Pushover token+user **template**; real file is 0600, **not** in the repo |
|
||||
|
||||
`deploy.sh` additionally **masks** `sleep.target suspend.target hibernate.target hybrid-sleep.target`
|
||||
(no repo file — symlinks to `/dev/null` under `/etc/systemd/system/`) so nothing else can suspend either.
|
||||
@@ -135,6 +140,14 @@ This directory is the source of truth. The live system files live under `/etc`,
|
||||
- **Tuning**: edit `/etc/van-thermal/config.json` (thresholds, intervals, sensor list), then `systemctl restart van-thermal`. Defaults: CPU warn 80 / crit 95 °C (silicon crit is 100), NVMe warn 65 / crit 70 °C (drive crit ~71).
|
||||
- Status: `systemctl status van-thermal` or `cat /run/van-thermal/state.json`.
|
||||
|
||||
### Battery monitor (`van-battery`)
|
||||
- Watches mains vs battery via `/sys/class/power_supply/AC0/online` (0 = on battery) and charge via `BAT0/capacity`. Both resolve by `type` (Mains/Battery) if those names ever differ.
|
||||
- **Only while on battery**, it sends escalating **Pushover** alerts at **25 / 20 / 15 %**, and at **10 %** sends a final alert and runs `systemctl poweroff` (after `shutdown_grace`, default 8 s, so the alert flushes first).
|
||||
- Edge-triggered per discharge episode: each severity fires once; the sequence **re-arms when mains returns**. Unplugging already below a warn level fires a single alert for the current severity (no burst), then shutdown at 10 %.
|
||||
- **Credentials** live in `/etc/van-battery/pushover.json` (mode 0600), seeded from `pushover.json.example` on first deploy and **never committed**. Missing/placeholder creds disable *sending* but **not** the shutdown — running flat must always power down safely (the skip is logged to the journal).
|
||||
- Tune in `/etc/van-battery/config.json` (`warn_levels`, `shutdown_level`, `poll_interval`), then `systemctl restart van-battery`.
|
||||
- Status: `systemctl status van-battery`, `journalctl -u van-battery -f`, or `cat /run/van-battery/state.json`.
|
||||
|
||||
### Adding the 4G/5G modem
|
||||
1. Plug the USB modem in. ModemManager + the existing `Koodo` gsm NM connection (autoconnect) bring it up.
|
||||
2. It auto-joins as the `cellular` WAN at metric 300 (last resort). Nothing else to configure.
|
||||
@@ -171,7 +184,7 @@ cd ~/vanlink
|
||||
sudo ./deploy.sh # copies all files to their system locations, reloads + enables services
|
||||
```
|
||||
|
||||
Two things `deploy.sh` does **not** do (one-time, manual):
|
||||
Three things `deploy.sh` does **not** do (one-time, manual):
|
||||
|
||||
1. **zerotier-systemd-manager binary** (v0.4.0, hand-installed — not in the ZeroTier apt repo):
|
||||
```bash
|
||||
@@ -180,6 +193,7 @@ Two things `deploy.sh` does **not** do (one-time, manual):
|
||||
sudo zerotier-cli set d3ecf5726d041b2a allowDNS=1
|
||||
```
|
||||
2. **hostapd unmask** (Ubuntu ships it masked): `sudo systemctl unmask hostapd`.
|
||||
3. **Pushover credentials** for `van-battery` — deploy seeds `/etc/van-battery/pushover.json` (0600) with placeholders; fill in your app token + user key, then `sudo systemctl restart van-battery`. Until then low-battery alerts are skipped (logged), but the 10 % auto-shutdown still works.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user