]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix libvirt-guests init script
authorJiri Denemark <jdenemar@redhat.com>
Thu, 27 May 2010 12:47:11 +0000 (14:47 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 28 May 2010 16:00:53 +0000 (18:00 +0200)
Firstly, the init script has to touch its file under /var/lock/subsys
when started, otherwise the 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.

Also $LISTFILE should be enclosed by quotes everywhere as suggested by
Eric.

daemon/libvirt-guests.init.in
libvirt.spec.in

index b87c11b6cfcc2d7f67a2c31a734b586aafcb46a4..17e68249ef8e170f8a43a0938d868c21e6e7df51 100644 (file)
@@ -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
+        rm -f "$LISTFILE"
+        started
         return 0
     fi
 
@@ -152,9 +158,10 @@ start() {
                 fi
             fi
         done
-    done <$LISTFILE
+    done <"$LISTFILE"
 
-    rm -f $LISTFILE
+    rm -f "$LISTFILE"
+    started
 }
 
 suspend_guest()
@@ -210,7 +217,7 @@ shutdown_guest()
 
 stop() {
     # last stop was not followed by start
-    [ -f $LISTFILE ] && return 0
+    [ -f "$LISTFILE" ] && return 0
 
     suspending=true
     if [ "x$ON_SHUTDOWN" = xshutdown ]; then
@@ -222,7 +229,7 @@ stop() {
         fi
     fi
 
-    : >$LISTFILE
+    : >"$LISTFILE"
     for uri in $URIS; do
         echo -n $"Running guests on $uri URI: "
         list=$(list_guests $uri)
@@ -237,7 +244,7 @@ stop() {
                 echo $"no running guests."
             else
                 echo
-                echo $uri $list >>$LISTFILE
+                echo $uri $list >>"$LISTFILE"
             fi
         fi
     done
@@ -256,7 +263,9 @@ stop() {
                 shutdown_guest $uri $guest
             fi
         done
-    done <$LISTFILE
+    done <"$LISTFILE"
+
+    rm -f "$VAR_SUBSYS_LIBVIRT_GUESTS"
 }
 
 gueststatus() {
@@ -277,7 +286,7 @@ case "$1" in
     force-reload)
         ;;
     status)
-        if [ -f $LISTFILE ]; then
+        if [ -f "$LISTFILE" ]; then
             RETVAL=3
         else
             RETVAL=0
index b8bd9ab60ea508bbe2cfb806dd61d9269151f523..6edbf2faf88f11ec973be66d87d8ff6676681398 100644 (file)
@@ -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