#!/bin/sh

# the following is the LSB init header see
# http://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/initscrcomconv.html
#
### BEGIN INIT INFO
# Provides:          virtlogd
# Required-Start:    $network $remote_fs
# Required-Stop:     $network $remote_fs
# Default-Start:     3 5
# Default-Stop:      0 1 2 4 6
# Should-Start
# Should-Stop:
# Short-Description: virtual machine log manager
# Description:       This is a daemon for managing logs
#                    of virtual machine consoles
### END INIT INFO

# the following is chkconfig init header
#
# virtlogd:          virtual machine log manager
#
# chkconfig:         345 96 04
# description:       This is a daemon for managing logs \
#                    of virtual machine consoles
#
# processname:       virtlogd
# pidfile:           /var/run/virtlogd.pid
#

. /etc/rc.status
rc_reset

SERVICE=virtlogd
PROCESS=/usr/sbin/virtlogd
PIDFILE=/var/run/$SERVICE.pid

VIRTLOGD_ARGS=

test -f /etc/sysconfig/virtlogd && . /etc/sysconfig/virtlogd


start() {
    echo -n $"Starting $SERVICE "
    test -d $PIDDIR || mkdir -p $PIDDIR
    startproc -p $PIDFILE $PROCESS --pid-file $PIDFILE --daemon $VIRTLOGD_ARGS
    rc_status -v
}

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

    killproc -p $PIDFILE $PROCESS > /dev/null 2>&1
    RETVAL=$?
    rc_status -v
    if [ $RETVAL -eq 0 ]; then
        rm -f $PIDFILE
    fi
}

restart() {
    stop
    start
}

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

    killproc -p $PIDFILE $PROCESS -USR1
    rc_status
}

# See how we were called.
case "$1" in
    start|stop|restart|reload)
        $1
        ;;
    status)
        echo -n "Checking status of $SERVICE "
        checkproc $PROCESS
        rc_status -v
        ;;
    force-reload)
        reload
        ;;
    condrestart|try-restart)
        $0 status >/dev/null && restart || :
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload|try-restart}"
        rc_failed 2
        rc_exit
        ;;
esac
rc_exit
