#!/bin/sh
#
# bitlbee	IRC gateway to IM chat networks
#
# chkconfig: - 95 10
# description: IRC gateway to IM chat networks
# processname: bitlbee
# pidfile: /var/run/bitlbee.pid
# config: /etc/bitlbee/bitlbee.conf

. /etc/init.d/functions

PIDFILE=/var/run/bitlbee.pid
LOCKFILE=/var/lock/subsys/bitlbee
USER=bitlbee
BITLBEE_ARGS="-F -u $USER"

SourceIfExists /etc/sysconfig/bitlbee

BITLBEE=/usr/sbin/bitlbee
[ -x "$BITLBEE" ] || exit

start()
{
	msg_starting $"IRC gateway to IM chat networks"
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --no-announce --expect-user "$USER" -- $BITLBEE $BITLBEE_ARGS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	msg_stopping $"IRC gateway to IM chat networks"
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --no-announce --expect-user "$USER" -- bitlbee
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

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

exit $RETVAL
