#! /bin/bash
### BEGIN INIT INFO
# Provides:          pyyimt
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

set -e

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

NAME=pyyimt
DESC="Yahoo transport for Jabber"

PIDDIR=/opt/pyyimt
PIDFILE=$PIDDIR/$NAME.pid
USER=jabber
GROUP=jabber

SSD_OPTS="--pidfile=$PIDFILE --name=python2.5 --user=$USER"

DAEMON=/usr/bin/python2.5
OPTIONS="/opt/pyyimt/src/yahoo.py"

test -f $DAEMON || exit 0

if test ! -e $PIDDIR; then
	mkdir $PIDDIR
	chown $USER:$GROUP $PIDDIR
fi

case "$1" in
start)
	echo -n "Starting $DESC: "
	(start-stop-daemon --start $SSD_OPTS --background --chdir "$PIDDIR/src" --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