* init scripts for KVM guests UPDATE!
@ 2009-07-18 0:13 Saman Behnam
2009-07-18 5:25 ` Michael Tokarev
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Saman Behnam @ 2009-07-18 0:13 UTC (permalink / raw)
To: kvm
Hi there,
here is an update for the "init scripts for KVM guests"I'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" 2>&1; 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" 2>&1; 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" 2>&1; 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" 2>&1; 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" 2>&1; 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" 2>&1; then
echo "VM "$VM_NAME" is allready running!!! Exiting."
exit 1
fi
if ! ls "$VM_SAVE_DIR"/"$VM_NAME".kvm.save > "$DEVNULL" 2>&1 ; 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 stopping
/ starting KVM VM's???
greets
saman
--
mit freundlichen Grüßen / Kind regards
Saman Behnam
--
opensoft24-Systems
Lena-Christ-Str. 3
80807 München
Tel.: +49 (0) 89 69397631
Fax.: +49 (0) 89 69397631
info@opensoft24.de
www.opensoft24.de
www.opensoft24.com
Bankverbindung:
Postbank München
BLZ.: 70010080
Kto.: 279702806
Steuer-Nr.: 135 70442
UST-IdNr.: 76 158 941 031
IBAN.: PBNKDEFF
SWIFT.: DE21700100800279702806
Diese Nachricht und/oder Anhänge sind vertraulich und können der Geheimhaltungspflicht unterliegen. Wenn Sie nicht der vorgesehene Adressat sind, weisen wir Sie hiermit darauf hin, dass jegliche Nutzung, Weiterleitung und Kopien unzulässig sind. Benachrichtigen Sie uns bitte unverzüglich per E-Mail und löschen Sie diese Nachricht und/oder Anhänge aus Ihrem System.
This mail and/or attachments are confidential and may also be legally privileged. If you are not the intended recipient, you are hereby notified, that any review, dissemination, distribution or copying of this email and/or attachments is strictly prohibited. Please notify us immediately by email and delete this message and all its attachments.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: init scripts for KVM guests UPDATE!
2009-07-18 0:13 init scripts for KVM guests UPDATE! Saman Behnam
@ 2009-07-18 5:25 ` Michael Tokarev
2009-07-18 16:03 ` Daniel Bareiro
2009-07-19 5:01 ` Charles Duffy
2009-07-19 9:51 ` Ján ONDREJ (SAL)
2 siblings, 1 reply; 6+ messages in thread
From: Michael Tokarev @ 2009-07-18 5:25 UTC (permalink / raw)
To: Saman Behnam; +Cc: kvm
Saman Behnam wrote:
> Hi there,
>
>
> here is an update for the "init scripts for KVM guests"I'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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: init scripts for KVM guests UPDATE!
2009-07-18 5:25 ` Michael Tokarev
@ 2009-07-18 16:03 ` Daniel Bareiro
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Bareiro @ 2009-07-18 16:03 UTC (permalink / raw)
To: kvm
[-- Attachment #1: Type: text/plain, Size: 907 bytes --]
Hi Michael.
On Saturday, 18 July 2009 09:25:57 +0400,
Michael Tokarev wrote:
>> here is an update for the "init scripts for KVM guests"I'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
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: init scripts for KVM guests UPDATE!
2009-07-18 0:13 init scripts for KVM guests UPDATE! Saman Behnam
2009-07-18 5:25 ` Michael Tokarev
@ 2009-07-19 5:01 ` Charles Duffy
2009-07-19 9:51 ` Ján ONDREJ (SAL)
2 siblings, 0 replies; 6+ messages in thread
From: Charles Duffy @ 2009-07-19 5:01 UTC (permalink / raw)
To: kvm
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: init scripts for KVM guests UPDATE!
2009-07-18 0:13 init scripts for KVM guests UPDATE! Saman Behnam
2009-07-18 5:25 ` Michael Tokarev
2009-07-19 5:01 ` Charles Duffy
@ 2009-07-19 9:51 ` Ján ONDREJ (SAL)
2009-07-19 9:53 ` Ján ONDREJ (SAL)
2 siblings, 1 reply; 6+ messages in thread
From: Ján ONDREJ (SAL) @ 2009-07-19 9:51 UTC (permalink / raw)
To: Saman Behnam; +Cc: kvm
On Sat, Jul 18, 2009 at 02:13:44AM +0200, Saman Behnam wrote:
> here is an update for the "init scripts for KVM guests"I'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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: init scripts for KVM guests UPDATE!
2009-07-19 9:51 ` Ján ONDREJ (SAL)
@ 2009-07-19 9:53 ` Ján ONDREJ (SAL)
0 siblings, 0 replies; 6+ messages in thread
From: Ján ONDREJ (SAL) @ 2009-07-19 9:53 UTC (permalink / raw)
To: Saman Behnam; +Cc: kvm
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 guests"I'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-list@redhat.com/msg14754.html
SAL
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-07-19 9:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-18 0:13 init scripts for KVM guests UPDATE! Saman Behnam
2009-07-18 5:25 ` Michael Tokarev
2009-07-18 16:03 ` Daniel Bareiro
2009-07-19 5:01 ` Charles Duffy
2009-07-19 9:51 ` Ján ONDREJ (SAL)
2009-07-19 9:53 ` Ján ONDREJ (SAL)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox