This file is indexed.

/usr/lib/stonith/plugins/external/libvirt is in cluster-glue 1.0.8-2ubuntu6.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/sh
#
# External STONITH module for a libvirt managed hypervisor (kvm/Xen).
# Uses libvirt as a STONITH device to control guest.
#
# Copyright (c) 2010 Holger Teutsch <holger.teutsch@web.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like.  Any license provided herein, whether implied or
# otherwise, applies only to this software file.  Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

# start a domain
libvirt_start() {
    out=$($VIRSH -c $hypervisor_uri start $domain_id 2>&1)
    if [ $? -eq 0 ]
    then
        ha_log.sh notice "Domain $domain_id was started"
        return 0
    fi

    if echo "$out" | grep -i 'Domain is already active' > /dev/null 2>&1
    then
        ha_log.sh notice "Domain $domain_id is already active"
        return 0
    fi

    ha_log.sh err "Failed to start domain $domain_id"
    ha_log.sh err "$out"
    return 1
}

# stop a domain
# return
#   0: success
#   1: error
#   2: was already stopped
libvirt_stop() {
    out=$($VIRSH -c $hypervisor_uri destroy $domain_id 2>&1)
    if [ $? -eq 0 ]
    then
        ha_log.sh notice "Domain $domain_id was stopped"
        return 0
    fi

    if echo "$out" | grep -i 'domain is not running' > /dev/null 2>&1
    then
        ha_log.sh notice "Domain $domain_id is already stopped"
        return 2
    fi

    ha_log.sh err "Failed to stop domain $domain_id"
    ha_log.sh err "$out"
    return 1
}

# get status of stonith device (*NOT* of the domain).
# If we can retrieve some info from the hypervisor
# the stonith device is OK.
libvirt_status() {
    out=$($VIRSH -c $hypervisor_uri version 2>&1)
    if [ $? -eq 0 ]
    then
        out=`echo "$out" | tail -1`
        ha_log.sh notice "$hypervisor_uri: $out"
        return 0
    fi

    ha_log.sh err "Failed to get status for $hypervisor_uri"
    ha_log.sh err "$out"
    return 1
}

# check config and set variables
# does not return on error
libvirt_check_config() {
    VIRSH=`which virsh 2>/dev/null`

    if [ ! -x "$VIRSH" ]
    then
        ha_log.sh err "virsh not installed"
        exit 1
    fi

    if [ -z "$hostlist" -o -z "$hypervisor_uri" ]
    then
        ha_log.sh err "hostlist or hypervisor_uri missing; check configuration"
        exit 1
    fi
}

# set variable domain_id for the host specified as arg
libvirt_set_domain_id ()
{
    for h in $hostlist
    do
        case $h in
            $1:*)
            domain_id=`expr $h : '.*:\(.*\)'`
            return
            ;;

            $1)
            domain_id=$1
            return
        esac
    done

    ha_log.sh err "Should never happen: Called for host $1 but $1 is not in $hostlist."
    exit 1
}

libvirt_info() {
cat << LVIRTXML
<parameters>
<parameter name="hostlist" unique="1" required="1">
<content type="string" />
<shortdesc lang="en">
List of hostname[:domain_id]..
</shortdesc>
<longdesc lang="en">
List of controlled hosts: hostname[:domain_id]..
The optional domain_id defaults to the hostname. 
</longdesc>
</parameter>

<parameter name="hypervisor_uri" required="1">
<content type="string" />
<shortdesc lang="en">
Hypervisor URI
</shortdesc>
<longdesc lang="en">
URI for connection to the hypervisor.
driver[+transport]://[username@][hostlist][:port]/[path][?extraparameters]
e.g.
qemu+ssh://my_kvm_server.mydomain.my/system   (uses ssh for root)
xen://my_kvm_server.mydomain.my/              (uses TLS for client)

virsh must be installed (e.g. libvir-client package) and access control must
be configured for your selected URI.
</longdesc>
</parameter>
</parameters>
LVIRTXML
exit 0
}

#############
# Main code #
#############

# don't fool yourself when testing with stonith(8)
# and transport ssh
unset SSH_AUTH_SOCK

# support , as a separator as well
hostlist=`echo $hostlist| sed -e 's/,/ /g'`

case $1 in
    gethosts)
    hostnames=`echo $hostlist|sed -e 's/:[^ ]*//g'`
    for h in $hostnames
    do
        echo $h
    done
    exit 0
    ;;

    on)
    libvirt_check_config
    libvirt_set_domain_id $2

    libvirt_start
    exit $?
    ;;

    off)
    libvirt_check_config
    libvirt_set_domain_id $2

    libvirt_stop
    [ $? = 1 ] && exit 1
    exit 0
    ;;

    reset)
    # libvirt has no reset so we do a power cycle
    libvirt_check_config
    libvirt_set_domain_id $2

    libvirt_stop
    rc=$?
    [ $rc = 1 ] && exit 1

    # stonith reset seems to require a power on even if it was off
    # before so the next line is commented out
    # [ $rc = 2 ] && exit 0

    sleep 2
    libvirt_start
    exit $?
    ;;

    status)
    libvirt_check_config
    libvirt_status
    exit $?
    ;;

    getconfignames)
    echo "hostlist hypervisor_uri"
    exit 0
    ;;

    getinfo-devid)
    echo "libvirt STONITH device"
    exit 0
    ;;

    getinfo-devname)
    echo "libvirt STONITH external device"
    exit 0
    ;;

    getinfo-devdescr)
    echo "libvirt-based Linux host reset for Xen/KVM guest domain through hypervisor"
    exit 0
    ;;

    getinfo-devurl)
    echo "http://libvirt.org/uri.html http://linux-ha.org/wiki"
    exit 0
    ;;

    getinfo-xml)
    libvirt_info
    echo 0;
    ;;

    *)
    exit 1
    ;;
esac