#!/bin/sh
#
# $Id: reaim,v 1.3 2003/03/26 11:59:30 mark-c Exp $
# 
#   ReAim startup / shutdown script.  Based on RedHat 8.0 distribution
#   scripts for other GPL'd packages.
#
#   This script is designed for systems that have a user called reaim
#   defined, as this id is used for the log file.
#
#   Linux chkconfig stuff:
#
#   chkconfig: 2345 50 50
#   description: ReAIM Messaging Proxy
#
#   processname: reaim
#   pidfile: /var/run/reaim.pid

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

RETVAL=0
prog="reaim"
# Command line flags to the program
flags=""
LOG_FILE="/var/log/reaim.log"
USER_NAME="reaim"

start() {
	touch "$LOG_FILE"
	chown "$USER_NAME" "$LOG_FILE"
	echo -n $"Starting $prog: "
        daemon --user "$USER_NAME" "/usr/sbin/$prog" "$flags"
	RETVAL="$?"
	echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
	return $RETVAL
}

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

reload(){
	echo -n $"Reloading $prog: "
	killproc $prog -HUP
	RETVAL="$?"
	echo
	return $RETVAL
}

restart(){
	stop
	start
}

condrestart(){
    [ -e /var/lock/subsys/$prog ] && restart
    return 0
}

condstop(){
    [ -e /var/lock/subsys/$prog ] && stop
    return 0
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
        ;;
  reload)
	reload
        ;;
  condrestart)
	condrestart
	;;
  condstop)
	condstop
	;;
  status)
        status $prog
	RETVAL=$?
        ;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|condstop|reload}"
	RETVAL=1
esac

exit $RETVAL
