#! /bin/bash
#
# The following is LSB information
### BEGIN INIT INFO
# Provides: rxapi
# Required-Start: $local_fs $network $time
# Required-Stop: $local_fs $network $time
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop rxapi daemon
# Description: rxapid provides the communication service for between all running
#	 ooRexx scripts
### END INIT INFO#
#
# rxapid.sh    Start/Stop the rxapi daemon.
#
# description: rxapi is a standard UNIX program which coordinates the sharing
#              of data betwenn multiple instances of ooRexx scripts.
# processname: rxapi
# pidfile:     /var/run/rxapi.pid

# Work around for Debian-based systems, maybe there is a better way...
is_debian_like=0

# Source function library.  If none of these work, then we haven't installed
# on this platform yet and the installer will need to figure out what will
# work.
if [ -e /etc/rc.d/init.d/functions ]; then
   . /etc/init.d/functions
elif [ -e /etc/rc.status ]; then
   . /etc/rc.status
elif [ -e /lib/lsb/init-functions ]; then
   . /lib/lsb/init-functions
   is_debian_like=1
fi

prog="rxapi"

start() {
	echo -n $"Starting $prog: "
        if [ -e /etc/rc.d/init.d/functions ]; then
	   daemon /usr/bin/rxapi
        elif [ -e /lib/lsb/init-functions ]; then
	   start_daemon /usr/bin/rxapi
        else
	   startproc /usr/bin/rxapi
        fi
	RETVAL=$?
	echo
	if [ $is_debian_like -eq 0 ]; then
	    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/rxapi
	else
	    [ $RETVAL -eq 0 ] && touch /var/lock/rxapi
	fi
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	if [ $is_debian_like -eq 0 ]; then
	    killproc rxapi
	else
	    killproc -p /var/run/ooRexx.pid rxapi
	fi
	RETVAL=$?
	echo
	if [ $is_debian_like -eq 0 ]; then
	    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/rxapi
	else
	    [ $RETVAL -eq 0 ] && rm -f /var/lock/rxapi
	fi
	return $RETVAL
}

rhstatus() {
	status /usr/bin/rxapi
}

restart() {
  	stop
	start
}

force-reload() {
	echo -n $"Force-reload not supported."
	echo
	return 0
}

# See how we were called.

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  status)
  	rhstatus
	;;
  force-reload)
  	force-reload
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|status|force-reload}"
	exit 1
esac
