[libvirt] libvirtd shutdown script patches

Here is a small patch for libvirtd init and sysconfig script. Before killing libvirtd, we virsh shutdown any running domains. We also have a maximum time limit for shutdown (300 sec default), just in case the VM will not shut down. Any thoughts as to whether this is the right place to put this functionality? Is the shutdown script proper, or since libvirtd handles autostarts domains internally, should libvirtd shut down active domains upon SIGTERM all by itself? -Richard --- /etc/init.d/libvirtd.orig 2009-01-13 19:31:47.000000000 -0500 +++ /etc/init.d/libvirtd 2009-01-13 19:53:25.000000000 -0500 @@ -47,6 +47,11 @@ LIBVIRTD_CONFIG_ARGS="--config $LIBVIRTD_CONFIG" fi +if [ -z "$LIBVIRTD_SHUTDOWN_TIMEOUT" ] +then + LIBVIRTD_SHUTDOWN_TIMEOUT=300 +fi + RETVAL=0 start() { @@ -62,6 +67,15 @@ stop() { echo -n $"Stopping $SERVICE daemon: " + starttime=`date '+%s'` + for VM in $(virsh list | grep running | gawk '{print $2}'); do virsh -q shutdown $VM; done + while ( virsh list | grep -qc running ); do + sleep 5; + nowtime=`date '+%s'` + elapsed=$(($nowtime-$starttime)) + [[ $elapsed -ge $LIBVIRTD_SHUTDOWN_TIMEOUT ]] && break + done + killproc $PROCESS RETVAL=$? echo --- /etc/sysconfig/libvirtd.orig 2009-01-13 19:56:09.000000000 -0500 +++ /etc/sysconfig/libvirtd 2009-01-13 19:41:27.000000000 -0500 @@ -8,4 +8,7 @@ # Override Kerberos service keytab for SASL/GSSAPI #KRB5_KTNAME=/etc/libvirt/krb5.tab +# Shutdown timeout in seconds - Default is 300 seconds (or 5 minutes) +#LIBVIRTD_SHUTDOWN_TIMEOUT=300 -- -Sir Woody Hackswell

On Tue, 2009-01-13 at 15:00 -0500, Sir Woody Hackswell wrote:
Here is a small patch for libvirtd init and sysconfig script. Before killing libvirtd, we virsh shutdown any running domains. We also have a maximum time limit for shutdown (300 sec default), just in case the VM will not shut down.
Any thoughts as to whether this is the right place to put this functionality? Is the shutdown script proper, or since libvirtd handles autostarts domains internally, should libvirtd shut down active domains upon SIGTERM all by itself?
Funny that this patch precedes Dan's patches to keep stuff alive on libvirtd shutdown :-) I think the main concern here is autostart domains - if you have an autostart domain and you boot up and immediately power down, then you're not going to even remember you have a domain running. Cheers, Mark.

On Tue, Jan 13, 2009 at 03:00:17PM -0500, Sir Woody Hackswell wrote:
Here is a small patch for libvirtd init and sysconfig script. Before killing libvirtd, we virsh shutdown any running domains. We also have a maximum time limit for shutdown (300 sec default), just in case the VM will not shut down.
Any thoughts as to whether this is the right place to put this functionality? Is the shutdown script proper, or since libvirtd handles autostarts domains internally, should libvirtd shut down active domains upon SIGTERM all by itself?
We don't really want to stop anything when the daemon shuts down. It is desirable to stop things when the machine is shutting down. If we put this functionality in the stop() function of the initscript we cannot make this distinction. I thing this would thus have to go in a separate initscrpit that is configured to run before the main libvirtd initscript. This ensures that if admin just wants to stop/start the daemon, their domains are not touched, but if the whole machine is shutdown, things are cleanly shutdown. Shutting down is not neccessarily the only thing an admin would want to do with guests. They may wish to save guests to a file. Or migrate them to a separate machine. In the case of saving to a file, you ahve the added complication that when libvirtd later starts on next boot, instead of auto-starting, you want it to restore from the saved file. This will entail additional logic in libvirtd. I also don't particularly like having this functionality split between the init scripts and the daemon, because the init script is neccessarily Red Hat specific, and there's many other distros using libvirt. My preference would be to have an explicit way to tell libvirtd to shutdown/save all running guests so initscript only needed a single command to do the job, and al the functional / timeout / waiting logic was in the daemon. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Wed, Jan 14, 2009 at 5:58 AM, Daniel P. Berrange <berrange@redhat.com> wrote:
On Tue, Jan 13, 2009 at 03:00:17PM -0500, Sir Woody Hackswell wrote:
It is desirable to stop things when the machine is shutting down.
If we put this functionality in the stop() function of the initscript we cannot make this distinction.
I thing this would thus have to go in a separate initscrpit that is configured to run before the main libvirtd initscript. This ensures that if admin just wants to stop/start the daemon, their domains are not touched, but if the whole machine is shutdown, things are cleanly shutdown.
A kill-only script, effectively? start() would be null, and stop() would shutdown or save or whatever is needed.
Shutting down is not neccessarily the only thing an admin would want to do with guests. They may wish to save guests to a file. Or migrate them to a separate machine. In the case of saving to a file, you ahve the added complication that when libvirtd later starts on next boot, instead of auto-starting, you want it to restore from the saved file. This will entail additional logic in libvirtd. I also don't particularly like having this functionality split between the init scripts and the daemon, because the init script is neccessarily Red Hat specific, and there's many other distros using libvirt. My preference would be to have an explicit way to tell libvirtd to shutdown/save all running guests so initscript only needed a single command to do the job, and all the functional / timeout / waiting logic was in the daemon.
This was my thought. Since libvirtd autostarts some domains, it should cleanly stop when it is time for shutdown (not necessarily at the death of libvirtd). If we put something in for startup, we shouldn't have to script it on shutdown, IMHO. Shutdown: (Replace "libvirtd" with virsh as needed) libvirtd --shutdown-all libvirtd --migrate-all new.server.com libvirtd --snapshot-all libvirtd --die-domains-die ;) Startup: libvirtd (startup, "intelligently" determines how it previously shut down domains, and reverses it) -- -Sir Woody Hackswell
participants (3)
-
Daniel P. Berrange
-
Mark McLoughlin
-
Sir Woody Hackswell