Hi,
On Thu, May 26, 2011 at 10:50:52PM +0200, Lars Ellenberg wrote:
> On Thu, May 26, 2011 at 06:31:16PM +0200, RaSca wrote:
> > 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"
> > ;;
Please use ha_log.sh to log errors. See other external plugins
for examples.
> > esac
> > return 1
> > fi
>
> suggestion:
> ...
> {
> case $1 in
> 200)
> return 0 ;;
> 400)
> echo ... ;;
> ...)
> ...
> 500)
> echo ... ;;
> *)
> # catch all other "unexpected" return codes
> echo "something went wrong, http response code: [$1]"
> ...
> esac
> return 1
> }
>
>
>
>
> > }
> >
> > 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
Replace comments with ha_log.sh calls.
> > 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 $?
>
>
> as this is the last command in your script,
> you could also leave off the exit $?.
> script exit code will be the exit code of the last simple command
> respective the return code of the last function called.
>
> But I think it is ok to leave it in, to make it obvious and explicit
> (and robust against other people editing the script later).
>
> > ;;
> > 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
>
> all these exit 0 are not necessary, actually, as the last command of the
> script will be "echo something", which should have a return value of
> zero, anyways... but see above, to have it explicit and obvious and robust,
> just leave it in.
>
> > ;;
> > 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
> > ;;
> > *)
>
> maybe:
> echo >&2 "Don't know what to do for '$1'"
> or display some usage or URL of wiki page or whatever
Yes, just use ha_log.sh.
Cheers,
Dejan
> > exit 1
> > ;;
> > esac
>
> Thank you!
>
> Lars
>
>
> --
> : Lars Ellenberg
> : LINBIT | Your Way to High Availability
> : DRBD/HA support and consulting http://www.linbit.com
> _______________________________________________________
> Linux-HA-Dev: [email protected]
> http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
> Home Page: http://linux-ha.org/
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/