Tuesday, February 23, 2010

Set up the transmission-deamon BitTorrent Client in FreeBSD

I switched over to FreeBSD a while back and still am in the process of configuring it the way my Ubuntu server used to be set up. One of the things I used to have was uTorrent running, via wine, and auto-loading torrents from a shared directory. This allowed me to queue downloads from anywhere and have them auto-download. It is not possible to set up my 32bit FreeBSD box the same was as ZFS prevents wine from operating. (This is a known issue due to the custom kernel with an increased memory map.)

As such I was looking for a similar solution that would run as a daemon and could automatically process torrent files. And as it turns out the transmission-daemon package does exactly that. Following is a brief review of setting up this service and some customizations I did.

I installed the transmission-daemon package via the ports tree.
cd /usr/ports/net-p2p/transmission-daemon
sudo portinstall -P

Daemon Configuration
I created my own /usr/local/srv/torrent directory and set up transmission to use it. This path is also shared out to the network via NFS.
sudo -u transmission mkdir -p /usr/local/srv/torrent/{data,autoload}
chmod -R g+w /usr/local/srv/torrent

I added the following to my rc.conf so that transmission would use the new paths.
sudo vim /etc/rc.conf

You have to start and then stop transmission so it will create its configuration files
sudo /usr/local/etc/rc.d/transmission --start
sudo /usr/local/etc/rc.d/transmission --stop

Transmission Configuration
Now edit the transmission configuration file to change a few settings. Only the settings listed below need to be changed now, the rest can be managed after the daemon is up and running with the transmission-remote command. The first few settings force authentication and add the local subnet to the white list for remote access. The blacklist setting will cause transmission to ignore any hosts in the optional blacklist file. The last settings changes the file creation mask so that members of the transmission group can manage the downloads.
sudo -u transmission vim /usr/local/etc/transmission/home/settings.json
  "rpc-authentication-required": true,
  "rpc-username": "admin",
  "rpc-password": "password",
  "rpc-whitelist": ",192.168.1.*",
  "blocklist-enabled": true,
  "umask": 2,

Blacklist Configuration
You can fetch a copy of the peer blacklist with the following command.
sudo -u transmission wget -NP /usr/local/etc/transmission/home/blocklists http://update.transmissionbt.com/level1.gz

And add the following line to sron so it updates every night.
sudo -u transmission crontab -e
  0 0 * * * /usr/local/bin/wget -NP ~/blocklists http://update.transmissionbt.com/level1.gz && gunzip -f ~/bl

Final Steps
You will also want to add your user to the transmission group so that you can directly manage downloads.
sudo pw groupmod transmission -m USERNAME

The configureation is all don and we can start the server up for real now.
sudo /usr/local/etc/rc.d/transmission --start

You can now tweak the torrent server properties as necessary with the following command
transmission-remote --auth admin:password

You can also view and manage torrents from the web interface at http://localhost:9091.

Also this Firefox add-on can be used to add torrents directly to transmission from any computer on the network instead of using the network share or there are client applications.


Olli Kaven said...

Thanks for the guide! Got everything working very well.

However, 'sudo pw usermod USERNAME -G transmission' did remove my user from the wheel group. Better to use 'sudo pw groupmod transmission -m USERNAME'

remsus.ru said...

Thank you! very accessible written - now translate their own web-based resources with ubuntu server freebsd. Looking for a solution and found this, thanks again for the article.
P.S. I would like to place your article in their blog, of course, with a link to your page

lauren said...

Just now I read one of your other article and I must say the way you present the information is really amazing and easy to follow.Thanks.Keep it up!
digital certificates

Unknown said...

Ditto what Olli said. Your article makes extensive use of the sudo command. but, if you follow all the steps, you won't be sudoing for long, as you will remove yourself from the wheel group, which for most users means they will not longer be able to sudo. Please update your article to use a correct command for adding yourself to the transmission group: sudo pw groupmod transmission -m USERNAME

Jeremy Pyne said...

Thanks for the note. I updated the code.