1 |
slords |
1.1 |
#! /bin/bash |
2 |
|
|
# |
3 |
|
|
# chkconfig: - 26 74 |
4 |
|
|
# description: Network UPS Tools is a collection of programs which provide a common \ |
5 |
|
|
# interface for monitoring and administering UPS hardware. |
6 |
|
|
|
7 |
|
|
# processname: upsd |
8 |
|
|
# config: /etc/ups/ |
9 |
|
|
|
10 |
|
|
# Source function library. |
11 |
|
|
if [ -f /etc/init.d/functions ]; then |
12 |
|
|
. /etc/init.d/functions |
13 |
|
|
elif [ -f /etc/rc.d/init.d/functions ]; then |
14 |
|
|
. /etc/rc.d/init.d/functions |
15 |
|
|
else |
16 |
|
|
exit 0 |
17 |
|
|
fi |
18 |
|
|
|
19 |
|
|
# Get config. |
20 |
|
|
if [ -f /etc/sysconfig/ups ]; then |
21 |
|
|
. /etc/sysconfig/ups |
22 |
|
|
else |
23 |
|
|
SERVER="no" |
24 |
|
|
fi |
25 |
|
|
|
26 |
|
|
start() { |
27 |
|
|
if [ "$SERVER" = "yes" ]; then |
28 |
|
|
# Exit if server = yes and model = NONE (not configured) |
29 |
|
|
|
30 |
|
|
if [ "$MODEL" = "NONE" ]; then |
31 |
|
|
exit 0 |
32 |
|
|
fi |
33 |
|
|
|
34 |
|
|
echo -n $"Starting $MODEL: " |
35 |
|
|
if [ "$MODEL" = "upsdrvctl" ]; then |
36 |
|
|
daemon /sbin/upsdrvctl start |
37 |
|
|
else |
38 |
|
|
daemon /sbin/$MODEL $OPTIONS $DEVICE |
39 |
|
|
fi |
40 |
|
|
echo |
41 |
|
|
|
42 |
|
|
prog="upsd" |
43 |
|
|
echo -n $"Starting $prog: " |
44 |
|
|
daemon /usr/sbin/upsd $UPSD_OPTIONS |
45 |
|
|
RETVAL=$? |
46 |
|
|
echo |
47 |
|
|
|
48 |
|
|
echo -n $"Starting UPS monitor (master): " |
49 |
|
|
daemon /usr/sbin/upsmon |
50 |
|
|
echo |
51 |
|
|
else |
52 |
|
|
echo -n $"Starting UPS monitor (slave): " |
53 |
|
|
daemon /usr/sbin/upsmon |
54 |
|
|
echo |
55 |
|
|
fi |
56 |
|
|
|
57 |
|
|
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/ups |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
stop() { |
61 |
|
|
echo -n $"Stopping UPS monitor: " |
62 |
|
|
killproc upsmon |
63 |
|
|
echo |
64 |
|
|
|
65 |
|
|
if [ "$SERVER" = "yes" ]; then |
66 |
|
|
prog="upsd" |
67 |
|
|
echo -n $"Stopping $prog: " |
68 |
|
|
killproc upsd |
69 |
|
|
RETVAL=$? |
70 |
|
|
echo |
71 |
|
|
|
72 |
|
|
echo -n $"Shutting down $MODEL: " |
73 |
|
|
if [ "$MODEL" = "upsdrvctl" ]; then |
74 |
|
|
/sbin/upsdrvctl stop |
75 |
|
|
else |
76 |
|
|
killproc $MODEL |
77 |
|
|
fi |
78 |
|
|
echo |
79 |
|
|
fi |
80 |
|
|
[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/ups |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
restart() { |
84 |
|
|
stop |
85 |
|
|
start |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
# See how we are called. |
89 |
|
|
case "$1" in |
90 |
|
|
start) |
91 |
|
|
start ;; |
92 |
|
|
|
93 |
|
|
stop) |
94 |
|
|
stop ;; |
95 |
|
|
|
96 |
|
|
restart) |
97 |
|
|
restart ;; |
98 |
|
|
|
99 |
|
|
condrestart) |
100 |
|
|
[ -f /var/lock/subsys/ups ] && restart || : |
101 |
|
|
;; |
102 |
|
|
|
103 |
|
|
status) |
104 |
|
|
if [ "$SERVER" = "yes" ]; then |
105 |
|
|
if [ "$MODEL" = "upsdrvctl" ]; then |
106 |
|
|
/sbin/upsdrvctl -v status |
107 |
|
|
else |
108 |
|
|
status $MODEL |
109 |
|
|
fi |
110 |
|
|
status upsd |
111 |
|
|
fi |
112 |
|
|
status upsmon |
113 |
|
|
;; |
114 |
|
|
|
115 |
|
|
*) |
116 |
|
|
echo $"Usage: $0 {start|stop|restart|condrestart|status}" |
117 |
|
|
exit 1 |
118 |
|
|
esac |
119 |
|
|
|
120 |
|
|
exit $RETVAL |