Bringing laptops back after a power cut
Two of my machines are laptops that never sleep. One is an ASUS, one is a ThinkPad. They act as always-on servers, so I set them up to stay reachable instead of saving power. A power cut tests that setup.
Keep them awake
Closing the lid does nothing. A drop-in file for systemd-logind sets
HandleLidSwitch=ignore on both machines. The ASUS already had its own file
that sets suspend-then-hibernate. logind applies drop-ins in lexical order, so
my override has a zz- prefix to sort after it. Deleting that one file
restores normal lid behaviour.
Cap the charge
A battery that sits at 100% on mains wears out. I cap it at 80%.
- On the ThinkPad, a small systemd unit writes the start and end thresholds at boot. The firmware forgets them on every reboot. The unit writes the start value first, because the kernel rejects an inverted pair.
- On the ASUS, the
asusddaemon owns the cap. A direct write to sysfs reverted after the next reboot. I change the value in theasusdconfig file instead.
Shut down clean on low battery
UPower does this. I wrote no script. Each machine has a percentage for
“action” and CriticalPowerAction=PowerOff. The thresholds must stay ordered
low, then critical, then action. An action value above critical never fires.
Power on without me
The two machines differ here.
The ThinkPad has a firmware setting, OnByAcAttach. I set it to Enable
through the thinklmi interface. The machine starts when mains returns. It
survived a reboot test.
The ASUS has no such setting. I tested Wake-on-LAN from a full power-off. The
magic packet reached the network card, which I confirmed with tcpdump. The
firmware ignored it. The card still reports that wake-on-magic-packet is
armed, so the flag looks right while the feature is dead.
RTC alarms do work. On shutdown, a hook arms the next alarm. The delays grow: 30 minutes, 1 hour, 2, 4, 8, then 12 hours. The hook arms an alarm only on battery, so a deliberate shutdown on mains stays off. A counter updates at boot, not at shutdown, because the disk may be read-only by then.
Tell me about it
One laptop was unplugged and shut down without any notice. Two small additions came from that.
- A timer runs every minute. It sends a Telegram message when the charger is unplugged or plugged back in, and at 30% and 15% while unplugged.
- A service runs once per boot. It reports how the previous boot ended, read from the logind lines in the journal, plus the last battery reading.
The journals confirmed that UPower powered off both laptops on low battery.
Still open
I do not trust boot times on these machines. uptime -s and the first
journal line both gave wrong values, so the report leaves them out. The ASUS
journal size is also still uncapped. I would test the RTC chain with a real
outage earlier next time.