[libvirt] [PATCH] daemon: Modify init script to check for libvirtd managed with upstart

On some systems init scripts are installed along with upstart . This may cause trouble if user tries to restart/stop a instance of libvirtd managed with upstart with init script. This patch adds check for a started libvirtd managed by upstart and fails the init script. [root@localhost ~]# initctl status libvirtd libvirtd start/running, process 3001 [root@localhost ~]# service libvirtd restart Stopping libvirtd daemon: error: libvirtd is managed by upstart and started, use initctl instead If libvirtd is not managed by upstart or is stopped, init script works normaly and allows the user to manage the service. https://bugzilla.redhat.com/show_bug.cgi?id=728153 --- daemon/libvirtd.init.in | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/daemon/libvirtd.init.in b/daemon/libvirtd.init.in index 0697a2b..823fa77 100644 --- a/daemon/libvirtd.init.in +++ b/daemon/libvirtd.init.in @@ -43,6 +43,8 @@ LIBVIRTD_CONFIG= LIBVIRTD_ARGS= KRB5_KTNAME=/etc/libvirt/krb5.tab +INITCTL_PATH=/sbin/initctl + test -f @sysconfdir@/sysconfig/libvirtd && . @sysconfdir@/sysconfig/libvirtd export QEMU_AUDIO_DRV @@ -56,8 +58,22 @@ fi RETVAL=0 +# Check if libvirt is managed by upstart and fail if it's the case +initctl_check() { + if [ -x $INITCTL_PATH ]; then + #extract status from upstart + LIBVIRTD_UPSTART_STATUS=`$INITCTL_PATH status libvirtd | tr "/" " " | cut -d " " -f 2` + if [ $LIBVIRTD_UPSTART_STATUS = "start" ]; then + echo "error: libvirtd is managed by upstart and started, use initctl instead" + exit 1 + fi + fi +} + start() { echo -n $"Starting $SERVICE daemon: " + initctl_check + mkdir -p @localstatedir@/cache/libvirt rm -rf @localstatedir@/cache/libvirt/* KRB5_KTNAME=$KRB5_KTNAME daemon --pidfile $PIDFILE --check $SERVICE $PROCESS --daemon $LIBVIRTD_CONFIG_ARGS $LIBVIRTD_ARGS @@ -68,6 +84,7 @@ start() { stop() { echo -n $"Stopping $SERVICE daemon: " + initctl_check killproc -p $PIDFILE $PROCESS RETVAL=$? @@ -88,6 +105,7 @@ restart() { reload() { echo -n $"Reloading $SERVICE configuration: " + initctl_check killproc -p $PIDFILE $PROCESS -HUP RETVAL=$? -- 1.7.3.4

On Wed, Sep 21, 2011 at 12:46:33PM +0200, Peter Krempa wrote:
On some systems init scripts are installed along with upstart . This may cause trouble if user tries to restart/stop a instance of libvirtd managed with upstart with init script.
This patch adds check for a started libvirtd managed by upstart and fails the init script.
[root@localhost ~]# initctl status libvirtd libvirtd start/running, process 3001 [root@localhost ~]# service libvirtd restart Stopping libvirtd daemon: error: libvirtd is managed by upstart and started, use initctl instead
If libvirtd is not managed by upstart or is stopped, init script works normaly and allows the user to manage the service.
https://bugzilla.redhat.com/show_bug.cgi?id=728153 --- daemon/libvirtd.init.in | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
NACK - Hosts should not have both the SysV initscript & upstart script installed at the same time - Even if both are installed together, there is no reason why a libvirtd started by upstart cannot be stopped be SysV init and vica-verca, since libvirtd puts its pidfile in the same place regardless of how it is launched Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 09/21/2011 01:17 PM, Daniel P. Berrange wrote:
On Wed, Sep 21, 2011 at 12:46:33PM +0200, Peter Krempa wrote:
On some systems init scripts are installed along with upstart . This may cause trouble if user tries to restart/stop a instance of libvirtd managed with upstart with init script.
This patch adds check for a started libvirtd managed by upstart and fails the init script.
[root@localhost ~]# initctl status libvirtd libvirtd start/running, process 3001 [root@localhost ~]# service libvirtd restart Stopping libvirtd daemon: error: libvirtd is managed by upstart and started, use initctl instead
If libvirtd is not managed by upstart or is stopped, init script works normaly and allows the user to manage the service.
https://bugzilla.redhat.com/show_bug.cgi?id=728153 --- daemon/libvirtd.init.in | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) NACK
- Hosts should not have both the SysV initscript& upstart script installed at the same time Well, they should not, but they do. And vdsm causes that upstart is used for libvirt even if rest of the system uses SysV.
- Even if both are installed together, there is no reason why a libvirtd started by upstart cannot be stopped be SysV init and vica-verca, since libvirtd puts its pidfile in the same place regardless of how it is launched. Because the upstart script states that the libvirtd process should respawn as soon as it exits, it's not possible for a SysV script to terminate
Vdsm requires that libvirtd is restarted in case of a crash/quit and abuses upstart and his "respawn" stanza. libvirtd. Stop operation of the SysV script kills the libvirtd process and soon after that it's restarted again by upstart as configured. Another way aroun this would be to detect if libvirtd is managable via upstart at the beginning of the SysV script and hand control over to upstart if this is the case. Peter
Daniel
participants (2)
-
Daniel P. Berrange
-
Peter Krempa