3
# chkconfig: 2345 30 90
5
# 2002-02-07 Nigel Metheringham <Nigel.Metheringham@InTechnology.co.uk>
6
# made ups.conf pre-eminant, added new upsdrvctl functions, targeted for RH7.2, should
7
# work OK on RH 6.x, 7.x
8
# 2001-10-24 Peter Bieringer <pb@bieringer.de>
9
# enhancements for new style drivers and controls, tested on a RHL 7.1.93 system
11
# description: NUT upsd and its drivers directly monitor a ups and \
12
# make information from it available to other programs
14
# config: @sysconfdir@/upsd.conf
15
# config: @sysconfdir@/ups.conf
17
PATH=/sbin:/bin:/usr/sbin:/usr/bin
20
# Source function library.
21
. /etc/rc.d/init.d/functions
23
# POWERDOWNFLAG *must* match that in upsmon.conf
24
DRIVERPATH=@MODELPATH@
25
POWERDOWNFLAG=/etc/killpower
26
UPSDCONF=@sysconfdir@/upsd.conf
27
UPSCONF=@sysconfdir@/ups.conf
29
# if there is no config file, bail out
30
[ -f $UPSDCONF ] || exit 0
35
if [ "$BOOTUP" = "color" ]; then
36
$* && echo_success || echo_failure
43
# See how we are called.
48
if [ -f $UPSCONF ]; then
49
# new style drivers uses 'upsdrvctl'
50
echo -n "NUT starting UPS model drivers: "
51
daemon upsdrvctl start
57
if [ -f $UPSDCONF ]; then
59
for cmd_line in "`grep '^UPS' $UPSDCONF| cut -d' ' -f4-`"
61
if [ -n "$cmd_line" ]; then
62
DAEMON=`echo $cmd_line | cut -d' ' -f1`
63
ARGUMENTS=`echo $cmd_line | cut -d' ' -f2-`
64
echo -n "NUT Starting model driver $DAEMON: "
65
daemon $DRIVERPATH/$DAEMON $ARGUMENTS
73
if [ $NUM -eq 0 ]; then
74
failure "NUT No UPS drivers were configured"
77
echo -n "NUT Starting UPS daemon: "
80
touch /var/lock/subsys/upsd
85
echo -n "NUT Stopping UPS daemon: "
89
if [ -f $UPSCONF ]; then
90
# new style drivers uses 'upsdrvctl'
91
action "NUT Stopping UPS model drivers" \
94
if [ -f $UPSDCONF ]; then
96
for DAEMON in `awk '/^UPS/ {print $4}' $UPSDCONF`
98
echo -n "NUT Stopping model driver $DAEMON: "
105
rm -f /var/lock/subsys/upsd
109
if [ -f $UPSCONF ]; then
111
runcmd "NUT powerdown of attached UPS(es)" upsdrvctl shutdown
113
if [ -f $UPSDCONF ]; then
115
# what fun - cut is in /usr/bin, we'll use awk & sed
116
# we also use runcmd - action needs things not available at this stage
117
# the first part of the sed replaces tabs with spaces
118
# - mind the raw tab in this script
119
if [ -f $POWERDOWNFLAG ]; then
120
for cmd_line in "`grep '^UPS' $UPSDCONF |\
121
sed -e 'y/ / /;s/^UPS *[^ ][^ ]* *[^ ][^ ]* *//'`"
123
if [ -n "$cmd_line" ]; then
124
DAEMON=`echo $cmd_line | awk '{print $1}'`
125
# Arguments are munged to insert -k before device name (last arg)
126
ARGUMENTS=`echo $cmd_line | sed -e 's/^[^ ][^ ]* *//;s/\( *[^ ][^ ]* *\)$/ -k \1/'`
127
runcmd "NUT Powerdown model driver $DAEMON" $DRIVERPATH/$DAEMON -d0 $ARGUMENTS
141
if [ -f $UPSCONF ]; then
143
action "NUT: checking UPS model drivers" upsdrvctl status
145
if [ -f $UPSDCONF ]; then
147
# ugh - this is painful - maybe it should all be made one function to do this parsing
148
for DAEMON in `awk '/^UPS/ {print $4}' $UPSDCONF`; do
157
echo "Usage: upsd {start|stop|powerdown|restart|status}"