~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to resources/heartbeat/LVSSyncDaemonSwap.in

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2010-02-17 21:59:18 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100217215918-06paxph5do4saw8v
Tags: 3.0.2-0ubuntu1
* New upstream release
* Drop hard dep on pacemaker for heartbet; moved to Recommends
* debian/heartbeat.install:
  - follow upstream changes
* debian/control:
  - added docbook-xsl and xsltproc to build depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
#
4
 
#        Copyright (C) 2005 Horms <horms@verge.net.au>
5
 
#
6
 
#        License:      GNU General Public License (GPL)
7
 
#        Support:      linux-ha@lists.linux-ha.org
8
 
#
9
 
#        This script manages the LVS synchronisation daemon
10
 
#
11
 
#       Please note that as of 2.4.29, this is no longer needed
12
 
#       as both the master and backup daemon can run simultaneously
13
 
#
14
 
#        usage: $0 {master|backup} {interface} {start|stop|status|monitor|cleanup}
15
 
#
16
 
#        The first argument, master or backup, is the YING.
17
 
#        The YANG is internally calculated to be which ever or master and
18
 
#        backup YING is not.
19
 
#
20
 
#       e.g $0 LVSSyncDaemonSwap master start   # YING=master YANG=backup
21
 
#           $0 LVSSyncDaemonSwap backup start   # YING=backup YANG=master
22
 
#               
23
 
#
24
 
#       "start" will stop the YANG if it is running and starts the YING
25
 
#       "stop"  will stop the YING if it is running and starts the YANG
26
 
#       "cleanup" is a non-standard target stop the YING if it is running
27
 
#                 an stop the YANG if it is running 
28
 
#
29
 
#
30
 
#
31
 
unset LANG
32
 
LC_ALL=C
33
 
export LC_ALL
34
 
 
35
 
prefix=@prefix@
36
 
exec_prefix=@exec_prefix@
37
 
. @sysconfdir@/ha.d/shellfuncs
38
 
 
39
 
USAGE="usage: $0 {master|backup} {interface} {start|stop|status|monitor|cleanup}\n\nNote: $0 only works on Linux";
40
 
 
41
 
# This is consistent with ldirectord's behaviour
42
 
# Except that this script does not have a debug mode
43
 
if [ -x "/sbin/ipvsadm" ]; then
44
 
        IPVSADM="/sbin/ipvsadm";
45
 
elif [ -x "/usr/sbin/ipvsadm" ]; then
46
 
        IPVSADM="/usr/sbin/ipvsadm";
47
 
else
48
 
        ha_log "ERROR: Can not find ipvsadm";
49
 
        exit 1
50
 
fi
51
 
 
52
 
IPVSADM_VERSION=$($IPVSADM --version | cut -d " " -f 2)
53
 
 
54
 
get_status() {
55
 
    if echo $PS | grep " \[ipvs[ _]sync$1\]$" > /dev/null; then
56
 
        echo "running"
57
 
        return 3
58
 
    fi
59
 
 
60
 
    echo "stopped"
61
 
    return 0
62
 
}
63
 
 
64
 
status() {
65
 
    echo -n "$1 "
66
 
    get_status $1
67
 
    RC=$?
68
 
 
69
 
    pid=$(echo "$PS" | sed -e '/ \[ipvs[ _]syncmaster\]$/!d' -e 's/^ *//' -e 's/ .*$//')
70
 
    if [ ! -z "$pid" ]; then
71
 
        echo "(ipvs_syncmaster pid: $pid)"
72
 
    fi
73
 
 
74
 
    pid=$(echo "$PS" | sed -e '/ \[ipvs[ _]syncbackup\]$/!d' -e 's/^ *//' -e 's/ .*$//')
75
 
    if [ ! -z "$pid" ]; then
76
 
        echo "(ipvs_syncbackup pid: $pid)"
77
 
    fi
78
 
 
79
 
    return $RC
80
 
}
81
 
 
82
 
run_ipvsadm () {
83
 
    $IPVSADM $@
84
 
    rc=$?
85
 
    if [ $rc -ne 0 ]; then
86
 
        echo "ERROR: ipvsadm $@ failed."
87
 
        return $rc
88
 
    fi
89
 
 
90
 
    return 0
91
 
}
92
 
 
93
 
ying_yan() {
94
 
    if [ "$1" = "master" ]; then
95
 
        echo "backup"
96
 
    else 
97
 
        echo "master"
98
 
    fi
99
 
}
100
 
 
101
 
start_stop() {
102
 
    YING=$1
103
 
    YANG=$2
104
 
 
105
 
    if [ $(get_status $YING) = "running" ]; then
106
 
        return 0
107
 
    fi
108
 
 
109
 
    if [ $(get_status $YANG) = "running" ]; then
110
 
        if [ "$IPVSADM_VERSION" = "v1.21" ]; then
111
 
            run_ipvsadm --stop-daemon || return $?
112
 
        else
113
 
            run_ipvsadm --stop-daemon $YANG || return $?
114
 
        fi
115
 
        ha_log "info: ipvs_sync$YANG down"
116
 
    fi
117
 
 
118
 
    run_ipvsadm --start-daemon $YING --mcast-interface=$IFACE || return $?
119
 
 
120
 
    ha_log "info: ipvs_sync$YING up"
121
 
    return 0
122
 
}
123
 
 
124
 
start() {
125
 
    start_stop $1 $(ying_yan $1) || return $?
126
 
    ha_log "info: ipvs_sync$YING obtained"
127
 
    return 0
128
 
}
129
 
 
130
 
stop() {
131
 
    start_stop $(ying_yan $1) $1 || return $?
132
 
    ha_log "info: ipvs_sync$YANG released"
133
 
    return 0
134
 
}
135
 
 
136
 
cleanup() {
137
 
    if [ $(get_status master) = "running" ]; then
138
 
            YING=master
139
 
    elif [ $(get_status backup) = "running" ]; then
140
 
            YING=backup
141
 
    else
142
 
        return 0
143
 
    fi
144
 
 
145
 
    
146
 
    run_ipvsadm --stop-daemon || return $?
147
 
    if [ "$IPVSADM_VERSION" = "v1.21" ]; then
148
 
        run_ipvsadm --stop-daemon || return $?
149
 
    else
150
 
        run_ipvsadm --stop-daemon $YANG || return $?
151
 
    fi
152
 
    ha_log "info: ipvs_sync$YING down"
153
 
    return 0
154
 
}
155
 
 
156
 
usage() {
157
 
  echo -e $USAGE >&2
158
 
}
159
 
 
160
 
if
161
 
    [ $# -lt 2 -o $# -gt 3 ]
162
 
then
163
 
    usage
164
 
    exit 1
165
 
fi
166
 
 
167
 
PS=$(ps ax | grep " \[ipvs[ _]sync")
168
 
 
169
 
if [ $# -eq 3 ]
170
 
then
171
 
    CMD=$3
172
 
    IFACE=$2
173
 
else
174
 
    CMD=$2
175
 
    IFACE=eth0
176
 
fi
177
 
 
178
 
case $CMD in
179
 
    start)
180
 
        start $1
181
 
        ;;
182
 
    stop)
183
 
        stop $1
184
 
        ;;
185
 
    status)
186
 
        status $1
187
 
        ;;
188
 
    monitor)
189
 
        status $1
190
 
        ;;
191
 
    cleanup)
192
 
        cleanup $1
193
 
        ;;
194
 
    *)
195
 
        usage
196
 
        exit 1
197
 
        ;;
198
 
esac
199
 
 
200
 
exit $?
201