[libvirt] [PATCH] implement BOOT_TIMEOUT

--- tools/libvirt-guests.init.sh | 2 ++ tools/libvirt-guests.sysconf | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.sh index f247e5e..b462ea8 100644 --- a/tools/libvirt-guests.init.sh +++ b/tools/libvirt-guests.init.sh @@ -42,6 +42,7 @@ URIS=default ON_BOOT=start ON_SHUTDOWN=suspend SHUTDOWN_TIMEOUT=0 +BOOT_TIMEOUT=0 test -f "$sysconfdir"/sysconfig/libvirt-guests && . "$sysconfdir"/sysconfig/libvirt-guests @@ -166,6 +167,7 @@ start() { gettext "already active"; echo else retval run_virsh "$uri" start "$name" >/dev/null && \ + sleep $BOOT_TIMEOUT && \ gettext "done"; echo fi fi diff --git a/tools/libvirt-guests.sysconf b/tools/libvirt-guests.sysconf index cd58728..e970a00 100644 --- a/tools/libvirt-guests.sysconf +++ b/tools/libvirt-guests.sysconf @@ -10,6 +10,9 @@ # libvirtd #ON_BOOT=start +# number of seconds to wait before starting the next guest +#BOOT_TIMEOUT=0 + # 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 -- 1.7.1

Sorry for top posing. This is https://bugzilla.redhat.com/show_bug.cgi?id=695653. Was filed first in Bugzilla because the mailing list wasn't accessible yesterday. На 13.04.2011 11:15, Alexander Todorov написа:
--- tools/libvirt-guests.init.sh | 2 ++ tools/libvirt-guests.sysconf | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.sh index f247e5e..b462ea8 100644 --- a/tools/libvirt-guests.init.sh +++ b/tools/libvirt-guests.init.sh @@ -42,6 +42,7 @@ URIS=default ON_BOOT=start ON_SHUTDOWN=suspend SHUTDOWN_TIMEOUT=0 +BOOT_TIMEOUT=0
test -f "$sysconfdir"/sysconfig/libvirt-guests&& . "$sysconfdir"/sysconfig/libvirt-guests @@ -166,6 +167,7 @@ start() { gettext "already active"; echo else retval run_virsh "$uri" start "$name">/dev/null&& \ + sleep $BOOT_TIMEOUT&& \ gettext "done"; echo fi fi diff --git a/tools/libvirt-guests.sysconf b/tools/libvirt-guests.sysconf index cd58728..e970a00 100644 --- a/tools/libvirt-guests.sysconf +++ b/tools/libvirt-guests.sysconf @@ -10,6 +10,9 @@ # libvirtd #ON_BOOT=start
+# number of seconds to wait before starting the next guest +#BOOT_TIMEOUT=0 + # 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
-- инж. Александър Тодоров - RHCE, RHCVA, RHCI Отворени Технологии България ЕООД - Red Hat Ready Business Partner www.otb.bg/sumu

On 04/13/2011 02:15 AM, Alexander Todorov wrote:
--- tools/libvirt-guests.init.sh | 2 ++ tools/libvirt-guests.sysconf | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.sh index f247e5e..b462ea8 100644 --- a/tools/libvirt-guests.init.sh +++ b/tools/libvirt-guests.init.sh @@ -42,6 +42,7 @@ URIS=default ON_BOOT=start ON_SHUTDOWN=suspend SHUTDOWN_TIMEOUT=0 +BOOT_TIMEOUT=0
test -f "$sysconfdir"/sysconfig/libvirt-guests && . "$sysconfdir"/sysconfig/libvirt-guests @@ -166,6 +167,7 @@ start() { gettext "already active"; echo else retval run_virsh "$uri" start "$name" >/dev/null && \ + sleep $BOOT_TIMEOUT && \
I think the idea of a configurable sleep between guests (so that they are staged rather than run back-to-back as fast as virsh can respond) makes sense, but don't like the name BOOT_TIMEOUT. It's not a timeout, so much as a delay. And it's not tied to BOOT (which is what the init script does when the host boots) so much as guest starts. Does the name START_DELAY work any better?
gettext "done"; echo
As written, if you have n guests, you also have n sleeps. But after the last guest, that's wasted dead time. It seems like the better usage pattern would be to sleep _before_ starting a guest, and to write the code where the first guest started skips that sleep (n guests, n-1 sleeps).
fi fi diff --git a/tools/libvirt-guests.sysconf b/tools/libvirt-guests.sysconf index cd58728..e970a00 100644 --- a/tools/libvirt-guests.sysconf +++ b/tools/libvirt-guests.sysconf @@ -10,6 +10,9 @@ # libvirtd #ON_BOOT=start
+# number of seconds to wait before starting the next guest
And this would read better as "number of seconds to wait between each guest start"
+#BOOT_TIMEOUT=0 + # 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
-- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

На 13.04.2011 20:31, Eric Blake написа:
On 04/13/2011 02:15 AM, Alexander Todorov wrote:
--- tools/libvirt-guests.init.sh | 2 ++ tools/libvirt-guests.sysconf | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.sh index f247e5e..b462ea8 100644 --- a/tools/libvirt-guests.init.sh +++ b/tools/libvirt-guests.init.sh @@ -42,6 +42,7 @@ URIS=default ON_BOOT=start ON_SHUTDOWN=suspend SHUTDOWN_TIMEOUT=0 +BOOT_TIMEOUT=0
test -f "$sysconfdir"/sysconfig/libvirt-guests&& . "$sysconfdir"/sysconfig/libvirt-guests @@ -166,6 +167,7 @@ start() { gettext "already active"; echo else retval run_virsh "$uri" start "$name">/dev/null&& \ + sleep $BOOT_TIMEOUT&& \
I think the idea of a configurable sleep between guests (so that they are staged rather than run back-to-back as fast as virsh can respond) makes sense, but don't like the name BOOT_TIMEOUT. It's not a timeout, so much as a delay. And it's not tied to BOOT (which is what the init script does when the host boots) so much as guest starts. Does the name START_DELAY work any better?
I have no preference on the name.
gettext "done"; echo
As written, if you have n guests, you also have n sleeps. But after the last guest, that's wasted dead time. It seems like the better usage pattern would be to sleep _before_ starting a guest, and to write the code where the first guest started skips that sleep (n guests, n-1 sleeps).
Right, that makes sense. It was a quick patch to resolve my particular issue where starting 10 guests at once puts big load on my system. I will rework the patch with your comments and post it again but was wondering about something more advanced. Is it possible to specify the order(and timeouts) in which individual guests are started? As it seems currently this is not possible. I've come across a situation where one of the guests needs to start first (provides a database) and then another guests needs to start second (an app server). The reason is that this is a proprietary app which is badly written and fails to connect/re-connect to the database if it is not online in the first place. Regards, Alexander.

On 04/14/2011 04:21 AM, Alexander Todorov wrote:
I will rework the patch with your comments and post it again but was wondering about something more advanced.
Is it possible to specify the order(and timeouts) in which individual guests are started? As it seems currently this is not possible.
I'm not sure of any way to do this short of naming your guests so that their names are sorted in the order you want them started. Hmm, thinking back to an earlier proposal, this might be a good fit for the idea of VM groups: https://www.redhat.com/archives/libvir-list/2011-March/msg01546.html That is, if you can teach libvirt to manage the notion of groups of related VMs, then you can also express ordering contraints within each group.
I've come across a situation where one of the guests needs to start first (provides a database) and then another guests needs to start second (an app server). The reason is that this is a proprietary app which is badly written and fails to connect/re-connect to the database if it is not online in the first place.
Without more code on the libvirt front, I think you're stuck renaming the guests to enforce naming order (assuming that libvirt even goes by sorted name order, as opposed to readdir() order where you have no control). -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Thu, Apr 14, 2011 at 02:32:36PM -0600, Eric Blake wrote:
Without more code on the libvirt front, I think you're stuck renaming the guests to enforce naming order (assuming that libvirt even goes by sorted name order, as opposed to readdir() order where you have no control).
I solved this problem in my own application, a layer above libvirt. I simply make all of my domains non-persistent. When the node reboots, nothing starts up. My application detects that domains that should be running aren't and defines/starts them. It's easy at that point to start them up in whatever order I want and give whatever delay between startups. Even if you don't have some overarching managing application (like, if you're managing one node instead of hundreds), you could easily do something similar with a cron job. --Igor

On 04/14/2011 04:32 PM, Eric Blake wrote:
I've come across a situation where one of the guests needs to start first (provides a database) and then another guests needs to start second (an app server). The reason is that this is a proprietary app which is badly written and fails to connect/re-connect to the database if it is not online in the first place. Without more code on the libvirt front, I think you're stuck renaming
On 04/14/2011 04:21 AM, Alexander Todorov wrote: the guests to enforce naming order (assuming that libvirt even goes by sorted name order, as opposed to readdir() order where you have no control).
Of course that does no good if guest A which happens to startup on Host 1 has a prerequisite of guest B which may already be running on Host 2, or may not be running at all. So should libvirt try to solve the problem for the special case of all guests on one host, or defer it to higher level management, which may know about more than one host? Maybe libvirt could just make space for the information about dependencies in the domain XML, but not do anything to try and enforce it (or maybe that could be something optionally enabled in system config for installations with a single host).

Hello folks, here's a second try at this wrt to Eric's comments. BOOT_TIMEOUT changed to START_DELAY, updated wording in the conf file to better reflect what this does and added a flag to skip sleeping for the first ever started guest. --- tools/libvirt-guests.init.sh | 7 +++++++ tools/libvirt-guests.sysconf | 3 +++ 2 files changed, 10 insertions(+), 0 deletions(-) diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.sh index f247e5e..30f957a 100644 --- a/tools/libvirt-guests.init.sh +++ b/tools/libvirt-guests.init.sh @@ -42,6 +42,7 @@ URIS=default ON_BOOT=start ON_SHUTDOWN=suspend SHUTDOWN_TIMEOUT=0 +START_DELAY=0 test -f "$sysconfdir"/sysconfig/libvirt-guests && . "$sysconfdir"/sysconfig/libvirt-guests @@ -141,6 +142,7 @@ start() { return 0 fi + isfirst=true while read uri list; do configured=false set -f @@ -165,6 +167,11 @@ start() { if "$guest_running"; then gettext "already active"; echo else + if "$isfirst"; then + isfirst=false + else + sleep $START_DELAY + fi retval run_virsh "$uri" start "$name" >/dev/null && \ gettext "done"; echo fi diff --git a/tools/libvirt-guests.sysconf b/tools/libvirt-guests.sysconf index cd58728..37b258e 100644 --- a/tools/libvirt-guests.sysconf +++ b/tools/libvirt-guests.sysconf @@ -10,6 +10,9 @@ # libvirtd #ON_BOOT=start +# number of seconds to wait between each guest start +#START_DELAY=0 + # 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

On 04/15/2011 02:57 AM, Alexander Todorov wrote:
Hello folks, here's a second try at this wrt to Eric's comments. BOOT_TIMEOUT changed to START_DELAY, updated wording in the conf file to better reflect what this does and added a flag to skip sleeping for the first ever started guest.
--- tools/libvirt-guests.init.sh | 7 +++++++ tools/libvirt-guests.sysconf | 3 +++ 2 files changed, 10 insertions(+), 0 deletions(-)
Your mailer botched the patch (it used 2 instead of 1 leading space for each context line), and 'git apply' had a hard time applying it; I had to redo it by hand. ACK and pushed. Thanks for the contribution! I added you to AUTHORS; feel free to let me know (off-list if desired) if I need to adjust your listing. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (4)
-
Alexander Todorov
-
Eric Blake
-
Igor Serebryany
-
Laine Stump