Raspberry Pi as a Torrentbox

This article is a follow-up of my earlier post about how to run a Raspberry Pi box as an always-on NAS box. I figured that since I only have a theoretical maximum of 4 concurrent clients in the house, and none of them are intensive users, I might as well squeeze out some more juice out of the Pi to run as an always-on torrentbox. Internet speeds in Indonesia are notoriously slow, and even downloading the Raspbian Wheezy image takes quite a while. Scheduling the download for off-peak hours (middle of the night, or mid-day when nobody is in the house) seems to be reasonable. I could even schedule the machine to be a seeder during those hours, and for once give back to the torrent community. (confession: I’m usually a leecher and stop seeding once my download is completed)

Choice of Clients

I like the idea of thin client access, which minimizes resource usage on the Pi itself. That’s why I chose Deluge. I did try using Transmission, and the fact that I need to run the Transmission desktop client on X so that I can access its web UI appalled me. So there you go, Deluge FTW!

Thin Client Installation

To install Deluge Thin Client, I did this as the pi user:

sudo apt-get install deluge
sudo apt-get install deluge-console

I log in as mysambauser to do everything, so that the thin client will run as mysambauser. Why? Because I think running it as a user who already has access to the USB HDD mounts makes a lot more sense than adding pi to the sambausers user group. If I wanted to be more careful, I’d create an entirely new user, let’s say deluge-user, put it in the sambausers group, and work from there. But I’m too lazy for that. Ha!

Alright, let’s login as mysambauser:

su mysambauser

Now let’s run deluged so that it generates a config file and then kill it afterwards:

pkill deluged

Alright, that should do it. Now, let’s create a backup of the config file:

cp ~/.config/deluge/auth ~/.config/deluge/auth.old
sudo pico ~/.config/deluge/auth

Go the end of the file and add the user/password/access level of your liking. I went like this:


Not the best, I know, but for the sake of example it’ll do. Now, go into the console:


Once inside, I went:

config -s allow_remote True

After that, I went like this to check that the setting is indeed changed:

config allow_remote

After I was sure remote is allowed, I exit the deluge console by, surely enough, typing exit. Then, I restart deluge daemon:

pkill deluged
Deluge Console
Setting up remote access.

Right. All done for the Pi for now. Time to install Deluge client on my PC. Downloads are available at the Deluge website. After installing it, I fire it up and go to preferences:

Deluge Desktop 01
Preferences menu.

I then disable classic mode by unchecking that first checkbox:

Deluge Desktop 02
Disable classic mode.

I then have to restart Deluge client to load the classic interface, and be presented with the connection manager.

Deluge Desktop 03
Connection manager.

Next, I enter mysambauser’s credentials (leaving the port alone for now), and click connect.

Deluge Desktop 04
Host credentials.

Alright, so now I can control my Pi’s torrents from the comfort of my PC without having to keep my PC on to do the actual download. Cool bananas!

Web Interface Setup

Now, I’d like to have web access to my Deluge thin client. First, I log out of mysambauser’s shell to get back to pi’s shell by pressing Ctrl-D, then:

sudo apt-get install python-mako
sudo apt-get install deluge-web

Next, I switch back to mysambauser:

su mysambauser

Then I run deluge-web and kill it, to make it create a configuration file that I can edit:

deluge-web -f
pkill deluge-web

The -f flag up there tells deluge-web to fork the current interface. If you don’t do it, the console will just sit there and wait and you’d have to exit by hitting Ctrl-C. Not pretty. Deluge should’ve given some warning about this. Anyway, I go and edit the configuration file:

sudo pico ~/.config/deluge/web.conf

I just change the port. I don’t like using the default port. Alright then, now I start deluge-web again:

deluge-web -f

Next, I browse from my PC to [Pi’s-IP-address-here]:[deluge-web’s-port]. I log in using the default password “deluge” and chose to change it immediately. Done.

Download Locations

I’d want my downloads to go to my external hard drive, lest my SD card become crowded and eventually run out of space. I do this by going to Preferences, Downloads, and set up my directories there. This is the reason why I use the mysambauser user instead of the default pi user, because pi doesn’t have access to my external hard drive.

I create four directories under /media/USBHDD1/Torrents: Backup, Completed, Incomplete, and Watch. Next, I add a samba share location to the Torrents directory. This way I can just drop torrents into the Watch folder or copy completed torrents from my Completed folder. Easy.

To test, simply copy a torrent file into the Watch directory. It’ll immediately disappear and be whisked to the Backup directory, and if you’re watching your desktop client or web UI, the torrents will show up and immediately start downloading. Delightful!

Setting Up Deluge to Start On Boot

To have the Pi start Deluge on boot, I’m going to skip the scripts and just use the download link the guys at HowToGeek.com provided:

sudo wget -O /etc/default/deluge-daemon http://cdn8.howtogeek.com/wp-content/uploads/gg/up/sshot5151a8c86fb85.txt
sudo chmod 755 /etc/default/deluge-daemon
sudo nano /etc/default/deluge-daemon

I change the user to mysambauser, and then do this to download the actual init script:

sudo wget -O /etc/init.d/deluge-daemon http://cdn8.howtogeek.com/wp-content/uploads/gg/up/sshot5151aa042ad11.txt
sudo chmod 755 /etc/init.d/deluge-daemon
sudo update-rc.d deluge-daemon defaults

Alright, time to reboot now:

sudo reboot

After rebooting, if you can’t find the web UI, there’s something wrong either with the permissions, the hard drive mounting, or the init script itself. I won’t get into it as I experienced no problems at this point.

So, there you have it, I now have a Pi box capable of leeching (and seeding torrents) automatically just by dropping a torrent file into the Watch folder, and can be controlled either with a desktop client or web UI. As before, any comments or suggestions are welcome. Cheers!