[libvirt] [PATCH] Fix libvirt-guests init script

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

On 05/28/2010 09:16 AM, Jiri Denemark wrote:
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.
Makes sense.
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
touch "$VAR_SUBSYS_LIBVIRT_GUESTS"
+} + start() { - [ -f $LISTFILE ] || return 0 + [ -f $LISTFILE ] || { started; return 0; }
Do we want to detect failures in started (that is, failure to touch the lock file)? Then again, failure to touch the lock file merely means that stop won't be called automatically, but doesn't affect whether we actually started and can call stop manually, so blindly succeeding seems okay to me.
+ + rm -f $VAR_SUBSYS_LIBVIRT_GUESTS
rm -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ACK with those tweaks. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 05/28/2010 09:29 AM, Eric Blake wrote:
On 05/28/2010 09:16 AM, Jiri Denemark wrote:
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.
Makes sense.
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
touch "$VAR_SUBSYS_LIBVIRT_GUESTS"
+} + start() { - [ -f $LISTFILE ] || return 0 + [ -f $LISTFILE ] || { started; return 0; }
On rereading this email, we should also s/\$LISTFILE/"\1"/g throughout the script. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

+started() { + touch $VAR_SUBSYS_LIBVIRT_GUESTS
touch "$VAR_SUBSYS_LIBVIRT_GUESTS"
+} + start() { - [ -f $LISTFILE ] || return 0 + [ -f $LISTFILE ] || { started; return 0; }
Do we want to detect failures in started (that is, failure to touch the lock file)? Then again, failure to touch the lock file merely means that stop won't be called automatically, but doesn't affect whether we actually started and can call stop manually, so blindly succeeding seems okay to me.
Yeah, I think that's fine. Also no other init script seems to check it either.
+ + rm -f $VAR_SUBSYS_LIBVIRT_GUESTS
rm -f "$VAR_SUBSYS_LIBVIRT_GUESTS"
ACK with those tweaks.
Thanks for the review. I made the corrections you suggested here and in the next email and pushed. Jirka
participants (2)
-
Eric Blake
-
Jiri Denemark