]> git.pld-linux.org Git - packages/nut.git/blob - nut.init
- updated to 2.6.3
[packages/nut.git] / nut.init
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                 RETVALDRV=$?
46                 msg_starting "UPS network daemon"
47                 daemon /usr/sbin/upsd "$OPTIONS"
48                 RETVAL=$?
49                 if [ $RETVAL -eq 0 ]; then
50                         touch /var/lock/subsys/ups
51                         RETVAL=$RETVALDRV
52                 fi
53         else
54                 msg_already_running "UPS drivers and network daemon"
55         fi
56         ;;
57   stop)
58         if [ -f /var/lock/subsys/ups ]; then
59                 msg_stopping "UPS daemon"
60                 /usr/sbin/upsd -c stop
61                 run_cmd "Stopping UPS drivers" /lib/nut/upsdrvctl stop
62                 rm -f /var/lock/subsys/ups
63         else
64                 msg_not_running "UPS daemon"
65         fi
66         ;;
67   restart)
68         $0 stop
69         $0 start
70         exit $?
71         ;;
72   reload|force-reload)
73         if [ -f /var/lock/subsys/ups ]; then
74                 show "Reloading UPS drivers"
75                 /lib/nut/upsdrvctl stop
76                 /lib/nut/upsdrvctl start
77                 [ $? -ne 0 ] && RETVAL=7
78                 msg_reloading "UPS network daemon"
79                 /usr/sbin/upsd -c reload
80                 [ $? -ne 0 ] && RETVAL=7
81         else
82                 msg_not_running "UPS daemon" >&2
83                 exit 7
84         fi
85         ;;
86   powerdown)
87         show "Switching the power off"; busy
88         /lib/nut/upsdrvctl shutdown
89         sleep 60
90         fail
91         ;;
92   status)
93         status upsd
94         RETVAL=$?
95         ;;
96   *)
97         msg_usage "$0 {start|stop|restart|reload|force-reload|status|powerdown}"
98         exit 3
99 esac
100
101 exit $RETVAL
This page took 0.092643 seconds and 3 git commands to generate.