/
apcupsd.init
executable file
·80 lines (70 loc) · 1.77 KB
/
apcupsd.init
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /bin/sh
#
# apcupsd
# Start the APC UPS daemon to monitor power status.
#
DAEMON=/sbin/apcupsd
CONFIG=/etc/default/apcupsd
CONFIGFILES=/etc/apcupsd/apcupsd*.conf
POWERFAIL=/var/spool/apcupsd/powerfail
test -x $DAEMON || exit 0
test -e $CONFIG || exit 0
set -e
. $CONFIG
if [ $ISCONFIGURED = no ]
then
echo -n "Please check your configuration "
echo " ISCONFIGURED in /etc/default/apcupsd"
exit 0
fi
case "$1" in
start)
echo -n "Starting APC UPS power management: "
rm -f $POWERFAIL
# Create proper links
/usr/local/sbin/assignAPC
for f in $CONFIGFILES
do
PIDFILE=`echo $f | sed 's/.*apcupsd\([^.]*\).conf/\/var\/run\/apcupsd\1.pid/g'`
echo -n "$PIDFILE "
if [ ! -f $PIDFILE ] || [ ! -e /proc/`cat $PIDFILE` ]
then
start-stop-daemon --start --pidfile $PIDFILE --quiet --exec $DAEMON -- -f $f -P $PIDFILE \
|| echo -n "failed! "
# sleep 2
else
echo ""
echo "A copy of the daemon is still running. If you just stopped it,"
echo "please wait about 5 seconds for it to shut down."
exit 0
fi
done
echo ""
;;
stop)
echo -n "Stopping APC UPS power management: "
for f in $CONFIGFILES
do
PIDFILE=`echo $f | sed 's/.*apcupsd\([^.]*\).conf/\/var\/run\/apcupsd\1.pid/g'`
echo -n "$PIDFILE "
start-stop-daemon --stop --pidfile $PIDFILE --quiet --exec $DAEMON \
|| echo -n "failed: not running? "
done
echo ""
;;
restart|force-reload)
echo -n "Restarting APC UPS power management: "
$0 stop
sleep 10
$0 start
;;
status)
#/sbin/apcaccess status
$APCACCESS status
;;
*)
echo "Usage: /etc/init.d/apcupsd {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0