#!/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: virtlockd
# Default-Start: 3 4 5
# Short-Description: virtual machine lock manager
# Description: This is a daemon for managing locks
#              on virtual machine disk images
### END INIT INFO

# the following is chkconfig init header
#
# virtlockd:   virtual machine lock manager
#
# chkconfig: 345 97 03
# description:  This is a daemon for managing locks \
#               on virtual machine disk images
#
# processname: virtlockd
# pidfile: @localstatedir@/run/libvirt/virtlockd.pid
#

# Source function library.
. @sysconfdir@/rc.d/init.d/functions

SERVICE=virtlockd
PROCESS=virtlockd
PIDFILE=@localstatedir@/run/libvirt/lockd/$SERVICE.pid

VIRTLOCKD_ARGS=

test -f @sysconfdir@/sysconfig/virtlockd && . @sysconfdir@/sysconfig/virtlockd

RETVAL=0

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

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

    killproc -p $PIDFILE $PROCESS
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        rm -f @localstatedir@/lock/subsys/$SERVICE
        rm -f $PIDFILE
    fi
}

restart() {
    stop
    start
}

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

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

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