#!/bin/bash
#
# Startup script for tigase XMPP server
#
# chkconfig: - 85 15
# description: Tigase is a Java XMPP server
#

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

export TIGASE_DIR=/usr/share/tigase/
exec=$TIGASE_DIR/scripts/tigase.sh
prog=tigase
config=/etc/tigase/tigase.conf
lockfile=/var/lock/subsys/$prog
RETVAL=0

start() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6
    echo -n $"Starting $prog: "
    daemon $exec start 
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    daemon $exec stop
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status $tigase
	RETVAL=$?
	;;
  force_restart|restart)
	stop
	start
	;;
  condrestart)
	if [ -f /var/log/tigase/tigase.log.*.lck ] ; then
		stop
		start
	fi
	;;
  *)
	gprintf "Usage: %s {start|stop|restart|status|help}\n" "$prog"
	exit 1
esac

exit $RETVAL
