#!/bin/sh

# the following is the LSB init header see
# http://www.linux-foundation.org/spec//booksets/LSB-Core-generic/LSB-Core-generic.html#INITSCRCOMCONV
#
### BEGIN INIT INFO
# Provides: libvirt-qpid
# Should-Start: libvirtd
# Short-Description: gateway daemon to interact with libvirt viq qpid
# Description: This is a daemon for interacting with libvirt viq qpid QMF.
### END INIT INFO

# the following is chkconfig init header
#
# libvirt-qpid:   gateway daemon to interact with libvirt viq qpid
#
# chkconfig: - 98 03
# description: This is a daemon for interacting with libvirt viq qpid QMF.
#
# processname: libvirt-qpid
# pidfile: /var/run/libvirt-qpid.pid
#

# Sanity checks.
[ -x /usr/sbin/libvirt-qpid ] || exit 0

# Source function library.
. /etc/rc.d/init.d/functions

SERVICE=libvirt-qpid
PROCESS=libvirt-qpid

RETVAL=0

test -f /etc/sysconfig/libvirt-qpid && . /etc/sysconfig/libvirt-qpid

start() {
    echo -n $"Starting $SERVICE daemon: "
    daemon --check $SERVICE $PROCESS --daemon $LIBVIRT_QPID_ARGS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SERVICE
}

stop() {
    echo -n $"Stopping $SERVICE daemon: "

    killproc $PROCESS
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        rm -f /var/lock/subsys/$SERVICE
        rm -f /var/run/$SERVICE.pid
    fi
}

restart() {
    stop
    start
}

reload() {
    echo -n $"Reloading $SERVICE configuration: "

    killproc $PROCESS -HUP
    RETVAL=$?
    echo
    return $RETVAL
}

# See how we were called.
case "$1" in
    start|stop|restart|reload)
        $1
        ;;
    status)
        status $PROCESS
        RETVAL=$?
        ;;
    force-reload)
        reload
	;;
    condrestart|try-restart)
        [ -f /var/lock/subsys/$SERVICE ] && restart || :
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload}"
	exit 2
        ;;
esac
exit $RETVAL
