#!/bin/sh
#
# cvsupd    Start/Stop the cvsup daemon.
#
# chkconfig: 345 57 49
# description: CVSup is a method for automatically checking out files in a \
#     CVS repository.  It can also be used for CVS mirroring.  This program \
#     starts after xinetd and stops before it, as I run CVS out of xinetd.
# processname: cvsupd
# config: /etc/cvsupd/cvsupd.conf
# pidfile: /var/run/cvsupd.pid
#
# Jason Corley <Jason.Corley@Borland.com>
#

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

# Source in config file
[ -r "/etc/cvsupd/cvsupd.conf" ] && . /etc/cvsupd/cvsupd.conf || exit 0

# Source networking configuration and check that networking is up.
if [ -f /etc/sysconfig/network ] ; then
    . /etc/sysconfig/network
    [ ${NETWORKING} = "no" ] && exit 0
fi

# Check to see that cvsupd exists
[ -x /usr/sbin/cvsupd ] || exit 0

RETVAL=0

start()
{
    if [ -f /var/lock/subsys/cvsupd ]; then
        echo -n $"$prog is already started..."
        echo_failure
        echo
        exit 0
    else
        echo -n $"Starting $prog: "
        daemon --user=$user /usr/sbin/cvsupd -A $ip -p $port -b $configbase \
            -c $collPath -C $maxClients -l $logfile $options
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cvsupd && pidofproc cvsupd \
            > /var/run/cvsupd.pid
        return $RETVAL
    fi
}

stop()
{
    if [ -f /var/lock/subsys/cvsupd ]; then
        echo -n $"Stopping $prog: "
        killproc cvsupd
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/cvsupd && \
            rm -f /var/run/cvsupd.pid
        return $RETVAL
    else
        echo -n $"$prog is not started..."
        echo_failure
        echo
        exit 0
    fi
}

restart() {
    stop
    start
}

condrestart() {
    [ -e /var/lock/subsys/cvsupd ] && restart
    return 0
}

#
#    See how we were called.
#
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  condrestart)
    condrestart
    ;;
  status)
    status cvsupd
    ;;
  *)
    echo "Usage: /etc/rc.d/init.d/$prog {start|stop|restart|condrestart|status}"
    exit 1
esac

exit $?
