#!/bin/sh
#
# refdb: Start the refdb bibliography tool application server
#        (for use as init.d or rc.d script)
#
# chkconfig: 2345 93 7
# description: Starts and stops the RefDB daemon
#
# processname: refdbd
# pidfile: /var/run/refdbd.pid

### BEGIN INIT INFO
# Provides: refdb
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Description: RefDB is a reference database and bibliography tool for SGML, XML, and LaTeX/BibTeX documents
# Short-Description: RefDB, bibliography database
### END INIT INFO

# markus@mhoenicka.de 2001-7-22

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
  
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
  
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# ***********IMPORTANT*************
# This file is configured for SysV-style systems (most Linux distributions and
# a few commercial Unices). If you want to use the script on a BSD-style
# system (Slackware, {Free|Net|Open}BSD and a few commercial Unices), these
# two changes are recommended:
# 1. Set the value of BSDSTYLE to "YES" a few lines below
# 2. Rename the file to refdb.sh
# *********************************
 
# the name of the application
NAME=refdb

# set some default path
#PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin

# the full path to the binary that is to be started as a daemon
DAEMON=/usr/bin/refdbd

# the full path to the script that actually starts and stops the application
REFDBCTL=/usr/bin/refdbctl

# set to 'YES' if the OS uses a BSD-style daemon startup system (this is
# true for BSD-UNIX and Unices derived thereof, as well as for the
# Slackware Linux distribution). This setting does not perform any black
# magic, but it makes the screen messages at startup match the OS style
BSDSTYLE=NO

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

. /etc/sysconfig/network

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

REFDB_BIN=/usr/bin/refdbd
test -x $REFDB_BIN || exit 5

DAEMON_NAME=refdb
DAEMON_PROCESS=refdbd
DAEMON_BINARY=/usr/bin/refdbd
LOCK_FILE=/var/lock/subsys/$DAEMON_NAME

# default option, they can be overriden in /etc/sysconfig/$DAEMON_NAME
# of course, you can place what you want.

OPTIONS=
PORT=5432

# this file should be commented, with proper pointer to the doc, and you should use
# more than one line of option, if possible.

[ -f /etc/sysconfig/$DAEMON_NAME ] && . /etc/sysconfig/$DAEMON_NAME

# don't get interrupted
trap "" 1

# see whether all ingredients are available
test -f $DAEMON || exit 1
test -f $REFDBCTL || exit 1

# now run the specified command
case "$1" in
    start)
	if [ $BSDSTYLE = "YES" ]; then
	    $REFDBCTL start > /dev/null && echo -n ' refdb'
	else
	    echo -ne "Starting bibliography tool application server: $NAME.\n"
	    $REFDBCTL start
	fi;;
    stop)
	if [ $BSDSTYLE = "YES" ]; then
	    $REFDBCTL stop > /dev/null && echo -n ' refdb'
	else
	    echo -ne "Stopping bibliography tool application server: $NAME.\n"
	    $REFDBCTL stop
	fi;;
    status)
	status refdb
	;;
    restart)
	if [ $BSDSTYLE = "YES" ]; then
	    $REFDBCTL restart > /dev/null && echo -n ' refdb'
	else
	    echo -ne "Restarting bibliography tool application server: $NAME.\n"
	    $REFDBCTL restart
	fi;;
    force-reload)
	if [ $BSDSTYLE = "YES" ]; then
	    $REFDBCTL reload > /dev/null && echo -n ' refdb'
	else
	    echo -ne "Reloading bibliography tool application server: $NAME.\n"
	    $REFDBCTL reload
	fi;;
    *)
	echo "Usage: $(basename $0) {start|stop|status|restart|force-reload}" >&2
	exit 1;;
esac

exit 0
