Il giorno Gio 26 Mag 2011 11:13:46 CET, RaSca ha scritto:
[...]
The new version is attached.
Hi all,
After talking with Dejan on IRC, here it is the new version of the agent.
Major changes:
- The script do not relies anymore on SSH for checking the correct fence
of the device, instead it checks the http response code from the webservice;
- The status action looks for a 200 response from the webservice in
"GET" mode;
- In case of problems, the return code of the RA is 1 and I also added a
description of the problem (check_http_response function);
That's all, last but not least, it works.
To make things perfect I just ask to Lars (following two days ago
discussion) if there's a way to compact this:
check_http_response $(curl --silent -o /dev/null -w
'%{http_code}' -u $user:$pass $hetzner_server/reset/$remote_ip -d type=hw)
exit $?
to a one line statement.
Thanks everybody for the help,
--
RaSca
Mia Mamma Usa Linux: Niente รจ impossibile da capire, se lo spieghi bene!
[email protected]
http://www.miamammausalinux.org
#!/bin/sh
#
# External STONITH module for Hetzner.
#
# Copyright (c) 2011 MMUL S.a.S. - Raoul Scarazzini <[email protected]>
#
# 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
# Read parameters from config file, format is based upon the hetzner OCF
resource agent
# developed by Kumina:
http://blog.kumina.nl/2011/02/hetzner-failover-ip-ocf-script/
conf_file="/etc/hetzner.cfg"
user=`sed -n 's/^user.*=\ *//p' /etc/hetzner.cfg`
pass=`sed -n 's/^pass.*=\ *//p' /etc/hetzner.cfg`
hetzner_server="https://robot-ws.your-server.de"
check_http_response() {
# If the response is 200 then return 0
if [ "$1" = "200" ]
then
return 0
else
# If the response is not 200 then display a description of the problem
and return 1
case "$1" in
"400") echo "INVALID_INPUT - Invalid input parameters"
;;
"404") echo "SERVER_NOT_FOUND - Server with ip $remote_ip not found"
;;
"409") echo "RESET_MANUAL_ACTIVE - There is already a running manual
reset"
;;
"500") echo "RESET_FAILED - Resetting failed due to an internal error"
;;
esac
return 1
fi
}
case $1 in
gethosts)
echo $hostname
exit 0
;;
on)
# Can't really be implemented because Hetzner webservice cannot power
on a system
exit 1
;;
off)
# Can't really be implemented because Hetzner webservice cannot power
on a system
exit 1
;;
reset)
# Launching the reset action via webservice
check_http_response $(curl --silent -o /dev/null -w '%{http_code}' -u
$user:$pass $hetzner_server/reset/$remote_ip -d type=hw)
exit $?
;;
status)
# Check if we can contact the webservice
check_http_response "$(curl --silent -o /dev/null -w '%{http_code}' -u
$user:$pass $hetzner_server/server/$remote_ip)"
exit $?
;;
getconfignames)
echo "hostname"
echo "remote_ip"
exit 0
;;
getinfo-devid)
echo "Hetzner STONITH device"
exit 0
;;
getinfo-devname)
echo "Hetzner STONITH external device"
exit 0
;;
getinfo-devdescr)
echo "Hetzner host reset"
echo "Manages the remote webservice for reset a remote server."
exit 0
;;
getinfo-devurl)
echo "http://wiki.hetzner.de/index.php/Robot_Webservice_en"
exit 0
;;
getinfo-xml)
cat << HETZNERXML
<parameters>
<parameter name="hostname" unique="1">
<content type="string" />
<shortdesc lang="en">
Hostname
</shortdesc>
<longdesc lang="en">
The name of the host to be managed by this STONITH device.
</longdesc>
</parameter>
<parameter name="remote_ip" unique="1" required="1">
<content type="string" />
<shortdesc lang="en">
Remote IP
</shortdesc>
<longdesc lang="en">
The address of the remote IP that manages this server.
</longdesc>
</parameter>
</parameters>
HETZNERXML
exit 0
;;
*)
exit 1
;;
esac
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/