[PATCH] Fix libvirt-guests init script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Firstly, the init script has to touch its file under /var/lock/subsys
when started, otherwise system would think it's not running and won't
stop it during shutdown.

Secondly, for some reason there is a policy to automatically enable
init scripts when they are installed, so let the specfile do this. We
also need to start the init script to ensure it will be stopped during
the first shutdown after installing the package.
---
 daemon/libvirt-guests.init.in |   11 ++++++++++-
 libvirt.spec.in               |   17 ++++++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/daemon/libvirt-guests.init.in b/daemon/libvirt-guests.init.in
index b87c11b..a08ed82 100644
--- a/daemon/libvirt-guests.init.in
+++ b/daemon/libvirt-guests.init.in
@@ -37,6 +37,7 @@ SHUTDOWN_TIMEOUT=0
 test -f "$sysconfdir"/sysconfig/libvirt-guests && . "$sysconfdir"/sysconfig/libvirt-guests
 
 LISTFILE="$localstatedir"/lib/libvirt/libvirt-guests
+VAR_SUBSYS_LIBVIRT_GUESTS="$localstatedir"/lock/subsys/libvirt-guests
 
 RETVAL=0
 
@@ -117,12 +118,17 @@ guest_is_on() {
     return 0
 }
 
+started() {
+    touch $VAR_SUBSYS_LIBVIRT_GUESTS
+}
+
 start() {
-    [ -f $LISTFILE ] || return 0
+    [ -f $LISTFILE ] || { started; return 0; }
 
     if [ "x$ON_BOOT" != xstart ]; then
         echo $"libvirt-guests is configured not to start any guests on boot"
         rm -f $LISTFILE
+        started
         return 0
     fi
 
@@ -155,6 +161,7 @@ start() {
     done <$LISTFILE
 
     rm -f $LISTFILE
+    started
 }
 
 suspend_guest()
@@ -257,6 +264,8 @@ stop() {
             fi
         done
     done <$LISTFILE
+
+    rm -f $VAR_SUBSYS_LIBVIRT_GUESTS
 }
 
 gueststatus() {
diff --git a/libvirt.spec.in b/libvirt.spec.in
index b8bd9ab..6edbf2f 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -707,7 +707,22 @@ if [ $1 = 0 ]; then
 fi
 %endif
 
-%post client -p /sbin/ldconfig
+%preun client
+
+if [ $1 = 0 ]; then
+    /sbin/chkconfig --del libvirt-guests
+    rm -f /var/lib/libvirt/libvirt-guests
+fi
+
+%post client
+
+/sbin/ldconfig
+/sbin/chkconfig --add libvirt-guests
+if [ $1 -ge 1 ]; then
+    # this doesn't do anything but allowing for libvirt-guests to be
+    # stopped on the first shutdown
+    /sbin/service libvirt-guests start > /dev/null 2>&1 || true
+fi
 
 %postun client -p /sbin/ldconfig
 
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]