#!/bin/sh
#
# jabber-jit	This shell script takes care of starting and stopping
#               jabber-jit standalone Jabber component.
#
# chkconfig: - 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

# 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
