summaryrefslogtreecommitdiff
blob: 4d45a8e808f79f37345a8b0b5715b6cb2c4d97c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/sbin/runscript
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-power/nut/files/nut.powerfail.initd,v 1.2 2010/06/17 19:38:18 robbat2 Exp $

description='Signal the UPS to kill power in a power failure condition'

depend() {
	# This is only for baselayout2
	if [ -f /etc/init.d/sysfs ]; then
		keyword -jail -lxc -openvz -prefix -uml -vserver -xenu -timeout
	fi
	need mount-ro
}

start() {
	if [ ! -f /etc/init.d/sysfs ]; then
		eerror "The $SVCNAME init-script is written for baselayout-2!"
		eerror "Please do not use it with baselayout-1!".
		return 1
	fi
	local UPS_CTL UPS_POWERDOWN

	if [ -f /etc/killpower ]; then
		UPS_CTL=/sbin/upsdrvctl
		UPS_POWERDOWN="${UPS_CTL} shutdown"
	elif [ -f /etc/apcupsd/powerfail ]; then
		UPS_CTL=/sbin/apcupsd
		UPS_POWERDOWN="${UPS_CTL} --killpower"
	else
		ewarn "UPS powerfail script scheduled, but no poweroff commands found."
		return 0
	fi

	if [ -f "${UPS_CTL}" -a -x "${UPS_CTL}" ]; then
		ebegin 'Signaling UPS to kill power'
		${UPS_POWERDOWN}
		eend $?

		ebegin 'Halt system and wait for the UPS to kill our power'
		/sbin/halt -id
		# If the sleep gets hit, something is wrong...
		# do NOT restart the system.
		while [ 1 ]; do sleep 60; done
	else
		ewarn "UPS powerfail script scheduled, and flags found, but ${UPS_CTL} missing."
	fi
}