systemd/systemd-powerfail

29 lines
771 B
Bash

#!/bin/bash
#
# /usr/lib/systemd/systemd-powerfail
#
# Copyright (c) 2014 SUSE LINUX Products GmbH, Germany.
# Author: Werner Fink
# Please send feedback to http://www.suse.de/feedback
#
# Description:
#
# Used to evaluate the status of /var/run/powerstatus
#
trap "echo" SIGINT SIGSEGV SIGTERM
POWERFAIL='THE POWER IS FAILED! SYSTEM GOING DOWN! PLEASE LOG OFF NOW!'
POWERFAILNOW='THE POWER IS FAILED! LOW BATTERY - EMERGENCY SYSTEM SHUTDOWN!'
POWERISBACK='THE POWER IS BACK'
typeset pwrstat=0
test -s /var/run/powerstatus && read pwrstat < /var/run/powerstatus
rm -f /var/run/powerstatus
case "$pwrstat" in
O*) exec /sbin/shutdown -c +0 "$POWERISBACK" ;;
L*) exec /sbin/shutdown -P +0 "$POWERFAILNOW" ;;
*) exec /sbin/shutdown -P +2 "$POWERFAIL" ;;
esac