~ubuntu-branches/ubuntu/saucy/nut/saucy

« back to all changes in this revision

Viewing changes to scripts/RedHat-6.0/upsd.in

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Quette
  • Date: 2004-05-28 13:10:01 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040528131001-yj2m9qcez4ya2w14
Tags: upstream-1.4.2
ImportĀ upstreamĀ versionĀ 1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# chkconfig: 2345 30 90
4
 
#
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
10
 
#
11
 
# description: NUT upsd and its drivers directly monitor a ups and \
12
 
#       make information from it available to other programs
13
 
# processname: upsd
14
 
# config: @sysconfdir@/upsd.conf
15
 
# config: @sysconfdir@/ups.conf
16
 
 
17
 
PATH=/sbin:/bin:/usr/sbin:/usr/bin
18
 
export PATH
19
 
 
20
 
# Source function library.
21
 
. /etc/rc.d/init.d/functions
22
 
 
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
28
 
 
29
 
# if there is no config file, bail out
30
 
[ -f $UPSDCONF ] || exit 0
31
 
 
32
 
runcmd() {
33
 
   echo -n "$1 "
34
 
   shift
35
 
   if [ "$BOOTUP" = "color" ]; then
36
 
      $* && echo_success || echo_failure
37
 
   else
38
 
      $*
39
 
   fi
40
 
   echo
41
 
}
42
 
 
43
 
# See how we are called.
44
 
case "$1" in
45
 
    start)
46
 
        NUM=0
47
 
 
48
 
        if [ -f $UPSCONF ]; then
49
 
            # new style drivers uses 'upsdrvctl'
50
 
            echo -n "NUT starting UPS model drivers: "
51
 
            daemon upsdrvctl start
52
 
            echo
53
 
            if [ $? -eq 0 ]; then
54
 
                NUM=$[ $NUM + 1 ]
55
 
            fi
56
 
        else
57
 
            if [ -f $UPSDCONF ]; then
58
 
                # old style drivers
59
 
                for cmd_line in "`grep '^UPS' $UPSDCONF| cut -d' ' -f4-`"
60
 
                do
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
66
 
                        echo
67
 
                        NUM=$[ $NUM + 1 ]
68
 
                    fi
69
 
                done
70
 
            fi
71
 
        fi
72
 
 
73
 
        if [ $NUM -eq 0 ]; then
74
 
                failure "NUT No UPS drivers were configured"
75
 
                echo
76
 
        else
77
 
                echo -n "NUT Starting UPS daemon: "
78
 
                daemon upsd
79
 
                echo
80
 
                touch /var/lock/subsys/upsd
81
 
        fi
82
 
        ;;
83
 
 
84
 
    stop)
85
 
        echo -n "NUT Stopping UPS daemon: "
86
 
        killproc upsd
87
 
        echo
88
 
 
89
 
        if [ -f $UPSCONF ]; then
90
 
            # new style drivers uses 'upsdrvctl'
91
 
            action "NUT Stopping UPS model drivers" \
92
 
                upsdrvctl stop
93
 
        else
94
 
            if [ -f $UPSDCONF ]; then
95
 
                # old style drivers
96
 
                for DAEMON in `awk '/^UPS/ {print $4}' $UPSDCONF`
97
 
                do
98
 
                    echo -n "NUT Stopping model driver $DAEMON: "
99
 
                    killproc $DAEMON
100
 
                    echo
101
 
                done
102
 
            fi
103
 
        fi
104
 
 
105
 
        rm -f /var/lock/subsys/upsd
106
 
        ;;
107
 
 
108
 
    powerdown)
109
 
        if [ -f $UPSCONF ]; then
110
 
            # new style drivers
111
 
            runcmd "NUT powerdown of attached UPS(es)" upsdrvctl shutdown
112
 
        else
113
 
            if [ -f $UPSDCONF ]; then
114
 
                # old style drivers
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  *[^ ][^ ]*  *[^ ][^ ]*  *//'`"
122
 
                    do
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
128
 
                        fi
129
 
                    done
130
 
                fi
131
 
            fi
132
 
        fi
133
 
        ;;
134
 
 
135
 
    restart)
136
 
        $0 stop
137
 
        $0 start
138
 
        ;;
139
 
 
140
 
    status)
141
 
        if [ -f $UPSCONF ]; then
142
 
            # new style drivers
143
 
            action "NUT: checking UPS model drivers" upsdrvctl status
144
 
        else
145
 
            if [ -f $UPSDCONF ]; then
146
 
                # old style drivers
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
149
 
                    status $DAEMON
150
 
                done
151
 
            fi
152
 
        fi
153
 
 
154
 
        status upsd
155
 
        ;;
156
 
    *)
157
 
        echo "Usage: upsd {start|stop|powerdown|restart|status}"
158
 
        exit 1
159
 
esac
160