summaryrefslogtreecommitdiff
blob: 2a69687db89da28955a9567dd4c6084f68c42908 (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/openrc-run
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

INSTANCE="${SVCNAME#*.}"
if [ -z "${INSTANCE}" ] || [ "${SVCNAME}" = "apcupsd" ]; then
	INSTANCE="apcupsd"
fi

dir="/run/apcupsd"

depend() {
	use net
}

start_pre() {
        checkpath -d -m 0775 -o root:uucp ${dir} 
}

start() {
	rm -f /etc/apcupsd/powerfail

	export SERVICE="${SVCNAME}"

	if [ ! -d "${dir}" ]; then
		einfo " Creating ${dir}"
		/bin/mkdir -p "${dir}"
		/bin/chown root:uucp "${dir}"
	fi

	ebegin "Starting APC UPS daemon"
	start-stop-daemon \
		--start --pidfile "${dir}/${SVCNAME}.pid" \
		--exec /sbin/apcupsd -- \
		-f "/etc/apcupsd/${INSTANCE}.conf" \
		-P "${dir}/${SVCNAME}.pid"
	eend $?
}

stop() {
	ebegin "Stopping APC UPS daemon"
	start-stop-daemon \
		--stop --pidfile "${dir}/${SVCNAME}.pid" \
            	--retry TERM/5/TERM/5 \
		--exec /sbin/apcupsd
	eend $?
}