#! /bin/bash -e

export PATH=/sbin:/bin:/usr/sbin:/usr/bin

NAME=pymsnt
DESC="MSN transport for Jabber"

PIDFILE=/var/run/pymsnt/$NAME.pid
USER=pymsnt

SSD_OPTS="--pidfile=$PIDFILE --name=python --user=$USER"

DAEMON=/usr/bin/python
OPTIONS="/usr/share/pymsnt/PyMSNt.py --config=/etc/pymsnt.conf.xml --background --pid=$PIDFILE -o spooldir=/var/lib/pymsnt --log=/var/log/pymsnt/pymsnt.log"

test -f $DAEMON || exit 0

case "$1" in
start)
	echo -n "Starting $DESC: "
	(start-stop-daemon --start $SSD_OPTS --startas "$DAEMON" --chuid "$USER" -- $OPTIONS)
	if test "$?" = 0; then echo "$NAME."; fi
	;;
stop)
	echo -n "Stopping $DESC: "
	(start-stop-daemon --stop $SSD_OPTS --retry 10)
	if test "$?" = 0; then echo "$NAME."; fi
	;;
reload|force-reload)
	echo -n "Reloading $DESC configuration..."
	(start-stop-daemon --stop $SSD_OPTS --signal HUP)
	if test "$?" = 0; then echo 'done.'; fi
	;;
restart)
	$0 stop
	$0 start
	;;
*)
	echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0

# vim: filetype=sh
