#!/bin/sh
#
# c-icap	ICAP server.
#
# chkconfig: 345 90 10
# description:	Internet Content Adaptation \
#		Protocol (ICAP) server.
# processname: c-icap
# config: /etc/c-icap.conf
# pidfile: /var/run/c-icap/c-icap.pid

### BEGIN INIT INFO
# Provides:          c-icap
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:
# Default-Stop:
# Short-Description: Start c-icap at boot time
# Description:       Start Internet Content Adaptation Protocol server.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/run/c-icap/c-icap.pid
LOCKFILE=/var/lock/subsys/c-icap
CONFIG=/etc/c-icap.conf
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --user _c_icap -- c-icap -f "$CONFIG"
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user _c_icap -- c-icap
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload|restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user _c_icap -- c-icap
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
