#!/bin/sh
#
# start/stop the btpd daemon.
# (c) Copyright 2007 Cesare Falco
#
# Licensed under the BSD License.
# See the file /usr/share/common-licenses/BSD
#

set -e

### BEGIN INIT INFO
# Provides:             btpd
# Required-Start:       $time $syslog $remote_fs $network
# Required-Stop:        $time $syslog $remote_fs $network
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Bittorrent Protocol Daemon
# Description:          btpd is a bittorrent client consisting of a daemon
#                       capable of running several torrents simultaneously
#                       using one single tcp port.
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/btpd
USER=btpd
NAME=btpd
DAEMON_OPTS=

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

# include btpd defaults
if [ -f /etc/default/btpd ] ; then
	. /etc/default/btpd
fi

case "$1" in
  start)
    log_begin_msg "Starting the Bittorrent Protocol Daemon..."
	start-stop-daemon --start --quiet --oknodo --name $NAME --user $USER \
        --chuid $USER --exec $DAEMON -- $DAEMON_OPTS
    log_end_msg $?
	;;

  stop)
    log_begin_msg "Stopping the Bittorrent Protocol Daemon..."
	start-stop-daemon --stop --quiet --oknodo --name $NAME --user $USER --retry 5
    log_end_msg $?
	;;

  # btpd has no configuration files, however force-reload is mandatory
  restart|force-reload)
    $0 stop
    $0 start
	;;

  *)
    log_success_msg "Usage: /etc/init.d/btpd {start|stop|restart|force-reload}"
	exit 1
	;;
esac

exit 0
