silod is a tiny Rust daemon that monitors the TS‑SILO super‑capacitor backup power supply and orchestrates a graceful shutdown (plus any user‑defined helper scripts) when input power is lost. It is intended for embedded Linux systems that use the tssilo kernel driver (exposed via sysfs).
Features:
- Watches the kernel
ueventmulticast stream for power‑supply change events (no polling). - Executes event‑specific hooks in
/etc/silod/scripts.d/:power-failpower-restoredfully-chargedcritical
- Applies configuration to the driver on startup (
charge_behaviour, capacity thresholds, current limits…). - Logs to stdout when run interactively, or to syslog (
LOG_DAEMON) when run as a background service. - Re‑execs
shutdown -p nowautomatically once a critical capacity threshold is crossed.
Install rust if it is not already present, either through the distribution or rustup
# Fetch and build
git clone https://github.com/embeddedTS/silod.git
cd silod
cargo build --release
# Install the binary (requires root for /usr/sbin)
sudo install -m 0755 target/release/silod /usr/sbin/
sudo mkdir -p /etc/silod/scripts.d/{power-fail,power-restored,fully-charged,critical}# As root:
silod
systemctl start silod.service| Event | Condition | Hook executed |
|---|---|---|
| Initial charge | First run after boot | – |
| Fully charged | Online and capacity == 100 % | fully-charged |
| Power‑fail | Input lost while current capacity ≥ threshold | power-fail |
| Power‑restored | Input restored | power-restored |
| Critical | capacity < critical_pct |
critical |
/etc/silod/silo.toml
# Mandatory: percent below which the system shuts down
critical_pct = 60
# Optional: enable or inhibit charging (maps to charge_behaviour)
enable_charging = true
# Optional: minimum capacity required before the board may power on again
min_power_on_pct = 80
# Optional: initial charge current (mA) applied after a brown‑out
startup_charge_current_ma = 500All values are written to /sys/class/power_supply/tssilo/… and logged back for verification.
Place any executable files in /etc/silod/scripts.d in one of the directories:
power-failpower-restoredfully-chargedcritical
Example:
#!/bin/sh
#/etc/silod/scripts.d/critical/01-send-shutdown-message.sh
curl -X POST http://your-server.example.com/log \
-H "Content-Type: application/json" \
-d '{"level": "info", "message": "System is shutting down due supercaps draining", "timestamp": "'"$(date -Is)"'"}'
Scripts are executed sequentially in filename order. Failures are logged, but do not abort the chain.
# /etc/systemd/system/silod.service
[Unit]
Description=TS‑SILO supercap backup monitor
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/sbin/silod
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.targetsudo systemctl enable --now silod.service- Interactive run → stderr/stdout with ANSI colours.
- Background/service run → syslog (
LOG_DAEMON), view withjournalctl -t silodon systemd systems.
Set the log level with the RUST_LOG environment variable, e.g.:
sudo RUST_LOG=debug silod