#!/bin/sh
#
# refdb: Start the refdb bibliography tool application server
#        (for use as init.d or rc.d script)
#
# 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, see <http://www.gnu.org/licenses/>

# ***********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=<prefix>/bin/<program_prefix>refdbd<program_suffix>

# the full path to the script that actually starts and stops the application
REFDBCTL=<prefix>/bin/<program_prefix>refdbctl<program_suffix>

# 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

# 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 "Starting bibliography tool application server: $NAME."
	    $REFDBCTL start
	fi;;
    stop)
	if [ $BSDSTYLE = "YES" ]; then
	    $REFDBCTL stop > /dev/null && echo -n ' refdb'
	else
	    echo "Stopping bibliography tool application server: $NAME."
	    $REFDBCTL stop
	fi;;
    restart)
	if [ $BSDSTYLE = "YES" ]; then
	    $REFDBCTL restart > /dev/null && echo -n ' refdb'
	else
	    echo "Restarting bibliography tool application server: $NAME."
	    $REFDBCTL restart
	fi;;
    force-reload)
	if [ $BSDSTYLE = "YES" ]; then
	    $REFDBCTL reload > /dev/null && echo -n ' refdb'
	else
	    echo "Reloading bibliography tool application server: $NAME."
	    $REFDBCTL reload
	fi;;
    *)
	echo "Usage: $(basename $0) {start|stop|restart|force-reload}" >&2
	exit 1;;
esac

exit 0
