Thanks Dejan, I have it working now. I realised that the binaries were in a custom path and that it had been added to user shell profiles, including root (hence the reason the script worked when ran manually). So I added the path manually in this script and then exported.


--
Regards

James Little

Loadbalancer.org Limited
+44 (0)870 443 8779
www.loadbalancer.org



On 3 Dec 2008, at 21:44, Dejan Muhamedagic wrote:

Hi,

On Tue, Dec 02, 2008 at 04:33:21PM +0800, James Little wrote:
Thanks for the reply Dejan. I've added code for the status action but still
no luck. So my script is now:

###################################################################################################
usage() {
   echo "usage: $0 start|stop"
   exit 1
}
associate() {
   CURRENT_IP=`curl -s
http://169.254.169.254/latest/meta-data/public-ipv4`
ELASTIC_IP=`head -n 1 /etc/loadbalancer.org/aws/elasticip | tr - d '\n'`
   if [ "$CURRENT_IP" != "$ELASTIC_IP" ]; then
       INSTANCE_ID=`curl -s
http://169.254.169.254/latest/meta-data/instance-id`
ec2-associate-address -i $INSTANCE_ID $ELASTIC_IP > /dev/ null 2>&1
& #re-associate the elastic ip with THIS instance
       exit 0

You should check the exit status or the status to make sure that
the resource has really been started. Or do you expect this never
to fail ;-)

   else #do nothing and exit, as associating twice causes problems!
       exit 0
   fi
}
disassociate() {
ELASTIC_IP=`head -n 1 /etc/loadbalancer.org/aws/elasticip | tr - d '\n'`
   ec2-disassociate-address $ELASTIC_IP > /dev/null 2>&1 &
sleep 3 #put a small delay in to make sure that this IP will definitely
be disassociated by the time '$0 start' runs
   exit 0

The same here: Check if the resource has been stopped.

}

get_status() {
   CURRENT_IP=`curl -s
http://169.254.169.254/latest/meta-data/public-ipv4`
ELASTIC_IP=`head -n 1 /etc/loadbalancer.org/aws/elasticip | tr - d '\n'`
   if [ "$CURRENT_IP" = "$ELASTIC_IP" ]; then
       echo "Elastic IP Running OK"
       exit 0
   else
       echo "Elastic IP is stopped."
       exit 0
   fi

}

if [ $# != 1 ]; then
   usage
fi

case "$1" in
"start" ) associate;;
"stop"  ) disassociate;;
"status" ) get_status;;
*       ) usage;;
esac

####################################################################################################

here is a section of the heartbeat log:


heartbeat[23277]: 2008/12/02_03:24:47 info: Comm_now_up(): updating status
to active
heartbeat[23277]: 2008/12/02_03:24:47 info: Local status now set to:
'active'
heartbeat[23277]: 2008/12/02_03:24:47 WARN: No STONITH device configured. heartbeat[23277]: 2008/12/02_03:24:47 WARN: Shared disks are not protected. heartbeat[23277]: 2008/12/02_03:24:47 info: Resources being acquired from
lbslave.
harc[23286]: 2008/12/02_03:24:47 info: Running /etc/ha.d/rc.d/ status status mach_down[23315]: 2008/12/02_03:24:47 info: /usr/share/heartbeat/ mach_down:
nice_failback: foreign resources acquired
mach_down[23315]: 2008/12/02_03:24:47 info: mach_down takeover complete for
node lbslave.
heartbeat[23277]: 2008/12/02_03:24:47 info: mach_down takeover complete. heartbeat[23277]: 2008/12/02_03:24:47 info: Initial resource acquisition
complete (mach_down)
heartbeat[23287]: 2008/12/02_03:24:47 info: Local Resource acquisition
completed.
harc[23377]:    2008/12/02_03:24:47 info: Running
/etc/ha.d/rc.d/ip-request-resp ip-request-resp
ip-request-resp[23377]: 2008/12/02_03:24:47 received ip-request-resp
elastic OK yes
ResourceManager[23398]: 2008/12/02_03:24:47 info: Acquiring resource group:
lbmaster elastic
ResourceManager[23398]: 2008/12/02_03:24:47 info: Running
/etc/ha.d/resource.d/elastic  start

It looks like it is started. Perhaps try again from scratch.
Add some debugging in the script to verify that heartbeat really
invokes the start action.

Thanks,

Dejan

heartbeat[23277]: 2008/12/02_03:24:57 info: Local Resource acquisition
completed. (none)
heartbeat[23277]: 2008/12/02_03:24:57 info: local resource transition
completed.


As before, If I run '/etc/ha.d/resource.d/elastic start' manually, then
the script works as expected. My haresources is simply:
        master elastic

where master is the local hostname.




--
Regards

James Little

Loadbalancer.org Limited
+44 (0)870 443 8779
www.loadbalancer.org



On 1 Dec 2008, at 21:19, Dejan Muhamedagic wrote:

Hi,

On Mon, Dec 01, 2008 at 01:47:56PM +0800, James Little wrote:
Hi all,

I'm currently working with heartbeat in the Amazon cloud and (for those
that are familiar with Amazon EC2), I'm trying to use heartbeat to
re-allocate an elastic IP on detection of node failure. I'm not
experienced
with writing my own heartbeat resource scripts, but this is what I have:

usage() {
  echo "usage: $0 start|stop"
  exit 1
}
associate() {
  CURRENT_IP=`curl -s
http://169.254.169.254/latest/meta-data/public-ipv4`
  ELASTIC_IP=`head -n 1 /etc/loadbalancer.org/aws/elasticip | tr -d
'\n'`
  if [ "$CURRENT_IP" != "$ELASTIC_IP" ]; then
      INSTANCE_ID=`curl -s
http://169.254.169.254/latest/meta-data/instance-id`
ec2-associate-address -i $INSTANCE_ID $ELASTIC_IP > /dev/ null 2>&1
& #re-associate the elastic ip with THIS instance
      exit 0
  else #do nothing and exit, as associating twice causes problems!
      exit 0
  fi
}
disassociate() {
  ELASTIC_IP=`head -n 1 /etc/loadbalancer.org/aws/elasticip | tr -d
'\n'`
  ec2-disassociate-address $ELASTIC_IP > /dev/null 2>&1 &
  sleep 3 #put a small delay in to make sure that this IP will
definitely
be disassociated by the time '$0 start' runs
  exit 0
}

if [ $# != 1 ]; then
  usage
fi

case "$1" in
"start" ) associate;;
"stop"  ) disassociate;;
*       ) usage;;
esac


The RA must support the status action. You already have code for
it in the start action. See:

http://www.linux-ha.org/HeartbeatResourceAgent

Thanks,

Dejan


and I've simply put this script in /etc/ha.d/resource.d. The script
definitely runs (via heartbeat) and I have put some debug stuff in to
confirm this (piping output to files etc.) but for some reason the
ec2-associate-address and ec2-disassociate-address commands have no
effect,
but when tested manually these commands work ok. In fact this whole
script,
when ran manually, behaves as expected. The heartbeat log indicates that
the script has ran.

I'm running heartbeat v2.1.3, but have not enabled CRM. I did think it
may
be a timeout because the ec2 commands take a few seconds to run, but I
tested a trivial resource script that did 'sleep 10; echo 'stuff' >
test-file' and that ran without problems, despite the 10 second sleep.


Any help greatly appreciated; thanks in advance...



--
Regards

James Little

Loadbalancer.org Limited
+44 (0)870 443 8779
www.loadbalancer.org



_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

Reply via email to