#!/bin/sh
#
# jabber-jit	This shell script takes care of starting and stopping
#               jabber-jit standalone Jabber component.
#
# chkconfig: 2345 71 29
# description: ICQ transport for Jabber
# processname: jabberd-jit
# config:  /etc/jabber-jit/jabber-jit.xml
# pidfile: /var/run/jabberd-jit/jabber-jit.pid
#
### BEGIN INIT INFO
# Provides:          jabber-jit
# Required-Start:    $syslog $network
# Required-Stop:     $syslog $network
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts ICQ transport for Jabber
# Description:       starts JIT which provides a gateway that allows Jabber users to communicate with their
#                    contacts on the ICQ Messenger network. It can connect to any Jabber server
#                    that supports the Connect component mechanism.  
### END INIT INFO

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

# Source networking configuration.
. /etc/sysconfig/network

JIT_CONF=/etc/jabber-jit/jabber-jit.xml
LOCKFILE=/var/lock/subsys/jabber-jit
PIDFILE=/var/run/jabber-jit/jabber-jit.pid
JIT_USER=_jabber_jit

# Check that networking is up.
[ $NETWORKING = "no" ] && exit 0

RETVAL=0

start()
{
        # start daemon
	start_daemon \
	    --lockfile "$LOCKFILE" \
	    --pidfile "$PIDFILE" \
	    --user "$JIT_USER" \
	    -- /usr/sbin/jabber-jit -d -H /usr/lib64/jabber-jit -c "$JIT_CONF"
	RETVAL=$?
}

stop()
{
	stop_daemon \
	    --lockfile "$LOCKFILE" \
	    --pidfile "$PIDFILE" \
	    --expect-user "$JIT_USER" \
	    -- /usr/sbin/jabber-jit
	RETVAL=$?
}

reload()
{
	# cause the service configuration to be reread, either with kill -HUP:
	echo -n "Rereading Jabber-JIT configuration: "
	stop_daemon -HUP \
	    --pidfile "$PIDFILE" \
	    --expect-user "$JIT_USER" \
	    -- /usr/sbin/jabber-jit
	RETVAL=$?
	# or by simple restarting the daemons in a manner similar to restart above.
}


# See how we were called.
case "$1" in
    start)
	start
        ;;
    stop)
	stop
        ;;
    reload)
	reload
	;;
    restart)
	stop
	start
	;;
    condstop)
	# Stop the servce if it is already running, for example:
	if [ -e "$LOCKFILE" ]; then
 	  stop
	fi
	;;
    condrestart)
	# Restart the servce if it is already running, for example:
	if [ -e "$LOCKFILE" ]; then
	  stop
 	  start
	fi
	;;
    status)
	status \
	    --pidfile "$PIDFILE" \
	    --expect-user "$JIT_USER" \
	    -- /usr/sbin/jabber-jit
	RETVAL=$?
	;;
    *)
	echo "Usage: ${0##*/} {start|stop|reload|restart|condstop|condrestart|status}"
	RETVAL=1

esac

exit $RETVAL
