#! /bin/sh
### BEGIN INIT INFO
# Provides:          vk4xmpp
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts VKontakte transport for Jabber
# Description:       starts VKontakte which provides a gateway that allows Jabber users to communicate with their
#                    contacts on VKontakte. It can connect to any Jabber server
#                    that supports the Connect component mechanism.  
### END INIT INFO
# 
# chkconfig: - 90 10
# /etc/init.d/jabber-vk4xmpp: start and stop VK4XMPP Transport service

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

OPTIONS="--config /etc/jabber-vk4xmpp/vk4xmpp.conf"

NAME=jabber-vk4xmpp
DESC="VKontakte transport"
PIDFILE=/var/run/$NAME/$NAME.pid
LOCKFILE=/var/lock/subsys/$NAME
DAEMON="runbg /usr/share/$NAME/gateway.py"
USER=_vk4xmpp
RETVAL=0

start()
{
start_daemon --pidfile "$PIDFILE" --name $NAME --lockfile "$LOCKFILE" --user $USER -- $DAEMON "$OPTIONS"
RETVAL=$?
return $RETVAL
}

stop()
{
stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --name $NAME --expect-user $USER -- $DAEMON
RETVAL=$?
return $RETVAL
}

restart()
{
stop
start
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload | restart)
restart
;;
condstop)
if [ -e "$LOCKFILE" ]; then
stop
fi
;;
condreload | condrestart)
if [ -e "$LOCKFILE" ]; then
restart
fi
;;
status)
status --pidfile "$PIDFILE" --name $NAME --expect-user $USER -- $DAEMON
RETVAL=$?
;;
*)
msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
RETVAL=1
esac

exit $RETVAL
