Build a Media Server - Background

How to install Deluge (v1.2.x) headless on Ubuntu Server

Deluge is a great BitTorrent client that you can install on Ubuntu to allow you to share your favourite files with the rest of the BitTorrent community.

In the How to configure Torrents & TED on Ubuntu Server guide we installed Deluge and ran it via the VNC session.

In the newer versions of Ubuntu, Deluge comes in two parts; the server (also called the daemon) and the user interface. This means you can install the Deluge daemon as a headless service and then control it from a remote machine. You can either control the daemon using the Deluge client itself (for example the Windows version of Deluge) or alternatively you can use your browser to control it. If you've not installed VNC and are running a purely headless setup then running Deluge headless is pretty much your only option! So, here's how you install it:

At the time of writing Deluge version 1.2.x is still in development. If you wish to install the released version of Deluge (v1.1.9) then see the guide here: Installing Headless Deluge version 1.1.9

Updating the Source Repository

We firstly need to make a simple change to add the Release Candidate version of Deluge as a valid Ubuntu "source repository".

So, type the following command into your Putty session or directly into the command line on your server:

sudo vim /etc/apt/sources.list

and type your Ubuntu password if prompted. This will open a file called sources.list which lives in the /etc/apt folder.

TIP: If you're using Putty you can save yourself some typing by highlighting the required strings below then right-clicking on them and selecting Copy. Then toggle over to your Putty session and right-click once more. The strings you highlighted here should be pasted into the sources.list file in Putty.

Once you've opened the sources.list file scroll down to the bottom of the file and then press the [Insert] key once (to go into "edit" mode) and insert a new empty line at the bottom of the file. Next type or paste the following two strings into the file:

deb http://ppa.launchpad.net/deluge-team/ppa/ubuntu karmic main
deb-src http://ppa.launchpad.net/deluge-team/ppa/ubuntu karmic main

Now press the [Esc] key once and type the following:

:wq

This should save your changes and bring you back to the command line. If you make a mistake editing the file then issue :q! instead of :wq to abort your changes.

Next we need to type or paste the following string to validate the two sources we've just added:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 249AD24C

Next type/paste:

sudo apt-get update

Now we need to create a new user called "deluge" and perform a couple more steps. So type/paste the following:

sudo adduser --disabled-password --system --home /var/lib/deluge --gecos "SamRo Deluge server" --group deluge

sudo touch /var/log/deluged.log

sudo touch /var/log/deluge-web.log

sudo chown deluge:deluge /var/log/deluge*

Install the Deluge Daemon

Next we'll install the Deluge daemon itself:

sudo apt-get update

sudo apt-get install deluged

 Next we'll install the Web interface by typing:

sudo apt-get install deluge-webui

Run the Deluge Daemon on startup

Now we've got the components installed we need to make everything run on start-up. So, let's create the first script we need by typing the following command in a Putty Session:

sudo vim /etc/default/deluge-daemon

This will create and open a file called deluge-daemon

Next, assuming you're using Putty, highlight the following 5 commands, right-click on them and select Copy

# Configuration for /etc/init.d/deluge-daemon
# The init.d script will only run if this variable non-empty.
DELUGED_USER="deluge"
# Should we run at startup?
RUN_AT_STARTUP="YES"

Toggle back to the Putty Session and press the [Insert] key once and then right click and the 5 lines we've just copied above will be pasted into the file.

Now press the [Esc] key once and type :wq to save and quit out of the script. If you make a mistake editing the file then issue :q! instead of :wq to abort your changes.

Creating the "Init Script"

Now we need an "init script". This script is rather long but we can do some more copying and pasting to implement this script. So, type the following command in your Putty Session to create and open the script:

sudo vim /etc/init.d/deluge-daemon

Next, highlight and copy this script.

Toggle back to your Putty Session and press the [Insert] key once and then right click and the whole script you've just highlighted will be pasted into the screen.

IMPORTANT: By default the init script starts the Deluge Daemon on port 9092. However, Squeezebox Server also uses port 9092. So, if you're installing Squeezebox Server along with this release of Deluge then you must change the port that the Deluge Daemon uses else only one of these two application will work at any one time. ie. you'd have to stop one application running so that you can run the other one. So, the line in the script which currently reads:

DAEMON2_ARGS="-p 9092 -c /var/lib/deluge -l /var/log/deluge-web.log -L warning"

must be changed to:

DAEMON2_ARGS="-p 8112 -c /var/lib/deluge -l /var/log/deluge-web.log -L warning"

As before, press the [Esc] key once and type :wq to save and quit out of the script. If you make a mistake editing the file then issue :q! instead of :wq to abort your changes.

We now need to make this script executable. So:

sudo chmod a+x /etc/init.d/deluge-daemon

Now we need to make sure this script runs on start-up. To do this type the following command:

sudo update-rc.d deluge-daemon defaults

Cross your fingers and restart the server by typing the following command:

sudo reboot -h now

Accessing Deluge via the web interface

You should now be able to access the Web front-end for Deluge by typing http://MyMediaserver:9092 into the address bar of your browser where MyMediaserver is the name you gave to your server when you installed Ubuntu. Alternatively the IP address of the server works just as well.
NOTE: If you've changed the port number in the script above (from 9092 to 8112) then make sure you start the Web front-end using the correct port. eg. http://MyMediaserver:8112

You should now be presented with the Deluge login-screen. Enter deluge for the password and you should then see a screen similar to this:

Deluge Web UI

Opening the correct ports on your router

Inorder to start downloading Torrents you need to open up some ports on your router. If you click on the Preferences icon (the screwdriver/spanner) on the Deluge web interface and select Network, the Incoming Ports (the From: and To: ports inclusively) are the ports you need to open on your router. You can obviously change these ports if so wish, but make sure they match your router settings. Make sure you also uncheck the Use Random Ports option if you're going to be opening a specific port range on your router.

Starting and stopping the web daemon:

If at any time you want to stop the web daemon then you can do so by issuing the following command:

sudo /etc/init.d/deluge-daemon stop

To start it again use start instead of stop in the above command. To restart it use restart.

 

NOTE: The above instructions are a summary of the excellent guide which can be found here:

Bookmark and Share