[Ovirt-devel] [PATCH server] added ovirt-wait4service and invokation in installer to wait for psql/ldap

Mohammed Morsi mmorsi at redhat.com
Tue Jun 23 20:00:53 UTC 2009


FIXME this patch isn't complete, still need to figure out the ldap command to
wait for that service, something along the lines of:
 ldapsearch -b dc=priv,dc=ovirt,dc=org -x
(but how will we parse the base from the installer? also this cmd
 fails, how to fix?)
---
 installer/modules/ovirt/manifests/ovirt.pp    |    8 +++++-
 installer/modules/ovirt/manifests/postgres.pp |   13 ++++++---
 ovirt-server.spec.in                          |    2 +
 scripts/ovirt-wait4service                    |   34 +++++++++++++++++++++++++
 4 files changed, 52 insertions(+), 5 deletions(-)
 create mode 100755 scripts/ovirt-wait4service

diff --git a/installer/modules/ovirt/manifests/ovirt.pp b/installer/modules/ovirt/manifests/ovirt.pp
index d953ebe..f293375 100644
--- a/installer/modules/ovirt/manifests/ovirt.pp
+++ b/installer/modules/ovirt/manifests/ovirt.pp
@@ -111,9 +111,15 @@ class ovirt::setup {
 
         single_exec { "create_ovirtadmin_acct" :
 		command => "/usr/share/ovirt-server/script/grant_admin_privileges ovirtadmin",
-                require => [Single_Exec[db_migrate],Single_exec[set_ldap_hostname],Single_exec[set_ldap_dn]]
+                require => [Single_Exec[db_migrate],Single_exec[wait_for_ldap]]
 	}
 
+        single_exec { "wait_for_ldap" :
+                command => "/usr/bin/ovirt-wait4service 'true' 10 2",
+                require => [Single_exec[set_ldap_hostname],Single_exec[set_ldap_dn]]
+        }
+ 
+
         single_exec { "set_ldap_hostname" :
                 command => "/bin/sed -i -e 's/management.priv.ovirt.org/$ipa_host/' /usr/share/ovirt-server/config/ldap.yml",
                 require => Package[ovirt-server]
diff --git a/installer/modules/ovirt/manifests/postgres.pp b/installer/modules/ovirt/manifests/postgres.pp
index c46b360..9a4afa1 100644
--- a/installer/modules/ovirt/manifests/postgres.pp
+++ b/installer/modules/ovirt/manifests/postgres.pp
@@ -45,14 +45,19 @@ class postgres::bundled{
                 hasstatus => true
         }
 
+        single_exec { "wait_for_postgres" :
+                command => "/usr/bin/ovirt-wait4service 'psql -l -U postgres' 10 2",
+                require => Service[postgresql]
+        }
+
         single_exec {"create_ovirt_db":
 		command => "/usr/bin/createdb ovirt -U postgres",
-		require => [Exec[postgres_add_all_trust], Service[postgresql]]
+		require => [Exec[postgres_add_all_trust], Single_exec[wait_for_postgres]]
         }
 
 	single_exec {"create_ovirt_development_db":
                 command => "/usr/bin/createdb ovirt_development -U postgres",
-                require => [Exec[postgres_add_all_trust], Service[postgresql]]
+                require => [Exec[postgres_add_all_trust], Single_exec[wait_for_postgres]]
         }
 
 	postgres_execute_command {"ovirt_db_create_role":
@@ -70,13 +75,13 @@ class postgres::bundled{
 	exec {"postgres_add_all_trust":
                 command => "/bin/echo 'local all all trust' > /var/lib/pgsql/data/pg_hba.conf",
 		require => Single_exec[initialize_db],
-		notify => Service[postgresql]
+		notify => Single_exec[wait_for_postgres]
         }
 
 	exec {"postgres_add_localhost_trust":
 		command => "/bin/echo 'host all all 127.0.0.1 255.255.255.0 trust' >> /var/lib/pgsql/data/pg_hba.conf",
 		require => Exec[postgres_add_all_trust],
-                notify => Service[postgresql]
+                notify => Single_exec[wait_for_postgres]
         }
 
 	file { "/etc/ovirt-server/" :
diff --git a/ovirt-server.spec.in b/ovirt-server.spec.in
index 1569a9a..eff1f2f 100644
--- a/ovirt-server.spec.in
+++ b/ovirt-server.spec.in
@@ -132,6 +132,7 @@ touch %{buildroot}%{_localstatedir}/log/%{name}/db-omatic.log
 
 %{__cp} -a %{pbuild}/scripts/ovirt-add-host %{buildroot}%{_bindir}
 %{__cp} -a %{pbuild}/scripts/ovirt-vm2node %{buildroot}%{_bindir}
+%{__cp} -a %{pbuild}/scripts/ovirt-wait4service %{buildroot}%{_bindir}
 %{__cp} -a %{pbuild}/scripts/ovirt-reindex-search %{buildroot}%{_sbindir}
 %{__cp} -a %{pbuild}/scripts/ovirt-update-search %{buildroot}%{_sbindir}
 %{__rm} -rf %{buildroot}%{app_root}/tmp
@@ -205,6 +206,7 @@ fi
 %{_sbindir}/ovirt-update-search
 %{_bindir}/ovirt-add-host
 %{_bindir}/ovirt-vm2node
+%{_bindir}/ovirt-wait4service
 %{_initrddir}/ovirt-host-browser
 %{_initrddir}/ovirt-db-omatic
 %{_initrddir}/ovirt-host-collect
diff --git a/scripts/ovirt-wait4service b/scripts/ovirt-wait4service
new file mode 100755
index 0000000..65dbe2a
--- /dev/null
+++ b/scripts/ovirt-wait4service
@@ -0,0 +1,34 @@
+#!/bin/sh
+# ovirt-wait4service
+# run a command a specified number times or until succesful, 
+#   sleeping a specified number of seconds between tries
+
+testcmd=$1; shift
+n_retries=$1; shift
+sleep_seconds=$1; shift
+total=$((n_retries*sleep_seconds))
+
+print_usage(){
+   echo "ovirt-wait4service test_command number_of_retries seconds_between_retries"
+}
+
+if [ "$testcmd" == "" -o  \
+     "$sleep_seconds" == "" -o \
+     "$n_retries" == "" ]; then
+   print_usage
+   exit 1
+fi
+
+echo "running command $testcmd $n_retries times or until succesful, sleeping $sleep_seconds seconds between tries"
+
+while [ $n_retries -gt 0 ]
+do
+echo $n_retries
+  eval "$testcmd" > /dev/null 2>&1 && exit 0
+  echo service not ready yet, retrying...
+  n_retries=$((n_retries-1))
+  sleep $sleep_seconds
+done
+
+printf 'service not ready after %d seconds, giving up\n' $total 1>&2
+exit 1
-- 
1.6.0.6




More information about the ovirt-devel mailing list