#! /bin/sh
#

## Fedora Info
# chkconfig: 2345 20 80
### BEGIN INIT INFO
# Provides:          pkg-cacher
# Required-Start:    
# Should-Start:      mountall
# Required-Stop:     
# Should-Stop:       
# Default-Start:     2 3 4 5
# Default-Stop:      0 6
# Short-Description: pkg-cacher package caching proxy daemon 
# Description:       The pkg-cacher service is used to cache packages for a system or LAN
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Pkg-Cacher"
NAME=pkg-cacher
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

# Read config file if it is present.
if [ -r /etc/sysconfig/$NAME ]
then
	. /etc/sysconfig/$NAME
fi

. /etc/init.d/functions

#
#	Function that starts the daemon/service.
#
d_start() {

    if test "$AUTOSTART" = 1 ; then
        daemon $DAEMON -d $EXTRAOPT
    else
        echo -n " (not enabled in /etc/sysconfig/$NAME)";
    fi
}

#
#	Function that stops the daemon/service.
#
d_stop() {
	killproc $DAEMON
}

case "$1" in
  start)
	echo -n "Starting $DESC: $NAME"
	d_start
	;;
  stop)
	echo -n "Stopping $DESC: $NAME"
	d_stop
	;;
  restart)
	echo -n "Restarting $DESC: $NAME"
	d_stop
	sleep 1
	d_start
	echo "."
	;;
  force-reload|reload)
	echo -n "Reloading configuration of $DESC: $NAME"
    pid=`cat $PIDFILE`
    if test -z "$pid" ; then
        echo ", NOT RUNNING"
    else
        kill -HUP $pid
    fi
	echo "."
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
