#!/bin/bash
#
# /etc/rc.d/init.d/groonga-httpd
#
# chkconfig: - 80 20
# description: A full-text search engine and column store.
# processname: groonga-httpd
# config: /etc/sysconfig/groonga-httpd
# pidfile: /var/run/groonga/groonga-httpd.pid
#
### BEGIN INIT INFO
# Provides:          groonga-httpd
# Default-Stop:      0 1 6
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Short-Description: groonga-httpd's init script
# Description:       groonga-httpd is a HTTP server for Groonga.
### END INIT INFO

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

name="groonga-httpd"
prog="groonga-httpd"
GROONGA_HTTPD=/usr/sbin/$prog
GROONGA_HTTPD_RESTART=/usr/sbin/$prog-restart
GROONGA_HTTPD_ARGS=""

if [ -f /etc/sysconfig/$name ]; then
	. /etc/sysconfig/$name
fi

DAEMON_ARGS=""

RETVAL=0

start() {
	echo -n $"Starting $prog: "
	if [ -f /var/lock/subsys/$prog ]; then
		passed
		RETVAL=0
	else
		daemon $DAEMON_ARGS ${GROONGA_HTTPD} ${GROONGA_HTTPD_ARGS}
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
	fi
	echo
	return $RETVAL
}

stop() {
	action $"Stopping $prog: " ${GROONGA_HTTPD} -s stop
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
	return $RETVAL
}

restart() {
	action $"Reloading $prog: " ${GROONGA_HTTPD_RESTART}
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
	return $RETVAL
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		if [ -f /var/lock/subsys/$prog ]; then
			restart
		else
			start
		fi
		;;
	reload)
		${GROONGA_HTTPD} -s reload
		;;
	condrestart)
		[ -f /var/lock/subsys/$prog ] && restart || :
		;;
	status)
		status $prog
		;;
	*)
		echo "Usage: $prog {start|stop|reload|restart|condrestart|status}"
		exit 1
		;;
esac
exit $?
