Re: [Linux-ha-dev] New STONITH plug-in to be usable by Xen and KVM

2010-12-23 Thread Dejan Muhamedagic
Hi Yasumasa-san,

On Wed, Dec 22, 2010 at 05:58:34PM +0900, Yasumasa OZAKI wrote:
 Hi Dejan,

 I'm sorry I'm late.

NP.

 I took your advice, and corrected a plug-in, so it's sent.

 By the way, Holger made a similar plug-in, but how should I do?

Yes, Holger's plugin looks good to me. Your plugin uses ssh
explicitely whereas the other one relies on whatever protocol is
setup for libvirt (which can also be ssh, of course). There's
also the dump function in your plugin. I think that it would be
best if you implement that parameter for the Holger's plugin.

Cheers,

Dejan

 Best regards,
 Yasumasa OZAKI

 (2010/09/30 19:38), Yasumasa OZAKI wrote:
 Hi Dejan,

 Thank you for reply.

 I correct it based on your opinion because I think that your opinion is
 correct. wait a little, please.

 - The stop of the domain is judged from the virsh returns, and
 CheckIfDead function is removed.

 - RunCommand function does, and shortens the refactoring.

 - Other points are corrected based on your opinion.

 Thanks,
 Yasumasa OZAKI

 On Thu, 23 Sep 2010 17:08:12 +0200, Dejan Muhamedagic wrote:
 Hi Yasumasa-san,

 On Fri, Sep 10, 2010 at 03:17:56PM +0900, Yasumasa OZAKI wrote:
 Hi,

 I made the STONITH plug-in that can be used by both Xen and KVM.

 Thanks! Comments below.

 I would like to hear any opinion.

 Best regards,
 Yasumasa OZAKI




 #!/bin/sh
 #
 # External STONITH module for Xen/KVM hypervisor through ssh.
 # Uses Xen/KVM hypervisor as a STONITH device to control guest.
 #
 # Copyright (c) 2010 NIPPON TELEGRAPH AND TELEPHONE CORPORATION
 #

 STOP_COMMAND=virsh destroy
 START_COMMAND=virsh start
 DUMP_COMMAND=virsh dump
 SSH_COMMAND=/usr/bin/ssh -q -x -n

 # Rewrite the hostlist to accept , as a delimeter for hostnames too.
 hostlist=`echo $hostlist | tr ',' ' '`

 CheckIfDead() {
  for j in 1 2 3 4 5
  do
  if ! ping -w1 -c1 $1/dev/null 21
  then
  return 0
  fi
  sleep 1
  done

  return 1
 }

 I'd rather have this one removed. If virsh returns a meaningful
 exit code, then we can rely on that, right? Or use domstate?

 CheckHostList() {
  if [ x = x$hostlist ]
  then
  ha_log.sh err hostlist isn't set
  exit 1
  fi
 }

 CheckHypervisor() {
  if [ x = x$hypervisor ]
  then
  ha_log.sh err hypervisor isn't set
  exit 1
  fi
 }

 RunCommand() {
  CheckHostList
  CheckHypervisor

  for node in $hostlist
  do
  if [ $node != $1 ]
  then
  continue
  fi

 You can abbreviate code like this into a more compact

 [ $node != $1 ]  continue

  case $2 in
  stop)
  if [ x$run_dump != x ]
  then
  #Need to run core dump
  if [ x$dump_dir != x ]
  then
  TIMESTAMP=`date +%Y-%m%d-%H%M.%S`
  DOMAINNAME=`printf %s $node`
  COREFILE=$dump_dir/$TIMESTAMP-$DOMAINNAME.core
  #Run core dump
  command_result=$($SSH_COMMAND $hypervisor  \
 pgrep -f ^virsh_$node/dev/null 21; \
 if [ \$? = 0 ]; then echo RUNNING; exit; fi; \
 mkdir -p $dump_dir; \
 if [ \$? != 0 ]; then echo MKDIR_FAILED; exit; fi; \
 (exec -a virsh_$node $DUMP_COMMAND $node $COREFILE/dev/null 21); \
 if [ \$? != 0 ]; then echo DUMP_FAILED; exit; fi; \
 echo OK)
  ssh_result=$?
  if [ $ssh_result = 0 ]
  then
  case $command_result in
  RUNNING)
  ha_log.sh info Dump is already 
 running
  exit 0
  ;;
  SUSPEND_FAILED)
  ha_log.sh err Failed to suspend 
 domain $node
  ;;
  MKDIR_FAILED)
  ha_log.sh err Failed to create 
 directory $dump_dir
  ;;
  DUMP_FAILED)
  ha_log.sh err Failed to core dump 
 domain $node to $COREFILE
  ;;
  OK)
  ha_log.sh notice Domain $node dumped 
 to $COREFILE
  ;;
  esac
  else
  ha_log.sh err Couldn't connect to hypervisor 
 $hypervisor
  fi
  else
  ha_log.sh err dump_dir isn't set
  fi
  fi

  command_result=$($SSH_COMMAND $hypervisor ((sleep 2; 
 $STOP_COMMAND $node)/dev/null 21); echo \$?)
   

