Il giorno Mar 24 Mag 2011 16:10:17 CET, Lars Ellenberg ha scritto:
[...]
        exit $((! $?))
That is going to invert the code.
the shell has ! for that.
        ! is_host_up
Coffee?
  ;-)

Ok, following your suggestions I've modified (and tested, of course) the script. Compacting as much as I can. But Lars, sorry how didn't find out how to compact this:

         is_host_up "$remote_ip"
         exit $((! $?))

in this:

        exit ! is_host_up "$remote_ip"

:-(

Anyway, now I've got a deeper problem: I was totally misunderstanding what's the status field of the curl interrogation was meant for. So I corrected the is_host_up function, making it check (similar to ssh stonith agent) via nc if the ssh port is responding:

is_host_up() {
      /bin/nc -w 1 -z $1 22 > /dev/null 2>&1
      return $?
}

This sounds quite weird to me, but I can't do ping, and I can't control the state of the machine otherwise. I can only force the reset and then check if the machine is up. If you have any suggestions on how to make things better, don't hesitate...

Beyond all, it works. I set up a variable which is the timeout to wait before check the machine status. It can become a parameter.

The new version is attached.

--
RaSca
Mia Mamma Usa Linux: Niente รจ impossibile da capire, se lo spieghi bene!
ra...@miamammausalinux.org
http://www.miamammausalinux.org

#!/bin/sh
#
# External STONITH module for Hetzner.
#
# Copyright (c) 2011 MMUL S.a.S. - Raoul Scarazzini <ra...@mmul.it>
#
# 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
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";
wait_timeout=15

is_host_up() {
     /bin/nc -w 1 -z $1 22 > /dev/null 2>&1
     return $?
}

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)
        curl -s -u $user:$pass $hetzner_server/reset/$remote_ip -d type=hw > 
/dev/null 2>&1
        sleep $wait_timeout
        is_host_up "$remote_ip"
        exit $((! $?)) 
        ;;
status)
        is_host_up "$remote_ip"
        exit $?
        ;;
getconfignames)
        echo "hostname"
        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: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to