Power-source detection
The guard reads Linux power-supply data for mains, USB, USB-C, USB-PD, and battery charging or full states instead of relying on a single adapter name.
Linux laptop servers
Power Outage Helper watches incoming power and network reachability. If both remain unavailable after a grace period, it starts a normal Linux shutdown before the laptop battery is exhausted.
Two signals before shutdown
The guard reads Linux power-supply data for mains, USB, USB-C, USB-PD, and battery charging or full states instead of relying on a single adapter name.
After power is absent for 30 seconds, shutdown proceeds only if google.com, 1.1.1.1, and the local gateway at 192.168.1.1 are all unreachable.
One script installs, starts, checks, and removes a systemd service. The service restarts automatically and records events through the system logger.
Install with systemd
The installer copies the guard to /usr/local/sbin, creates the systemd unit, and enables it immediately. Root access and the ping command from iputils-ping are required.
chmod +x power-network-shutdown-guard.sh
sudo ./power-network-shutdown-guard.sh --install
sudo ./power-network-shutdown-guard.sh --status
Non-destructive verification
The adapter test polls every two seconds and never shuts down the machine. Use it first to confirm that the laptop exposes its charging state through /sys/class/power_supply.