From: Jiri Denemark Date: Thu, 27 May 2010 12:47:11 +0000 (+0200) Subject: Fix libvirt-guests init script X-Git-Tag: v0.8.2~147 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a5c465ee5eb18c3bf7390a73da4beeb4448cd52;p=thirdparty%2Flibvirt.git Fix libvirt-guests init script 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. --- diff --git a/daemon/libvirt-guests.init.in b/daemon/libvirt-guests.init.in index b87c11b6cf..17e68249ef 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 + 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 diff --git a/libvirt.spec.in b/libvirt.spec.in index b8bd9ab60e..6edbf2faf8 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