Re: init scripts for KVM guests UPDATE!

2009-07-19 Thread SAL
On Sat, Jul 18, 2009 at 02:13:44AM +0200, Saman Behnam wrote:
 here is an update for the init scripts for KVM guestsI've wrote for
 starting and stopping the KVM guest machines either by saving and
 restoring or by gracefully shutdown and start. My question, is there an
 option within libvirt to make the KVM guest mashines get saved when
 the KVM host shuts down? I had problems to gracefully shutdown Windows
 VM's!!!

Hello,

  I sent my (and also your) script to libvir-list, but no response yet.
There are also some suggestions, how libvirt can handle graceful shutdown
and leave ability to restart libvirt without touching guests.

  I use my script to also shutdown windows guests. It's working well, if you
configure to shutdown windows on acpi event (virtual power button pressed).
I am not an expert for windows and I can't tell you more, but I am sure,
that you can find more with google. :-)

SAL
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: init scripts for KVM guests UPDATE!

2009-07-19 Thread SAL
On Sun, Jul 19, 2009 at 11:51:44AM +0200, Ján ONDREJ (SAL) wrote:
 On Sat, Jul 18, 2009 at 02:13:44AM +0200, Saman Behnam wrote:
  here is an update for the init scripts for KVM guestsI've wrote for
  starting and stopping the KVM guest machines either by saving and
  restoring or by gracefully shutdown and start. My question, is there an
  option within libvirt to make the KVM guest mashines get saved when
  the KVM host shuts down? I had problems to gracefully shutdown Windows
  VM's!!!

   I sent my (and also your) script to libvir-list, but no response yet.
 There are also some suggestions, how libvirt can handle graceful shutdown
 and leave ability to restart libvirt without touching guests.
 
   I use my script to also shutdown windows guests. It's working well, if you
 configure to shutdown windows on acpi event (virtual power button pressed).
 I am not an expert for windows and I can't tell you more, but I am sure,
 that you can find more with google. :-)

Forgot to attach mail archive URL:
  http://www.mail-archive.com/libvir-l...@redhat.com/msg14754.html

SAL
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: init scripts for KVM guests UPDATE!

2009-07-18 Thread Daniel Bareiro
Hi Michael.

On Saturday, 18 July 2009 09:25:57 +0400,
Michael Tokarev wrote:

 here is an update for the init scripts for KVM guestsI've wrote for
 starting and stopping the KVM guest machines either by saving and
 restoring or by gracefully shutdown and start. My question, is there
 an option within libvirt to make the KVM guest mashines get saved
 when the KVM host shuts down? I had problems to gracefully shutdown
 Windows VM's!!!

 By the way, do you realize that libvirt != kvm?

Is there some way to obtain this without using libvirt? To write a
script for starting the virtual machines is not a problem to do doing
without libvirt, nevertheless the problem is in how doing shutdown of
the VMs when host does it.

Regards,
Daniel
-- 
Fingerprint: BFB3 08D6 B4D1 31B2 72B9  29CE 6696 BF1B 14E6 1D37
Powered by Debian GNU/Linux Squeeze - Linux user #188.598


signature.asc
Description: Digital signature


Re: init scripts for KVM guests UPDATE!

2009-07-18 Thread Charles Duffy
To echo Michael a little here -- posting this on the KVM mailing list 
implies that it shouldn't have dependencies beyond KVM; as such, the 
libvirt mailing list would probably be a better place for these scripts.


That said -- no, there isn't an option within libvirt to save or 
gracefully shut down the guests on daemon (or host) shutdown. This is in 
part because in newer versions, the libvirt daemon can be shut down or 
restarted without also shutting down the guests -- presuming that the 
host is being shut down whenever the guest is terminated would be an 
unfortunate thing from the perspective of some users, so in my opinion a 
separate init script for controlling the guests (similar to what you're 
doing here) is probably the Right Thing.


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


init scripts for KVM guests UPDATE!

2009-07-17 Thread Saman Behnam
Hi there,


here is an update for the init scripts for KVM guestsI've wrote for
starting and stopping the KVM guest machines either by saving and
restoring or by gracefully shutdown and start. My question, is there an
option within libvirt to make the KVM guest mashines get saved when
the KVM host shuts down? I had problems to gracefully shutdown Windows
VM's!!!


Right now I had to write these scripts to save and restore the machines
upon starting and stopping the KVM host.


Many Thanks for your response



vim /etc/init.d/kvm-win0-rcs


###


#!/bin/sh


