summaryrefslogtreecommitdiff
path: root/sysutils/ups-nut/files/upsd
blob: c89fffeeadd3e1de3ae58ce5a599d5d9c6b43153 (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
#!/bin/sh
#
# $NetBSD: upsd,v 1.2 2001/11/20 16:59:10 jlam Exp $
#
# PROVIDE: upsd
# REQUIRE: NETWORK syslogd mountcritremote

# You need to set some parameters for this script in /etc/rc.conf,
# examples are:
#upsd=YES	upsd_flags=""	
#		upsd_dev="/dev/tty01"
#		upsd_driver="apcsmart"
#upsmon=YES	upsmon_host="localhost"

. /etc/rc.conf

if [ -z "$1" -o "x$1" = xstart ]; then
	if [ "x${upsd}" = xYES ]; then
		%%PREFIX%%/bin/${upsd_driver} ${upsd_flags} ${upsd_dev}
		%%PREFIX%%/sbin/upsd
	fi

	if [ "x${upsmon}" = xYES ]; then
		%%PREFIX%%/sbin/upsmon ${upsmon_host}
	fi
elif [ "x$1" = xstop ]; then
	echo "Stopping upsd - caveat, this may not work if multiple instances are running"
	dpid=`ps ax | fgrep %%PREFIX%%/bin/${upsd_driver} | fgrep -v fgrep | awk '{print $1}'`
	upid=`ps ax | fgrep %%PREFIX%%/sbin/upsd | fgrep -v fgrep | awk '{print $1}'`
	if [ ! -z "${upid}" ]; then
		kill ${upid}
	fi
	if [ ! -z "${dpid}" ]; then
		kill ${dpid}
	fi
	if [ -r /var/run/upsmon.pid ]; then
		mpid=`/bin/cat /var/run/upsmon.pid`
		kill ${mpid}
	fi
fi