Setting up Deluge on a headless Ubuntu seedbox with a Windows client
Recently I had to rebuild aenea, my dedicated seedbox, due to a botched upgrade to Ubuntu Hardy. The install went fine, being as it is Ubuntu, but when I installed the latest version of Azureus, my preferred BitTorrent client for the last five years or so, I ran into trouble. It would download fine, 1.5MB/s, for between one to thirty minutes, then all download and upload traffic would cease. No meaningful errors on the console, and the NAT test showed green consistently, but no traffic.
I poked around on the Azureus support forums and found this guy having the same problem. No one could offer any meaningful suggestions beyond the usual “is it plugged in?” and “is it turned on?” type stuff, so as a diagnostic measure I decided to run a different BitTorrent client. I rummaged around and quickly found Deluge, which is a cross-platform client written in Python.
I did a quick aptitude install deluge, which installed (what I later learned is an ancient) version 0.5.something. I fired it up, configured it for my ports and download location, and pointed it to the same torrents Azureus was choking on. Not surprisingly, Deluge downloaded them fine, with no eventual slowdown. Clearly, not a NAT problem.
Since I already had a working Deluge install, I started to consider dumping Azureus entirely. I’ve hated Azureus since it became Vuze and started bolting all sorts of crap on top of what should be a pretty simple piece of software, but I never had any motivation to switch since Azureus just worked. Now that it didn’t, and I had another client that did, I figured it would be a great opportunity to see if my needs could be met elsewhere.
Once I realized the package I was running was an ancient version, I went to the Deluge site to download the latest (1.0.5 at the time of this writing) in the form of a .deb package. Install was painless, and the new version was much nicer looking. Then, I set about to duplicate my Azureus config.
Download locations
I keep in-progress downloads in /usr/local/p2p/downloading, and completed downloads go in /usr/local/p2p/downloaded. This makes it easier to keep them straight, and avoid accidentally copying over a partially-downloaded torrent.
Blocklist
I used to use the bluetack level1 blocklist, but it’s MIA again so I downloaded a copy of the PeerGuardian P2P blocklist intead. I had to enable Deluge’s BLocklist plugin to enable blocklist functionality, then pointed it at the text file blocklist and it loaded it into memory.
Bandwidth
I let torrents use unlimited download bandwidth, and 400 KiB/s upload. My OpenBSD packet shaping rules take care of preventing bandwidth starvation.
Headless
I don’t initiate downloads from aenea, I do it from my laptop, so it won’t do to have to VNC into aenea and launch the UI. Fortunately, Deluge supports this. Unfortunately, the docs consist of a hard-to-follow thread on the forums. To get the Deluge daemon and the WebUI to run on system startup, I created an init.d script based on a forum thread.
The final script came from this post. The /etc/default/deluge-daemon file looks like:
# Configuration for /etc/init.d/deluge-daemon # The init.d script will only run if this variable non-empty. DELUGED_USER="anelson" # Should we run at startup? RUN_AT_STARTUP="YES"
and the /etc/init.d/deluge-daemon looks like:
#!/bin/sh
### BEGIN INIT INFO
# Provides: deluge-daemon
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Daemonized version of deluge and webui.
# Description: Starts the deluge daemon with the user specified in
# /etc/default/deluge-daemon.
### END INIT INFO
# Author: Adolfo R. Brandes
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Deluge Daemon"
NAME1="deluged"
NAME2="deluge"
DAEMON1=/usr/bin/deluged
DAEMON1_ARGS="-d"
DAEMON2=/usr/bin/deluge
DAEMON2_ARGS="-u web"
PIDFILE1=/var/run/$NAME1.pid
PIDFILE2=/var/run/$NAME2.pid
PKGNAME=deluge-daemon
SCRIPTNAME=/etc/init.d/$PKGNAME
# Exit if the package is not installed
[ -x "$DAEMON1" -a -x "$DAEMON2" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME
# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
if [ -z "$RUN_AT_STARTUP" -o "$RUN_AT_STARTUP" != "YES" ]
then
log_warning_msg "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it."
exit 0
fi
if [ -z "$DELUGED_USER" ]
then
log_warning_msg "Not starting $PKGNAME, DELUGED_USER not set in /etc/default/$PKGNAME."
exit 0
fi
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --exec $DAEMON1 \
--chuid $DELUGED_USER --user $DELUGED_USER --test > /dev/null
RETVAL1="$?"
start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --exec $DAEMON2 \
--chuid $DELUGED_USER --user $DELUGED_USER --test > /dev/null
RETVAL2="$?"
[ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 1
start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --make-pidfile --exec $DAEMON1 \
--chuid $DELUGED_USER --user $DELUGED_USER -- $DAEMON1_ARGS
RETVAL1="$?"
sleep 2
start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --make-pidfile --exec $DAEMON2 \
--chuid $DELUGED_USER --user $DELUGED_USER -- $DAEMON2_ARGS
RETVAL2="$?"
[ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE2
RETVAL2="$?"
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE1
RETVAL1="$?"
[ "$RETVAL1" = "2" -o "$RETVAL2" = "2" ] && return 2
rm -f $PIDFILE1 $PIDFILE2
[ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] && return 0 || return 1
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME1"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME1"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME1"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
Obviously you must make /etc/init.d/deluge-daemon executable by root, then make it load on startup:
sudo update-rc.d deluge-daemon defaults
You can either reboot, or do
sudo /etc/init.d/deluge-daemon start
to start things up. Now the daemon should be listening on port 58846, and the Web UI on port 8112 (by default protected by password deluge).
Client
In a pinch I can use the WebUI at http://aenea:8112/, but as rich as the UI is it’s really a pain in the ass to use with private trackers, since I have to download the torrent file from my logged-in browser session, then upload that torrent file to the web UI. Fortunately, Deluge offers another option.
The Deluge GUI is actually just a client, that talks to a daemon. By default it talks to the local daemon, but it can be made to talk to one elsewhere on the network as well. Unfortunately, the docs suck to the point of non-existence, so you have to rummage around the forums or read this post to find out how to do it.
First, I downloaded the 64-bit windows installer, and ran it on my Vista laptop. I then started up Deluge, and (here’s the non-obvious bit) went into Preferences, Interface, unchecked ‘Enable’ under ‘Classic Mode’, and restarted Deluge. When it came back up, it came up with the connection manager dialog. I removed the connection to the localhost daemon, added aenea, and configured it to always connect to this host. That way, whenever I launch Deluge on my laptop, it comes up connected to aenea.
You might think that’s it, but there’s a bit more yet to do.
File associations
My normal torrent workflow is to use Firefox on my Vista laptop to find torrents I want, then download them and let Firefox launch my torrent client automatically. With Deluge this is a bit tricky, because it is launched with a batch file, deluge.cmd, in the Program Files\Deluge folder. This batch file sets up some Python environment variables before invoking the scripts\deluge.exe file. However, if you tell Firefox to launch deluge.cmd, you’ll find that you get a rather obtuse error message popup:
Failed to run the program, Error:267, The directory name is invalid.
This is due to Firefox running as a 32-bit process, and thus thinking the Program Files directory is Program Files (x86). The solution is to create another batch file, which I call deluge32.cmd, with the following contents:
@echo off rem Wrapper around deluge.cmd which will ensure the 64-bit command processor is used even if this batch file is invoked with the 32-bit rem command processor rem rem Use with 32-bit firefox on 64-bit windows with 64-bit deluge. Any other use is completely untested set DELUGEDIR=C:\Program Files\Deluge %windir%\sysnative\cmd.exe /c "%DELUGEDIR%\deluge.cmd" %*
Point Firefox to this batch file, and it works fine. I posted a bit more about this in the Deluge forums here
VNC
This isn’t really related to torrents at all, but I always configure my seedbox with resumable VNC sessions per this forum post. There’s a built-in desktop sharing thing in Gnome but you have to be logged in already and it shares the console session over VNC; this way VNC sees a separate session from the console, must like RDP on Windows.
Note that this tutorial is a bit old. I can’t get it working with Ubuntu 8.04, and apparently neither can anyone else. There’s a bug with the GNOME Settings Daemon crashing, and performance is shoot-me-in-the-head-I-cant-take-it-anymore slow. Dammit, sometimes I really hate computers.
March 19th, 2009 - 18:46
Thanks for wrapping all of the important information into one place. nice!!!
March 30th, 2009 - 03:27
Thank you so much for this blog post. I considered about three other setups, failing halfway through for various reasons, until I found this which laid out exactly what I wanted to do. Saved me a lot of time. Having this seedbox makes me so happy!
And FYI, I’m using Ubuntu 8.10 and it’s working just fine for me.
April 2nd, 2009 - 01:31
thanks for the guide. I ran in to one little problem, I had to edit ~/.config/deluge/auth to include my login details, so it looked like[without the quotes]:
localclient:”yourownhash”
“user”:”password”
April 2nd, 2009 - 10:28
Thanks for reminding me. The old Deluge bits I used work fine out of the box, but after I upgraded I did have to fiddle with the auth file in the way you described.
May 21st, 2009 - 01:59
Can anyone explain how to get this running under a user other then Root – never like to do so for security reasons.
Thanks
May 21st, 2009 - 10:35
I run the daemon as a non-root user with no problem. I don’t recall doing anything special to get that working.
June 2nd, 2009 - 15:05
thank you very much…
im using deluge on debian headless mashine..
August 16th, 2009 - 06:57
There is a typo in the section titled “Headless”. This line has an excess “s”:
/etc/defaults/deluge-daemon
should read:
/etc/default/deluge-daemon
it threw me for a moment… thanks for the great howto…
August 16th, 2009 - 10:21
Good catch!
December 23rd, 2009 - 14:04
Wow, great guide… I have deluge setup with the AJAX gui and it’s so much better than torrentflux, plus I can connect to the daemon from the client on my computer without even using the web interface
March 13th, 2010 - 13:32
Great guide! Combined with this one to get v1.2 on Ubuntu 9.10 worked like a charm. Thanks again.
March 13th, 2010 - 13:32
Missed link…
http://havetheknowhow.com/Install-the-software/Install-Deluge-Headless-RC.html