[one-users] Avoiding manual restart of (persistent) VMs in case of host reboot
Olivier Berger
olivier.berger at it-sudparis.eu
Wed May 23 10:12:11 PDT 2012
Hi.
Responding to myself ...
On Wed, 23 May 2012 17:03:44 +0200, Olivier Berger <olivier.berger at it-sudparis.eu> wrote:
> Hi.
>
> On Wed, 23 May 2012 16:09:20 +0200, Jaime Melis <jmelis at opennebula.org> wrote:
> >
> > You could do two things:
> > 1) Write a hook [1] on the event of running vm to do "virsh autostart
> > one-<VM_ID>" [2]
> > 2) Add a line in the deployment script [3] to execute "virsh autostart
> > one-<VM_ID>" ( after line 29 of the script for example)
> >
> > [1] http://libvirt.org/sources/virshcmdref/html/sect-autostart.html
> > [2]
> > http://opennebula.org/documentation:rel3.4:hooks#hooks_for_virtualmachines
> > [3]
> > https://github.com/OpenNebula/one/blob/one-3.2/src/vmm_mad/remotes/kvm/deploy#L29
> >
>
> Hmmm... I've tried this, but :
>
> # virsh autostart one-42
> error: Failed to mark domain one-42 as autostarted
> error: Requested operation is not valid: cannot set autostart for transient domain
>
> Maybe the result would be different if run from the hook / script, but
> I'm not sure...
>
> From reading http://remoteoutpost.nl/?page_id=71 I've understood that
> the virsh define command was needed, so I've tried adding that deployment
> script (which I believe is /var/lib/one/remotes/vmm/kvm/deploy), doing :
>
> virsh --connect $LIBVIRT_URI define $domain
>
> just before the :
>
> data=`virsh --connect $LIBVIRT_URI create $domain`
>
> However, it doesn't seem to be executed :-/
>
Ah, yes, I was changing the one in /var/lib/one instead of the one
"deployed on the node", but actually on the same host in
/var/tmp/one... (newbie mode)
So, the following in vmm/kvm/deploy should do the trick :
domain=$1
mkdir -p `dirname $domain`
cat > $domain
# First define the xml file as a domain definition
data=`virsh --connect $LIBVIRT_URI define $domain`
if [ "x$?" = "x0" ]; then
vm=`echo $data | sed 's/Domain //' | sed 's/ defined from .*$//'`
# start the VM/domain
data=`virsh --connect $LIBVIRT_URI start $vm`
if [ "x$?" = "x0" ]; then
echo $data | sed 's/Domain //' | sed 's/ started.*$//'
# set it as autostart in case of node reboot
virsh --connect $LIBVIRT_URI autostart $vm
else
error_message "Could not create domain from $domain"
exit -1
fi
else
error_message "Could not define domain from $domain"
exit -1
fi
This seems to allow the VM to be restarted/resumed (still need to
investigate exactly) in case of node reboot.
Hope this helps,
Best regards.
--
Olivier BERGER
http://www-public.it-sudparis.eu/~berger_o/ - OpenPGP-Id: 2048R/5819D7E8
Ingenieur Recherche - Dept INF
Institut Mines-Telecom, Telecom SudParis, Evry (France)
More information about the Users
mailing list