]>
Commit | Line | Data |
---|---|---|
f39891c4 AA |
1 | #! /bin/sh |
2 | # | |
e5732d56 | 3 | # apcupsd This shell script takes care of starting and stopping |
4 | # the apcupsd UPS monitoring daemon. | |
f39891c4 | 5 | # |
e5732d56 | 6 | # chkconfig: 2345 60 99 |
7 | # description: apcupsd monitors power and takes action if necessary | |
f39891c4 AA |
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 | ||
771e0039 SP |
25 | # Get service config |
26 | if [ -f /etc/sysconfig/apcupsd ]; then | |
a9875e22 | 27 | . /etc/sysconfig/apcupsd |
771e0039 SP |
28 | fi |
29 | ||
a9875e22 ER |
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 | ||
5013d837 ER |
55 | condrestart() { |
56 | if [ ! -f /var/lock/subsys/apcupsd ]; then | |
57 | msg_not_running "APC UPS monitoring" | |
58 | RETVAL=$1 | |
59 | return | |
60 | fi | |
61 | ||
62 | stop | |
63 | start | |
64 | } | |
65 | ||
a9875e22 ER |
66 | powerdown() { |
67 | if [ ! -f /etc/apcupsd/powerfail ]; then | |
68 | return | |
69 | fi | |
70 | ||
71 | show "Switching the power off" | |
72 | /etc/apcupsd/apccontrol killpower | |
73 | sleep 60 | |
74 | fail | |
75 | } | |
76 | ||
f39891c4 AA |
77 | RETVAL=0 |
78 | # See how we were called. | |
79 | case "$1" in | |
80 | start) | |
a9875e22 | 81 | start |
f39891c4 AA |
82 | ;; |
83 | stop) | |
a9875e22 | 84 | stop |
f39891c4 | 85 | ;; |
5013d837 | 86 | restart) |
a9875e22 ER |
87 | stop |
88 | start | |
f39891c4 | 89 | ;; |
5013d837 ER |
90 | try-restart) |
91 | condrestart 0 | |
92 | ;; | |
93 | force-reload) | |
94 | condrestart 7 | |
95 | ;; | |
f39891c4 | 96 | powerdown) |
a9875e22 | 97 | powerdown |
f39891c4 AA |
98 | ;; |
99 | status) | |
ed013e58 | 100 | status apcupsd |
f39891c4 | 101 | /usr/sbin/apcaccess status |
4ffe5847 | 102 | RETVAL=$? |
f39891c4 AA |
103 | ;; |
104 | *) | |
5013d837 | 105 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|powerdown|status}" |
f39891c4 AA |
106 | exit 3 |
107 | esac | |
108 | ||
109 | exit $RETVAL |