### BEGIN INIT INFO
# Provides:  kvm-win0-rcs
# Required-Start:$kvm $libvirtd
# Required-Stop: $kvm $libvirtd
# Default-Start: 2 3 4 5
# Default-Stop:  0 1 6
# Short-Description: Starting/Saving, Stopping/Restoring kvm-win0-rcs
KVM guest.
# Description:   Starting/Saving, Stopping/Restoring KVM guest win0.
# kvm-win0-rcs KVM guest.
### END INIT INFO#


# Please copy the init scripts of the KVM VM's in to /etc/init.d and
then run! for i in `cd /etc/init.d  ls kvm-*` ; do update-rc.d  $i
defaults 21 19 ; done

# U need per VM a separate start-stop-script!
VM_NAME=win0 # Name of ur guest VM
TIMEOUT=300
VM_SAVE_DIR=/kvm/tmp/vm_save_dir # Directory for storing the guest VM
save data..
DEVNULL=/dev/null
#ACTION=shutdown
ACTION=save # ACTION takes one argument, either save or shutdown.
In the save case it will save the VM and restore it while stopping or
starting. In the shtudown case it will sutdown then VM and start it
while stopping or starting.



vmshutdown () {
if ! virsh list|grep running|grep -v grep|grep $VM_NAME 
$DEVNULL 21; then
echo VM $VM_NAME is not running!!! Exiting.
exit 1
fi
COUNT=0
echo kvmshutdown \: Shutting down $VM_NAME with pid $PID
virsh shutdown $VM_NAME 
while [ $COUNT -lt $TIMEOUT ]; do
if ! virsh list|grep running|grep -v grep|grep
$VM_NAME  $DEVNULL 21; then
exit 0
fi
sleep 5
COUNT=$(($COUNT+5))
done
echo kvmshutdown \: Timeout happend. Destroying VM $VM_NAME
virsh destroy $VM_NAME  exit 1
}

vmstart () {
if virsh list|grep running|grep -v grep|grep $VM_NAME 
$DEVNULL 21; then
echo VM $VM_NAME is allready running!!! Exiting.
exit 1
fi
virsh start $VM_NAME  exit 0
exit 1
}

vmsave () {
if ! virsh list|grep running|grep -v grep|grep $VM_NAME 
$DEVNULL 21; then
echo VM $VM_NAME is not running!!! Exiting.
exit 1
fi
COUNT=0
echo vmsave \: Saving VM $VM_NAME
if [ ! -d $VM_SAVE_DIR ]; then
echo creating  $VM_SAVE_DIR
mkdir -p $VM_SAVE_DIR
fi
virsh save $VM_NAME $VM_SAVE_DIR/$VM_NAME.kvm.save 
while [ $COUNT -lt $TIMEOUT ]; do
if ! virsh list|grep running|grep -v grep|grep
$VM_NAME  $DEVNULL 21; then
exit 0
fi
sleep 5
COUNT=$(($COUNT+5))
done
echo vmsave \: Timeout happend. Destroying VM $VM_NAME
virsh destroy $VM_NAME
exit 1
}

vmrestore () {
if virsh list|grep running|grep -v grep|grep $VM_NAME 
$DEVNULL 21; then
echo VM $VM_NAME is allready running!!! Exiting.
exit 1
fi
if ! ls $VM_SAVE_DIR/$VM_NAME.kvm.save  $DEVNULL 21 ; then
echo Restore file $VM_NAME.kvm.save in $VM_SAVE_DIR
not found! Starting VM!!!
vmstart
exit 1
fi
cd $VM_SAVE_DIR
echo vmrestore \: Restoring VM $VM_NAME
virsh restore $VM_SAVE_DIR/$VM_NAME.kvm.save  rm -f
$VM_SAVE_DIR/$VM_NAME.kvm.save
exit 0
}

# Here is the start of the main program :-)
case $1 in
start)
case $ACTION in
save)
vmrestore
;;
shutdown)
vmstart
;;
esac
;;
stop)
case $ACTION in
save)
vmsave
;;
shutdown)
vmshutdown
;;
esac
;;

*)
N=$0
echo Usage: $N {start|stop} 2
exit 1
;;
esac
exit 0


###


Please tell also if there is an official script for gracefully 

Re: init scripts for KVM guests UPDATE!

2009-07-17 Thread Michael Tokarev

Saman Behnam wrote:

Hi there,


here is an update for the init scripts for KVM guestsI've wrote for
starting and stopping the KVM guest machines either by saving and
restoring or by gracefully shutdown and start. My question, is there an
option within libvirt to make the KVM guest mashines get saved when
the KVM host shuts down? I had problems to gracefully shutdown Windows
VM's!!!


By the way, do you realize that libvirt != kvm?

/mjt
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html