]> git.pld-linux.org Git - packages/nut.git/blame - nut.init
- release 2
[packages/nut.git] / nut.init
CommitLineData
eca6ebe0
SZ
1#!/bin/sh
2#
3# ups NUT - Network UPS Tools daemon
4#
5# chkconfig: 2345 10 90
6#
f57bb155 7# description: The ups daemon monitors an UPS and makes information about \
b9f08db8 8# it's status available to other programs
eca6ebe0
SZ
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
4257d08d 25if [ -n "$BIND_ADDRESS" ] || [ -n "$TCP_PORT" ]; then
26 # Check that networking is up.
27 if is_yes "${NETWORKING}"; then
7fdb4c2e 28 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
d5b98fd6 29 msg_network_down "UPS network daemon"
4257d08d 30 exit 1
31 fi
32 else
33 exit 0
34 fi
35fi
36
be0db874 37RETVAL=0
eca6ebe0
SZ
38# See how we are called.
39case "$1" in
40 start)
41 # Check if the service is already running?
42 if [ ! -f /var/lock/subsys/ups ]; then
b9f08db8 43 show "Starting UPS drivers"
7b1ed25c 44 daemon /lib/nut/upsdrvctl start
b9f08db8 45 RETVAL=$?
46 if [ $RETVAL -eq 0 ]; then
3132bf7d
TO
47 msg_starting "UPS network daemon"
48 daemon "upsd $OPTIONS"
49 RETVAL=$?
50 touch /var/lock/subsys/ups
51 fi
eca6ebe0 52 else
b9f08db8 53 msg_already_running "UPS drivers and network daemon"
eca6ebe0
SZ
54 fi
55 ;;
56 stop)
b9f08db8 57 if [ -f /var/lock/subsys/ups ]; then
eca6ebe0
SZ
58 msg_stopping "UPS daemon"
59 killproc upsd
7b1ed25c 60 run_cmd "Stopping UPS drivers" /lib/nut/upsdrvctl stop
eca6ebe0
SZ
61 rm -f /var/lock/subsys/ups
62 else
b9f08db8 63 msg_not_running "UPS daemon"
eca6ebe0
SZ
64 fi
65 ;;
66 restart)
67 $0 stop
68 $0 start
be0db874 69 exit $?
eca6ebe0 70 ;;
be0db874 71 reload|force-reload)
4257d08d 72 if [ -f /var/lock/subsys/ups ]; then
73 show "Reloading UPS drivers"
7b1ed25c 74 daemon /lib/nut/upsdrvctl reload
be0db874 75 [ $? -ne 0 ] && RETVAL=7
4257d08d 76 msg_reloading "UPS network daemon"
77 daemon upsd -c reload
be0db874 78 [ $? -ne 0 ] && RETVAL=7
4257d08d 79 else
be0db874 80 msg_not_running "UPS daemon" >&2
81 exit 7
4257d08d 82 fi
b9f08db8 83 ;;
7b1ed25c
JK
84 powerdown)
85 show "Switching the power off" ; busy
86 /lib/nut/upsdrvctl shutdown
87 sleep 60
88 fail
89 ;;
eca6ebe0
SZ
90 status)
91 status upsd
be0db874 92 RETVAL=$?
7b1ed25c 93 /lib/nut/upsdrvctl status
eca6ebe0
SZ
94 ;;
95 *)
7b1ed25c 96 msg_usage "$0 {start|stop|restart|reload|force-reload|status|powerdown}"
be0db874 97 exit 3
ea3b71f3 98esac
eca6ebe0 99
b9f08db8 100exit $RETVAL
This page took 0.076055 seconds and 4 git commands to generate.