#!/bin/sh
# Startup script for prewikka
#
# chkconfig: 2345 98 01
# description: Run prewikka

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

# Get service config
if [ -f /etc/sysconfig/prewikka ]; then
	. /etc/sysconfig/prewikka
else
	nls "Error: %s not found" /etc/sysconfig/prewikka
	nls " Prewikka can't be run."
	exit 1
fi

start() {
	if [ ! -f /var/lock/subsys/prewikka ]; then
		msg_starting "Prewikka"
		daemon --user http --fork prewikka-httpd $PREWIKKA_OPTS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/prewikka
	else
		msg_already_running "Prewikka"
	fi
}

stop() {
	if [ -f /var/lock/subsys/prewikka ]; then
		msg_stopping "Prewikka"
		killproc prewikka-httpd
		rm -f /var/lock/subsys/prewikka
	else
		msg_not_running "Prewikka"
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/prewikka ]; then
		stop
		start
	else
		msg_not_running prewikka-httpd
		RETVAL=$1
	fi
}

RETVAL=0
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/prewikka ]; then
		msg_reloading "Prewikka"
		killproc prewikka-httpd -HUP
		RETVAL=$?
	else
		msg_not_running prewikka
		exit 7
	fi
	;;
  status)
	status prewikka
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
