#!/bin/sh
#
# chkconfig: 345 81 45
# description: Starts and stops the http-replicator caching proxy

NAME="http-replicator"
DAEMON="/usr/bin/${NAME}"
CONFIG="/etc/sysconfig/${NAME}"
LOCKFILE=/var/lock/subsys/http-replicator

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

if LC_ALL=C grep -Eq "^\s*exit" $CONFIG
then
	gprintf "Not configured to run as a daemon on $CONFIG\n"
	exit 5
fi

# Source configuration
[ -f $CONFIG ] && . $CONFIG

RETVAL=0


start() {
	gprintf "Starting ${NAME}: "
	RETVAL=1
	daemon ${DAEMON} ${GENERAL_OPTS} ${DAEMON_OPTS}
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch ${LOCKFILE} || RETVAL=1
	return $RETVAL
}	
stop() {
	gprintf "Shutting down ${NAME}: "
	RETVAL=1
	killproc ${NAME}
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f ${LOCKFILE}
	return $RETVAL
}	
restart() {
	stop
	start
}	
reload() {
	export TMPDIR="/var/tmp"
        gprintf "Reloading ${NAME}: "
	killproc ${NAME} -HUP
	RETVAL=$?
	echo
	return $RETVAL
}	
mdkstatus() {
	status ${NAME}
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	reload
	;;
  status)
  	mdkstatus
	;;
  condrestart)
  	[ -f ${LOCKFILE} ] && restart || :
	;;
  *)
	gprintf "Usage: %s {start|stop|restart|status|condrestart}\n" "$0"
	exit 1
esac

exit $?
