Bittorrent seeder – Debian lenny

This how to is show how I have set up the program bittornado to run as a headless Bittorrent seeder. There are two configuration files. /etc/init.d/bt-seeder.sh to start and stop the program bittornado.btlaunchmany and the file /etc/default/bt-seeder which is where the program variables are set . All so I have added a system user named seeder to give more control and security.

First task is to install bittornado and then add system user named seeder.

sudo aptitude -R install bittornado

Now to add a system user named seeder. Then add two folders in the user seeder home folder. These two folders are named seeds.torrents and seeds. The folder seeds.torrents is where the bittorrent dot torrent files are placed and in the folder seeds is where the torrented data is stored.

sudo adduser --system --home /var/cache/btlaunchmany-sandbox
--shell /bin/sh --group --disabled-login seeder

sudo mkdir /var/cache/btlaunchmany-sandbox
sudo mkdir /var/cache/btlaunchmany-sandbox/seeds
sudo mkdir /var/cache/btlaunchmany-sandbox/seeds.torrents
sudo chown -R seeder:seeder /var/cache/btlaunchmany-sandbox

Second task to add the two configuration files.

sudo touch /etc/default/bt-seeder

Copy and paste to file: /etc/default/bt-seeder

# Default configuration for bittornado seeder, btlaunchmany.bittornado

# If you want the bittorrent seeder to run, switch this to 1.
START_BTLAUNCHMANY=1

# Set any btlaunchmany option --foo by defining the variable FOO to the argument
# you'd like to pass with the --foo option.  Run the command ' btlaunchmany.bittornado '
# for a detailed discussion of the options.

# Directory to look for .torrent files (semi-recursive)
DIRECTORY=/var/cache/btlaunchmany-sandbox/seeds.torrents

# local file name to save the file as, null indicates query user (defaults to '')
SAVEAS=/var/cache/btlaunchmany-sandbox/seeds

# Minimum port to listen on, counts up if unavailable
MINPORT=44400

# Maximum port to listen on
MAXPORT=44420

# Maximum kB/s to upload at (0 = no limit, -1 = automatic) (defaults to 0)
MAX_UPLOAD_RATE=5

# Maximum kB/s to download at (0 = no limit) (defaults to 0)
MAX_DOWNLOAD_RATE=5

# Whether to use special upload-efficiency-maximizing routines
# (only for dedicated seeds) (defaults to 0)
SUPER_SEEDER=0

# ip to report you have to the tracker. (defaults to '').
# if you are behind a NAT router use the WAN ip address here.
IP=
##
# The following options do not correspond to bttrack options; they influence how
# btlaunchmany's init script starts the daemon.

# Run under this uid.  Must have access to all files and directories involved,
# naturally, but should otherwise have minimal privileges to minimize any
# security risk.
DAEMONUSER=seeder

# Run the daemon at this "nice" priority.  Setting a positive value here will
# dissuade the system from giving all its CPU time to bttrack requests from the
# network.
DAEMONNICE=5

sudo touch /etc/init.d/bt-seeder.sh

Copy and paste to file: /etc/init.d/bt-seeder.sh

#! /bin/sh
### BEGIN INIT INFO
# Provides:          bittorrent
# Required-Start:    $network $local_fs
# Required-Stop:     $network $local_fs
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start a bittorrent seeder
# Description:       Starts a bittorrent seeder
#
### END INIT INFO

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="BitTorrent seeder"
NAME=btlaunchmany.bittornado
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/bt-seeder.sh

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

. /lib/lsb/init-functions

# Read config file if it is present.
if [ -r /etc/default/bt-seeder ]; then
        . /etc/default/bt-seeder
fi

# Add optional option $1 with argument $2 to OPTS, if $2 is nonempty
add_opt () {
        if ! test -z "$2" ; then
                OPTS="$OPTS $1 $2"
        fi
}

# Compose command-line arguments list for btlaunchmany daemon, based on variables
# set in /etc/default/bt-seeder
OPTS=""
add_opt --saveas "$SAVEAS"
add_opt --minport "$MINPORT"
add_opt --maxport "$MAXPORT"
add_opt --max_upload_rate "$MAX_UPLOAD_RATE"
add_opt --max_download_rate "$MAX_DOWNLOAD_RATE"
add_opt --super_seeder "$SUPER_SEEDER"
add_opt --ip "$IP"
DAEMONOPTS="$OPTS"

# Add arguments for start-stop-daemon, based on variables set in
# /etc/default/bt-seeder
OPTS=""
add_opt --chuid "$DAEMONUSER"
add_opt --nicelevel "$DAEMONNICE"
METAOPTS="$OPTS"

#
# Function that starts the daemon/service.
#
d_start() {
        if [ $START_BTLAUNCHMANY -ne 1 ]; then
                log_progress_msg "disabled in /etc/default/bt-seeder "
                return 1
        else
                start-stop-daemon --start --background --quiet
                --make-pidfile --pidfile "$PIDFILE"
                $METAOPTS
                --exec $DAEMON -- $DIRECTORY $DAEMONOPTS
                return 0
        fi
}

#
# Function that stops the daemon/service.
#
d_stop() {
        start-stop-daemon --stop --oknodo --quiet --pidfile "$PIDFILE"
        rm -f $PIDFILE
}

case "$1" in
  start)
        log_daemon_msg "Starting $DESC" "$NAME"
        d_start
        log_end_msg $?
        ;;
  stop)
        log_daemon_msg "Stopping $DESC" "$NAME"
        d_stop
        log_end_msg 0
        ;;
  restart|force-reload)
        log_daemon_msg "Restarting $DESC" "$NAME"
        d_stop
        sleep 1
        d_start
        log_end_msg $?
        ;;
  status)
        exit 4
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
        exit 2
        ;;
esac

exit 0

sudo chmod 755 /etc/init.d/bt-seeder.sh

sudo update-rc.d bt-seeder.sh defaults

This entry was posted in Bittorrent and tagged . Bookmark the permalink.

Comments are closed.