|
|
c401cc |
From 632aa814a7f3e54f307e59aa824130e1bb5e8c33 Mon Sep 17 00:00:00 2001
|
|
|
c401cc |
Message-Id: <632aa814a7f3e54f307e59aa824130e1bb5e8c33@dist-git>
|
|
|
c401cc |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
c401cc |
Date: Mon, 24 Feb 2014 13:12:04 +0100
|
|
|
c401cc |
Subject: [PATCH] libvirt-guests: Wait for libvirtd to initialize
|
|
|
c401cc |
|
|
|
c401cc |
https://bugzilla.redhat.com/show_bug.cgi?id=1032695
|
|
|
c401cc |
|
|
|
c401cc |
I've noticed that in some cases systemd was quick enough and even
|
|
|
c401cc |
if libvirt-guests.service is marked to be started after the
|
|
|
c401cc |
libvirtd.service my guests were not resumed as
|
|
|
c401cc |
libvirt-guests.sh failed to connect. This is because of a
|
|
|
c401cc |
simple fact: systemd correctly starts libvirt-guests after it
|
|
|
c401cc |
execs libvirtd. However, the daemon is not able to accept
|
|
|
c401cc |
connections right from the start. It's doing some
|
|
|
c401cc |
initialization which may take ages. This problem is not limited
|
|
|
c401cc |
to systemd only, indeed. Any init system that is able to startup
|
|
|
c401cc |
services in parallel (e.g. OpenRC) may run into this situation.
|
|
|
c401cc |
The fix is to try connecting not only once, but continuously a few
|
|
|
c401cc |
times with a small sleep in between tries.
|
|
|
c401cc |
|
|
|
c401cc |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
c401cc |
(cherry picked from commit 4e7fc8305a53676ba2362bfaa8ca05c4851b7e12)
|
|
|
c401cc |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c401cc |
---
|
|
|
c401cc |
tools/libvirt-guests.sh.in | 19 +++++++++++++------
|
|
|
c401cc |
1 file changed, 13 insertions(+), 6 deletions(-)
|
|
|
c401cc |
|
|
|
c401cc |
diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in
|
|
|
c401cc |
index 38e93c5..4bbd4e4 100644
|
|
|
c401cc |
--- a/tools/libvirt-guests.sh.in
|
|
|
c401cc |
+++ b/tools/libvirt-guests.sh.in
|
|
|
c401cc |
@@ -37,6 +37,8 @@ SHUTDOWN_TIMEOUT=300
|
|
|
c401cc |
PARALLEL_SHUTDOWN=0
|
|
|
c401cc |
START_DELAY=0
|
|
|
c401cc |
BYPASS_CACHE=0
|
|
|
c401cc |
+CONNECT_RETRIES=10
|
|
|
c401cc |
+RETRIES_SLEEP=1
|
|
|
c401cc |
|
|
|
c401cc |
test -f "$sysconfdir"/sysconfig/libvirt-guests &&
|
|
|
c401cc |
. "$sysconfdir"/sysconfig/libvirt-guests
|
|
|
c401cc |
@@ -87,12 +89,17 @@ test_connect()
|
|
|
c401cc |
{
|
|
|
c401cc |
uri=$1
|
|
|
c401cc |
|
|
|
c401cc |
- run_virsh "$uri" connect 2>/dev/null
|
|
|
c401cc |
- if [ $? -ne 0 ]; then
|
|
|
c401cc |
- eval_gettext "Can't connect to \$uri. Skipping."
|
|
|
c401cc |
- echo
|
|
|
c401cc |
- return 1
|
|
|
c401cc |
- fi
|
|
|
c401cc |
+ for ((i = 0; i < ${CONNECT_RETRIES}; i++)); do
|
|
|
c401cc |
+ run_virsh "$uri" connect 2>/dev/null
|
|
|
c401cc |
+ if [ $? -eq 0 ]; then
|
|
|
c401cc |
+ return 0;
|
|
|
c401cc |
+ fi
|
|
|
c401cc |
+ sleep ${RETRIES_SLEEP}
|
|
|
c401cc |
+ eval_gettext "Unable to connect to libvirt currently. Retrying .. \$i"
|
|
|
c401cc |
+ done
|
|
|
c401cc |
+ eval_gettext "Can't connect to \$uri. Skipping."
|
|
|
c401cc |
+ echo
|
|
|
c401cc |
+ return 1
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
# list_guests URI PERSISTENT
|
|
|
c401cc |
--
|
|
|
c401cc |
1.9.0
|
|
|
c401cc |
|