]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # | |
3 | # ups NUT - Network UPS Tools daemon | |
4 | # | |
5 | # chkconfig: 2345 10 90 | |
6 | # | |
7 | # description: The ups daemon monitors an UPS and makes information about \ | |
8 | # it's status available to other programs | |
9 | # processname: upsd | |
10 | # config: /etc/ups/ | |
11 | ||
12 | # Source function library. | |
13 | . /etc/rc.d/init.d/functions | |
14 | ||
15 | # Get network config | |
16 | . /etc/sysconfig/network | |
17 | ||
18 | # Get config. | |
19 | [ -f /etc/sysconfig/ups ] && . /etc/sysconfig/ups | |
20 | ||
21 | [ -n "$PORT" ] && OPTIONS="-p $PORT" | |
22 | [ -n "$TCP_PORT" ] && OPTIONS="-t $TCP_PORT" | |
23 | [ -n "$BIND_ADDRESS" ] && OPTIONS="$OPTIONS -i $BIND_ADDRESS" | |
24 | ||
25 | if [ -n "$BIND_ADDRESS" ] || [ -n "$TCP_PORT" ]; then | |
26 | # Check that networking is up. | |
27 | if is_yes "${NETWORKING}"; then | |
28 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
29 | msg_network_down "UPS network daemon" | |
30 | exit 1 | |
31 | fi | |
32 | else | |
33 | exit 0 | |
34 | fi | |
35 | fi | |
36 | ||
37 | RETVAL=0 | |
38 | # See how we are called. | |
39 | case "$1" in | |
40 | start) | |
41 | # Check if the service is already running? | |
42 | if [ ! -f /var/lock/subsys/ups ]; then | |
43 | show "Starting UPS drivers" | |
44 | daemon /lib/nut/upsdrvctl start | |
45 | RETVAL=$? | |
46 | if [ $RETVAL -eq 0 ]; then | |
47 | msg_starting "UPS network daemon" | |
48 | daemon "upsd $OPTIONS" | |
49 | RETVAL=$? | |
50 | touch /var/lock/subsys/ups | |
51 | fi | |
52 | else | |
53 | msg_already_running "UPS drivers and network daemon" | |
54 | fi | |
55 | ;; | |
56 | stop) | |
57 | if [ -f /var/lock/subsys/ups ]; then | |
58 | msg_stopping "UPS daemon" | |
59 | killproc upsd | |
60 | run_cmd "Stopping UPS drivers" /lib/nut/upsdrvctl stop | |
61 | rm -f /var/lock/subsys/ups | |
62 | else | |
63 | msg_not_running "UPS daemon" | |
64 | fi | |
65 | ;; | |
66 | restart) | |
67 | $0 stop | |
68 | $0 start | |
69 | exit $? | |
70 | ;; | |
71 | reload|force-reload) | |
72 | if [ -f /var/lock/subsys/ups ]; then | |
73 | show "Reloading UPS drivers" | |
74 | daemon /lib/nut/upsdrvctl reload | |
75 | [ $? -ne 0 ] && RETVAL=7 | |
76 | msg_reloading "UPS network daemon" | |
77 | daemon upsd -c reload | |
78 | [ $? -ne 0 ] && RETVAL=7 | |
79 | else | |
80 | msg_not_running "UPS daemon" >&2 | |
81 | exit 7 | |
82 | fi | |
83 | ;; | |
84 | powerdown) | |
85 | show "Switching the power off" ; busy | |
86 | /lib/nut/upsdrvctl shutdown | |
87 | sleep 60 | |
88 | fail | |
89 | ;; | |
90 | status) | |
91 | status upsd | |
92 | RETVAL=$? | |
93 | /lib/nut/upsdrvctl status | |
94 | ;; | |
95 | *) | |
96 | msg_usage "$0 {start|stop|restart|reload|force-reload|status|powerdown}" | |
97 | exit 3 | |
98 | esac | |
99 | ||
100 | exit $RETVAL |