This how to is show how I have set up the program Bittorrent to run as a tracker. There are three configuration files. The first file /etc/default/bt-tracker which is where the program variables are set. The second file /etc/init.d/bt-tracker.sh is to start and stop the program bttrack.bittorrent and the third file /etc/logrotate.d/bttrack that is the configuration file for logrotate, which looks after bttrack logs. All so I have added a system user named tracker to give more control and security.
I would run the tracker from the bittornado package but there is a bug with the bttrack part of the program. So I run the tracker from the original bittorrent package.
sudo aptitude install bittorrent
Now to add a system user named tracker
sudo adduser --system --home /var/local/lib/bttrack-sandbox
--shell /bin/sh --group --disabled-login tracker
Then add a folder where the .torrent files are stored.
sudo mkdir /srv/tracker
sudo chown tracker:tracker /srv/tracker
And add a folder and file for where the tracker torrent info is stored.
sudo mkdir /var/lib/tracker
sudo touch /var/lib/tracker/bttrack.state
sudo chown -R tracker:tracker /var/lib/tracker/
Now make the file where the tracker variables are set
sudo touch /etc/default/bt-tracker
Copy and paste to file: /etc/default/bt-tracker
# Default configuration for bittorrent tracker, bttrack.bittorrent
# If you want the bittorrent tracker to run, switch this to 1.
# If you change this, you will probably want to change
# ALLOWED_DIR as well, or anyone will be able to track anything
# just by pointing the .torrent at your server.
START_BTTRACK=1
# Set any bttrack option --foo by defining the variable FOO to the argument
# you'd like to pass with the --foo option. Run the command ' bttrack.bittorrent '
# for a detailed discussion of the options.
# Port defaults to 80, which tends to be inconvenient
PORT=6969
# Store recent downloader info in filename
DFILE=/var/lib/tracker/bttrack.state
# BitTornado
# Whether to display an info page when the tracker's root dir is
# loaded (defaults to 1)
# SHOW_INFOPAGE=1
# If set to 1, the tracker will show filenames of torrents that it
# knows about in its allowed_dir, instead of just showing
# info_hash's on its status page.
SHOW_NAMES=1
# Use this to restrict the files which your tracker will track.
# This parameter specifies a directory name, and it will only track
# torrents that exist in this directory. If this parameter is present
# you must somehow place the .torrent file in the specified directory
# before the tracker will accept it.
ALLOWED_DIR=/srv/tracker
# Use with allowed_dir; adds a /file?hash={hash} url that allows
# users to download the torrent file (defaults to 0)
ALLOW_GET=1
# File containing x-icon data to return when browser requests
# favicon.ico (defaults to '')
FAVICON=/var/local/lib/bttrack-sandbox/favicon.ico
# Append log output from daemon to this file. Make sure this log is rotated
# from time to time so it doesn't fill up your disk. The daemon will of course
# need write access to the log file.
DAEMONLOGFILE=/var/log/tracker/bttrack.log
# How many times to check if a downloader is behind a NAT
# (0 = don't check) (defaults to 3)
NAT_CHECK=3
# BitTornado
# Whether to add entries to the log for nat-check results (defaults to 0)
# LOG_NAT_CHECKS=1
##
# The following options do not correspond to bttrack options; they influence how
# bttrack'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=tracker
# 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-tracker.sh
Copy and paste to file: /etc/init.d/bt-tracker.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 tracker
# Description: Starts a bittorrent tracker, which
# aids bittorrent clients by locating
# other clients.
### END INIT INFO
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="BitTorrent tracker"
NAME=bttrack.bittorrent
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/bt-tracker.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-tracker ]; then
. /etc/default/bt-tracker
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 bttrack daemon, based on variables
# set in /etc/default/bt-tracker
OPTS=""
add_opt --dfile "$DFILE"
add_opt --port "$PORT"
add_opt --save_dfile_interval "$SAVE_DFILE_INTERVAL"
add_opt --nat_check "$NAT_CHECK"
add_opt --allowed_dir "$ALLOWED_DIR"
add_opt --show_names "$SHOW_NAMES"
add_opt --favicon "$FAVICON"
add_opt --logfile "$DAEMONLOGFILE"
add_opt --show_infopage "$SHOW_INFOPAGE"
add_opt --allow_get "$ALLOW_GET"
add_opt --log_nat_checks "$LOG_NAT_CHECKS"
DAEMONOPTS="$OPTS"
# Add arguments for start-stop-daemon, based on variables set in
# /etc/default/bt-tracker
OPTS=""
add_opt --chuid "$DAEMONUSER"
add_opt --nicelevel "$DAEMONNICE"
METAOPTS="$OPTS"
#
# Function that starts the daemon/service.
#
d_start() {
if [ $START_BTTRACK -ne 1 ]; then
log_progress_msg "disabled in /etc/default/bt-tracker "
return 1
else
start-stop-daemon --start --background --quiet
--make-pidfile --pidfile "$PIDFILE"
$METAOPTS
--exec $DAEMON -- $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-tracker.sh
sudo update-rc.d bt-tracker.sh defaults
sudo touch /etc/logrotate.d/bttrack
Copy and paste to file: /etc/logrotate.d/bttrack
/var/log/tracker/bttrack.log {
daily
rotate 7
compress
missingok
create 0640 tracker
copytruncate
}
Make a folder for the log files to go in.
sudo mkdir /var/log/tracker
Then make the file for the logs.
sudo touch /var/log/tracker/bttrack.log
sudo chown -R tracker:tracker /var/log/tracker
Notes: When the bug in bittornado.bttrack is fix I will change the line in.
/etc/init.d/bt-tracker.sh line 21
NAME=bttrack.bittorrent to : NAME=bttrack.bittornado
Then tracker will be back to using the bittornado package.
Run as a Open Tracker
In the configuration file /etc/default/bt-tracker change the option ” ALLOWED_DIR=/srv/tracker” to “ALLOWED_DIR=”.
The tracker will then be open to any one to use it. All they need to do is make their .torrent file with your tracker url.
Example : http://Domainname:6969/announce Check out OpenBitTorrent to see this method in action.