]>
Commit | Line | Data |
---|---|---|
1 | #! /bin/sh | |
2 | # | |
3 | # apcupsd This shell script takes care of starting and stopping | |
4 | # the apcupsd UPS monitoring daemon. | |
5 | # | |
6 | # chkconfig: 2345 60 99 | |
7 | # description: apcupsd monitors power and takes action if necessary | |
8 | ||
9 | # Source function library | |
10 | . /etc/rc.d/init.d/functions | |
11 | ||
12 | # Get network config | |
13 | . /etc/sysconfig/network | |
14 | ||
15 | # Check that networking is up. | |
16 | if is_yes "${NETWORKING}"; then | |
17 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
18 | msg_network_down "UPS monitoring" | |
19 | exit 1 | |
20 | fi | |
21 | else | |
22 | exit 0 | |
23 | fi | |
24 | ||
25 | # Get service config | |
26 | if [ -f /etc/sysconfig/apcupsd ]; then | |
27 | . /etc/sysconfig/apcupsd | |
28 | fi | |
29 | ||
30 | start() { | |
31 | # Check if the service is already running? | |
32 | if [ -f /var/lock/subsys/apcupsd ]; then | |
33 | msg_already_running "APC UPS monitoring" | |
34 | return | |
35 | fi | |
36 | ||
37 | msg_starting "APC UPS monitoring" | |
38 | rm -f /etc/apcupsd/powerfail | |
39 | daemon $SERVICE_RUN_NICE_LEVEL /usr/sbin/apcupsd -f /etc/apcupsd/apcupsd.conf | |
40 | RETVAL=$? | |
41 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/apcupsd | |
42 | } | |
43 | ||
44 | stop() { | |
45 | if [ ! -f /var/lock/subsys/apcupsd ]; then | |
46 | msg_not_running "APC UPS monitoring" | |
47 | return | |
48 | fi | |
49 | ||
50 | msg_stopping "APC UPS monitoring" | |
51 | killproc apcupsd | |
52 | rm -f /var/lock/subsys/apcupsd | |
53 | } | |
54 | ||
55 | powerdown() { | |
56 | if [ ! -f /etc/apcupsd/powerfail ]; then | |
57 | return | |
58 | fi | |
59 | ||
60 | show "Switching the power off" | |
61 | /etc/apcupsd/apccontrol killpower | |
62 | sleep 60 | |
63 | fail | |
64 | } | |
65 | ||
66 | RETVAL=0 | |
67 | # See how we were called. | |
68 | case "$1" in | |
69 | start) | |
70 | start | |
71 | ;; | |
72 | stop) | |
73 | stop | |
74 | ;; | |
75 | restart|force-reload) | |
76 | stop | |
77 | start | |
78 | ;; | |
79 | powerdown) | |
80 | powerdown | |
81 | ;; | |
82 | status) | |
83 | /usr/sbin/apcaccess status | |
84 | ;; | |
85 | *) | |
86 | msg_usage "$0 {start|stop|restart|force-reload|powerdown|status}" | |
87 | exit 3 | |
88 | esac | |
89 | ||
90 | exit $RETVAL |