[libvirt] [PATCH v2] Init script for handling guests on shutdown/boot
Eric Blake
eblake at redhat.com
Tue May 18 18:16:01 UTC 2010
On 05/18/2010 07:27 AM, Jiri Denemark wrote:
>
> Version 2 changes:
> - fixes suggested by Eric
> - configurable ON_BOOT and ON_SHUTDOWN behavior inspired by Gerd
>
> +++ b/daemon/libvirt-guests.init.in
> @@ -0,0 +1,295 @@
> +
> +sysconfdir=@sysconfdir@
> +localstatedir=@localstatedir@
Just in case @sysconfdir@ has spaces (if it has ', the user's hosed
themselves anyway):
sysconfdir='@sysconfdir@'
localstatedir='@localstatedir@'
But libvirtd.init.in does the same, so at this point, any cleanups for
minor issues like that can be done across both scripts at once, as a
separate patch.
> +
> +stop() {
> + # last stop was not followed by start
> + [ -f $LISTFILE ] && return 0
> +
> + suspending=true
> + if [ "x$ON_SHUTDOWN" = xshutdown ]; then
> + suspending=false
> + if [ $SHUTDOWN_TIMEOUT -le 0 ]; then
> + echo $"Shutdown action requested but SHUTDOWN_TIMEOUT was not set"
> + RETVAL=6
> + return
> + fi
> + fi
> +
> + : >$LISTFILE
> + for uri in $URIS; do
> + echo -n $"Running guests on $uri URI: "
> + list=$(list_guests $uri)
> + if [ $? -eq 0 ]; then
> + empty=true
> + for uuid in $list; do
> + $empty || printf ", "
> + echo -n $(guest_name $uri $uuid)
> + empty=false
> + done
> + if $empty; then
> + echo $"no running guests."
> + else
> + echo
> + echo $uri $list >>$LISTFILE
> + fi
> + fi
> + done
> +
> + while read uri list; do
> + if $suspending; then
> + echo $"Suspending guests on $uri URI..."
> + else
> + echo $"Shutting down guests on $uri URI..."
> + fi
> +
> + for guest in $list; do
> + if $suspending; then
> + suspend_guest $uri $guest
> + else
> + shutdown_guest $uri $guest
> + fi
> + done
> + done <$LISTFILE
> +}
This works as is, so need to change it. But I would have done something
along these lines:
how=suspend_guest
if [ "x$ON_SHUTDOWN" = xshutdown ]; then
how=shutdown_guest
fi
...
for guest in $list; do
$how $uri $guest
done
to cut down on some of the logic.
> + shutdown)
> + ON_SHUTDOWN=shutdown
> + stop
> + ;;
If someone calls 'service libvirt-guests shutdown', but...
> +# action taken on host shutdown
> +# - suspend all running guests are suspended using virsh managedsave
> +# - shutdown all running guests are asked to shutdown. Please be careful with
> +# this settings since there is no way to distinguish between a
> +# guest which is stuck or ignores shutdown requests and a guest
> +# which just needs a long time to shutdown. When setting
> +# ON_SHUTDOWN=shutdown, you must also set SHUTDOWN_TIMEOUT to a
> +# value suitable for your guests.
> +#ON_SHUTDOWN=suspend
> +
> +# number of seconds we're willing to wait for a guest to shut down
> +#SHUTDOWN_TIMEOUT=0
...left their config with the defaults, then the shutdown will fail
because SHUTDOWN_TIMEOUT is still 0. I guess that makes sense, though.
Are we sure that init scripts called during '/sbin/shutdown' are
normally called with 'stop' rather than 'shutdown' argument?
Looks nicer! ACK.
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100518/d9ede21a/attachment-0001.sig>
More information about the libvir-list
mailing list