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.
This commit is contained in:
Jiri Denemark 2010-05-27 14:47:11 +02:00
parent 208b2ad879
commit 1a5c465ee5
2 changed files with 34 additions and 10 deletions

View 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

View 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