#!/bin/sh
#
# IIim		Start and stop IIIM server
#
# chkconfig: 2345 87 17
# description: a major component of IIIMSF.

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

NAME=htt
HTT="/usr/sbin/htt"
LOCKER="/var/lock/subsys/htt"
OPTIONS="-retryonerror 0"
RETVAL=0

USER=htt
RUNDIR=/var/run/iiim

test -x $HTT || exit 0

start() {
	if [ ! -f $LOCKER ]; then
		echo -n $"Starting IIIMF input server: "
		# make sure USER owns unix socket directory
		[ -d "${RUNDIR}" ] && chown ${USER}:${USER} -R ${RUNDIR}
		daemon --user $USER $HTT $OPTIONS 2>&1 </dev/null
		echo
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch $LOCKER
	else
		return 0
	fi
	return $RETVAL
}

stop() {
        echo -n $"Stopping IIIMF input server: "
	killproc $NAME
	echo
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f $LOCKER
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $NAME
        ;;
  restart|reload)
        stop
        start
        ;;
  condrestart)
        if [ -f $LOCKER ]; then
            stop
            start
        fi
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        exit 1
esac

exit $RETVAL
