#! /bin/sh
#
# jabber-pymsnt MSN transport for jabber servers.
#
# chkconfig:    - 95 10
# description:  PyMSN-t transport is a external component for a Jabber server \
#               which allows to aggregate MSN contacts into jabber
# processname:  python
# config:       /etc/pymsnt.xml
# pidfile:      /var/lib/pymsnt/pid

WITHOUT_RC_COMPAT=1

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

PYTHON=/usr/bin/python
EXE=/usr/share/pymsnt/PyMSNt.py
CONF=/etc/pymsnt.xml
PIDFILE=/var/run/pymsnt/pid
LOCKFILE=/var/lock/subsys/pymsnt
RETVAL=0

start()
{
    action "Starting MSN component:" \
	start-stop-daemon --start --pidfile "$PIDFILE" \
	--background --chuid _pymsnt --exec "$PYTHON" -- "$EXE" -c "$CONF"
    RETVAL=$?
    [ "$RETVAL" -ne 0 ] || touch "$LOCKFILE"
    return $RETVAL
}

stop()
{
    action "Stopping MSN component:" \
	start-stop-daemon --stop --pidfile "$PIDFILE" --user _pymsnt --exec "$PYTHON"
    RETVAL=$?
    [ "$RETVAL" -ne 0 ] || rm -f -- "$LOCKFILE" "$PIDFILE"
    return $RETVAL
}

restart()
{
    stop
    start
}

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

exit $RETVAL
