#!/bin/sh
#
# wwwoffle	WWW proxy allowing offline view of cached pages
#
# chkconfig:	2345 85 20
#
# description:	WWW proxy allowing offline view of cached pages


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

# Get network config
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/wwwoffle ] && . /etc/sysconfig/wwwoffle

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down wwwoffle
		exit 1
	fi
else
	exit 0
fi

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/wwwoffle ]; then
		msg_starting wwwoffle
		daemon wwwoffled
		RETVAL=$?
		if [ $RETVAL -eq 0 ]; then
			touch /var/lock/subsys/wwwoffle
			[ -n "$ACTION" ] && wwwoffle "$ACTION" 2>&1 > /dev/null &
		fi
	else
		msg_already_running wwwoffled
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/wwwoffle ]; then
		# Stop daemons.
		msg_stopping wwwoffle
		killproc wwwoffled
		rm -f /var/lock/subsys/wwwoffle 2>&1 > /dev/null
	else
		msg_not_running wwwoffled
	fi
	;;
  restart)
	$0 stop
	$0 start
	exit $?
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/wwwoffle ]; then
		msg_reloading wwwoffled
		killproc wwwoffled -HUP
		RETVAL=$?
	else
		msg_not_running wwwoffled >&2
		exit 7
	fi
	;;
  status)
	status wwwoffled
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
