summaryrefslogtreecommitdiff
path: root/package/apcupsd/files/apcupsd.init
blob: a9817f1be685e058f7b44613ec9a287d0acae086 (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
#!/bin/sh
#PKG apcupsd
#INIT 15
. /etc/rc.conf

pidfile=$(echo "$apcupsd_flags" | \
	  sed -n 's/.*\(-P\|--pid-file\) \([^ ]\+\).*/\2/p')
[ "$pidfile" ] || pidfile="/var/run/apcupsd.pid"

case $1 in
autostop) ;;
autostart)
	test x"${apcupsd:-NO}" = x"NO" && exit 0
	test x"$apcupsd" = x"DAEMON" && test -x /bin/mksh && exec mksh -T- $0 start
	exec sh $0 start
	;;
start)
	mkdir -p /var/lock
	/usr/sbin/apcupsd $apcupsd_flags
	;;
stop)
	if [ -f "$pidfile" ]; then
		kill $(<$pidfile)
		rm -f $pidfile
	else
		kill $(pgrep -f /usr/sbin/apcupsd)
	fi
	;;
restart)
	sh $0 stop
	sleep 1
	sh $0 start
	;;
*)
	echo "usage: $0 (start | stop | restart)"
	exit 1
esac
exit $?