Re: [Linux-ha-dev] New STONITH plug-in to be usable by Xen and KVM

2010-12-22 Thread Yasumasa OZAKI

Hi Dejan,

I'm sorry I'm late.

I took your advice, and corrected a plug-in, so it's sent.

By the way, Holger made a similar plug-in, but how should I do?

Best regards,
Yasumasa OZAKI

(2010/09/30 19:38), Yasumasa OZAKI wrote:

Hi Dejan,

Thank you for reply.

I correct it based on your opinion because I think that your opinion is
correct. wait a little, please.

- The stop of the domain is judged from the virsh returns, and
CheckIfDead function is removed.

- RunCommand function does, and shortens the refactoring.

- Other points are corrected based on your opinion.

Thanks,
Yasumasa OZAKI

On Thu, 23 Sep 2010 17:08:12 +0200, Dejan Muhamedagic wrote:

Hi Yasumasa-san,

On Fri, Sep 10, 2010 at 03:17:56PM +0900, Yasumasa OZAKI wrote:

Hi,

I made the STONITH plug-in that can be used by both Xen and KVM.


Thanks! Comments below.


I would like to hear any opinion.

Best regards,
Yasumasa OZAKI






#!/bin/sh
#
# External STONITH module for Xen/KVM hypervisor through ssh.
# Uses Xen/KVM hypervisor as a STONITH device to control guest.
#
# Copyright (c) 2010 NIPPON TELEGRAPH AND TELEPHONE CORPORATION
#

STOP_COMMAND=virsh destroy
START_COMMAND=virsh start
DUMP_COMMAND=virsh dump
SSH_COMMAND=/usr/bin/ssh -q -x -n

# Rewrite the hostlist to accept , as a delimeter for hostnames too.
hostlist=`echo $hostlist | tr ',' ' '`

CheckIfDead() {
 for j in 1 2 3 4 5
 do
 if ! ping -w1 -c1 $1/dev/null 21
 then
 return 0
 fi
 sleep 1
 done

 return 1
}


I'd rather have this one removed. If virsh returns a meaningful
exit code, then we can rely on that, right? Or use domstate?


CheckHostList() {
 if [ x = x$hostlist ]
 then
 ha_log.sh err hostlist isn't set
 exit 1
 fi
}

CheckHypervisor() {
 if [ x = x$hypervisor ]
 then
 ha_log.sh err hypervisor isn't set
 exit 1
 fi
}

RunCommand() {
 CheckHostList
 CheckHypervisor

 for node in $hostlist
 do
 if [ $node != $1 ]
 then
 continue
 fi


You can abbreviate code like this into a more compact

[ $node != $1 ]  continue


 case $2 in
 stop)
 if [ x$run_dump != x ]
 then
 #Need to run core dump
 if [ x$dump_dir != x ]
 then
 TIMESTAMP=`date +%Y-%m%d-%H%M.%S`
 DOMAINNAME=`printf %s $node`
 COREFILE=$dump_dir/$TIMESTAMP-$DOMAINNAME.core
 #Run core dump
 command_result=$($SSH_COMMAND $hypervisor  \
pgrep -f ^virsh_$node/dev/null 21; \
if [ \$? = 0 ]; then echo RUNNING; exit; fi; \
mkdir -p $dump_dir; \
if [ \$? != 0 ]; then echo MKDIR_FAILED; exit; fi; \
(exec -a virsh_$node $DUMP_COMMAND $node $COREFILE/dev/null 21); \
if [ \$? != 0 ]; then echo DUMP_FAILED; exit; fi; \
echo OK)
 ssh_result=$?
 if [ $ssh_result = 0 ]
 then
 case $command_result in
 RUNNING)
 ha_log.sh info Dump is already running
 exit 0
 ;;
 SUSPEND_FAILED)
 ha_log.sh err Failed to suspend domain 
$node
 ;;
 MKDIR_FAILED)
 ha_log.sh err Failed to create directory 
$dump_dir
 ;;
 DUMP_FAILED)
 ha_log.sh err Failed to core dump domain $node 
to $COREFILE
 ;;
 OK)
 ha_log.sh notice Domain $node dumped to 
$COREFILE
 ;;
 esac
 else
 ha_log.sh err Couldn't connect to hypervisor 
$hypervisor
 fi
 else
 ha_log.sh err dump_dir isn't set
 fi
 fi

 command_result=$($SSH_COMMAND $hypervisor ((sleep 2; $STOP_COMMAND 
$node)/dev/null 21); echo \$?)
 ssh_result=$?
 if [ $ssh_result = 0 ]
 then
 if [ $command_result = 0 ]
 then
 ha_log.sh notice Domain $node is stoped
 else
 ha_log.sh err Failed to stop domain $node
 fi
 else
 ha_log.sh err Couldn't connect to hypervisor $hypervisor
 fi
 break;;
 start)