#! /bin/bash
#
# larpe        Startup script for the Larpe reverse proxy
#
# description: Larpe is Liberty Alliance reverse proxy.  It is used to add Liberty Alliance \
#           features to some sites without modifying the sites themselves.
# processname: larpe
# config: /etc/httpd/conf.d/larpe.conf
# config: /etc/larpe/apache2-vhost-larpe-common
# config: /etc/sysconfig/larpe
# pidfile: /var/run/larpe.pid
#

### BEGIN INIT INFO
# Provides:          larpe
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs $network
# Default-Start:
# Default-Stop:      0 1 2 3 4 5 6
# Short-Description: Start Larpe Liberty Alliance reverse proxy
# Description:       Start Larpe Liberty Alliance reverse proxy
### END INIT INFO

prog=larpe
LARPECTL=/usr/sbin/larpectl
PIDFILE=/var/run/larpe.pid

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

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

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

[ -x $LARPECTL ] || exit 5

# Read config file if it is present.
if [ -f /etc/sysconfig/larpe ]; then
	. /etc/sysconfig/larpe
fi

RETVAL=0

#
# Function that starts the daemon/service.
#
start() {
	echo -n $"Starting $prog: "
	$LARPECTL start &
	RETVAL=$?
	if [ $RETVAL -eq 0 ]
	then
		touch /var/lock/subsys/$prog
	fi
	echo
	return $RETVAL
}

#
# Function that stops the daemon/service.
#
stop() {
	echo -n $"Stopping $prog: "
	killproc $LARPECTL
	RETVAL=$?
	if [ $RETVAL -eq 0 ]
	then
		rm -rf /var/lock/subsys/$prog
	fi
	echo
	return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
	;;
	stop)
		stop
	;;
	status)
		status $prog
		RETVAL=$?
	;;
	restart)
		stop
		start
	;;
	condrestart)
		if [ -f ${PIDFILE} ] ; then
			stop
			start
		fi
	;;
	*)
		echo $"Usage: $prog {start|stop|restart|condrestart|status}"
		exit 1
esac

exit $RETVAL

