Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 592108
Collapse All | Expand All

(-)org/apcupsd.init.4 (-34 / +24 lines)
Lines 3-49 Link Here
3
# Distributed under the terms of the GNU General Public License v2
3
# Distributed under the terms of the GNU General Public License v2
4
# $Id$
4
# $Id$
5
5
6
INSTANCE="${SVCNAME#*.}"
6
INSTANCE="${RC_SVCNAME#*.}"
7
if [ -z "${INSTANCE}" ] || [ "${SVCNAME}" = "apcupsd" ]; then
8
	INSTANCE="apcupsd"
9
fi
10
7
11
dir="/run/apcupsd"
8
APCUPSD_RUN_DIR="/run/apcupsd"
9
POWERFAIL_FILE="/etc/apcupsd/powerfail"
10
INSTANCE_CONF_FILE="/etc/apcupsd/${INSTANCE}.conf"
11
12
description="APC UPS daemon"
13
name="${description}"
14
command="/sbin/apcupsd"
15
pidfile="${APCUPSD_RUN_DIR}/${RC_SVCNAME}.pid"
16
command_args="-f ${INSTANCE_CONF_FILE} -P ${pidfile}"
12
17
13
depend() {
18
depend() {
14
	use net
19
	use net mta
15
}
20
}
16
21
17
start_pre() {
22
_mng_powerfail() {
18
        checkpath -d -m 0775 -o root:uucp ${dir} 
23
	local UPSNAME=$(awk '{if($1 == "UPSNAME"){print $2}}' ${INSTANCE_CONF_FILE})
24
	[ -z "${UPSNAME}" ] && UPSNAME=$(hostname)
25
	/etc/apcupsd/apccontrol offbattery ${UPSNAME}
26
	rm -f ${POWERFAIL_FILE}
19
}
27
}
20
28
21
start() {
29
start_pre() {
22
	rm -f /etc/apcupsd/powerfail
30
	checkpath -d -m 0775 -o root:uucp ${APCUPSD_RUN_DIR}
23
24
	export SERVICE="${SVCNAME}"
25
26
	if [ ! -d "${dir}" ]; then
27
		einfo " Creating ${dir}"
28
		/bin/mkdir -p "${dir}"
29
		/bin/chown root:uucp "${dir}"
30
	fi
31
32
	ebegin "Starting APC UPS daemon"
33
	start-stop-daemon \
34
		--start --pidfile "${dir}/${SVCNAME}.pid" \
35
		--exec /sbin/apcupsd -- \
36
		-f "/etc/apcupsd/${INSTANCE}.conf" \
37
		-P "${dir}/${SVCNAME}.pid"
38
	eend $?
39
}
31
}
40
32
41
stop() {
33
start_post() {
42
	ebegin "Stopping APC UPS daemon"
34
	if [ "${INSTANCE}" = "apcupsd" -a -f ${POWERFAIL_FILE} ]
43
	start-stop-daemon \
35
	then
44
		--stop --pidfile "${dir}/${SVCNAME}.pid" \
36
		sleep 2
45
            	--retry TERM/5/TERM/5 \
37
		_mng_powerfail
46
		--exec /sbin/apcupsd
38
	fi
47
	eend $?
48
}
39
}
49

Return to bug 592108