[Linux-HA] Cannot use spaces in haresources script arguments?

Thomas Guyot-Sionnest Thomas at zango.com
Wed Mar 29 08:30:01 MST 2006


Have you tried using ${IFS} instead of spaces?

I'm not sure it will work, but in bash ${IFS} expands to a space by default.


You might as well use variable names in haressources, and in your script you 
source a config file where you map those variables to the names you need.

In /etc/ha.d/haresource:
Node1 1.2.3.4 virtual_machine::profilea

/etc/ha.d/resources/virtual_machine:
---------------
#!/bin/sh

. /etc/ha.d/conf/virtual_machine.conf

# Do your job here, replace $1 with $profilea
[...]
---------------

/etc/ha.d/conf/virtual_machine.conf
---------------
profilea="/drbd1/Test virtual machine/Test virtual machine.vmx"
---------------


Thomas

> -----Original Message-----
> From: linux-ha-bounces at lists.linux-ha.org
> [mailto:linux-ha-bounces at lists.linux-ha.org] On Behalf Of
> Chris de Vidal
> Sent: March 28, 2006 10:41
> To: linux-ha at lists.linux-ha.org
> Subject: [Linux-HA] Cannot use spaces in haresources script arguments?
>
> Debian 3.1
> Heartbeat 1.2.3-9sarge4
>
> Wonderful program!
>
>
> I wrote a custom script to start some VMware virtual machines
> (pasted at the bottom).  Heartbeat
> starts AND stops the VMs when there are no spaces in the
> script argument.  But when I have spaces
> Heartbeat fails to either start or stop the VMs.
>
> When I execute the script manually, it works.  I can use
> either double-quotes or escaped spaces.
>
>
> * I've tried wrapping the argument in double-quotes.
> * I've tried to escape the spaces with a backslash ('\ ').
> When I do both of those, it doesn't even pass the whole argument.
>
> * I've tried replacing the spaces with double-colons ::.
> This passes the whole argument, at least...
>
> * I've tried escaping the double-colons ('\::').
> * I've tried double-escaping the double-colons ('\\::').
> * I've tried putting double-quotes around single-escaped
> double-colons.
> * I've tried no-escaped double-colons and double-quotes
> around the argument.
> * I've tried no-escaped double-colons and single-escaped
> double-quotes (which is where I am now).
>
> Argggg!
>
>
> Here's my current haresources lines.  As you can see, I'm
> back to escaped double-quotes and
> double-colons:
> JaxFLCl02Nd01 172.19.2.50 drbddisk::drbd1
> Filesystem::/dev/drbd1::/drbd1::ext3
> virtual_machine::/drbd1/JaxFLArch01/JaxFLArch01.vmx
> virtual_machine::\"/drbd1/Test::virtual::machine/Test::virtual
> ::machine.vmx\"
> JaxFLCl02Nd02 172.19.2.51 drbddisk::drbd2
> Filesystem::/dev/drbd2::/drbd2::ext3
> virtual_machine::/drbd2/Puppy/Puppy.vmx
>
>
>
> When I do a failover, I see this in the logs:
> heartbeat: info: Running /etc/ha.d/resource.d/virtual_machine
> \"/drbd1/Test virtual machine/Test
> virtual machine.vmx\" stop
> heartbeat: info: Retrying failed stop operation
> [virtual_machine::\"/drbd1/Test::virtual::machine/Test::virtua
> l::machine.vmx\"]
> heartbeat: info: Running /etc/ha.d/resource.d/virtual_machine
> \"/drbd1/Test virtual machine/Test
> virtual machine.vmx\" stop
> heartbeat: WARN: it
> (virtual_machine::\"/drbd1/Test::virtual::machine/Test::virtua
> l::machine.vmx\") MUST succeed on a
> stop when already stopped
> heartbeat: WARN: Machine reboot narrowly avoided!
>
>
>
> (BUT when I run it manually, I get a zero exit code.  If you
> study my script, you'll see it exits
> 0 at the bottom.)
>
>
>
>
> Here's what I see on the other node:
> heartbeat: info: Running /etc/ha.d/resource.d/virtual_machine
> \"/drbd1/Test virtual machine/Test
> virtual machine.vmx\" start
>
>
>
> (BUT the virtual machine does not start!)
>
>
>
> I hate to use the "B" word, but is this a "BUG" in Heartbeat?
>  The script works perfectly when run
> manually and I've exhausted every option I can think of...
>
>
>
>
>
>
> The script:
>
>
> #!/bin/bash
>
> if [ -n "$1" ]
>         then
>         VMNAME="$1"
>         PARTITION=$(echo "$VMNAME" | /usr/bin/awk -F '/' '{
> print "/" $2; }')
>         fi # if [-n...
>
> case "$2" in
>     start)
>         # Look and see if our partition has been mounted yet...
>         for ((counter=1;counter<=60;counter++))
>                 do
>                 if `mount | grep -q $PARTITION`
>                         then
>                         break # It's mounted, stop waiting
>                         else
>                         sleep 1
>                         fi # if `mount...
>                 done # for ((counter...
>
>         # Register this VM to this server (in case it is not)
>         /usr/bin/vmware-cmd -s register "$VMNAME" &> /dev/null
>
>         # Kick it off
>         /usr/bin/vmware-cmd "$VMNAME" start 2>/dev/null
>
>         # Capture the exit status
>         EXIT_STATUS=$?
>
>         # It might be asking if we want to keep the
> identifier (answer 4)
>         echo 4 | /usr/bin/vmware-cmd "$VMNAME" answer &> /dev/null
>
>         exit $EXIT_STATUS
>         ;;
>     stop)
>         /usr/bin/vmware-cmd "$VMNAME" stop trysoft 2> /dev/null
>         ;;
>     status)
>         if `/usr/bin/vmware-cmd "$VMNAME" getstate
> 2>/dev/null | grep -q "getstate() = on"`
>                 then
>                 echo "running"
>                 else
>                 echo "stopped"
>                 fi # if `/usr/bin/vmware-cmd...
>         ;;
>     *)
>         echo "Usage: `basename $0` <virtual machine file>
> {start|stop|status}"
>         echo "Where <virtual machine file> is like
> /drbdX/VirtualMachine/VirtualMachine.vmx"
>         exit 1
>         ;;
> esac # case "$2"...
>
> exit 0
> _______________________________________________
> Linux-HA mailing list
> Linux-HA at lists.linux-ha.org
> http://lists.linux-ha.org/mailman/listinfo/linux-ha
> See also: http://linux-ha.org/ReportingProblems
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3022 bytes
Desc: not available
Url : http://lists.community.tummy.com/pipermail/linux-ha/attachments/20060329/97108bce/smime.bin


More information about the Linux-HA mailing list