An optimized Download Station

This post is about transforming the Raspberry Pi into a powerful download station, while trying to to reduce noise and power consumption.

The download package

The Raspberry Pi Mediacenter post showed how to turn that little guy into an awesome mediacenter setup. An useful addition is the installation of xbian-package-download:

For everyone new to this, this is an all-in one fully automated newsserver and torrent downloader. After configuring all you will have to do is tell it what movies, tvshows and music you like and it will be downloaded once available.

The xbian-package-download is a meta-package which includes:

hdparm, the dangerous

In the above mentioned setup we probably attach an USB disk (via a powered hub) to the Pi as a destination for downloads. However, this potentially prevents the disk from spinning down and going into the silent standby mode.

The hdparm commandline utility shows and configures hardware parameters of our disk. We can query power management information and put it in sleep mode. Before using it, read the hdparm man page with warnings like VERY DANGEROUS, DO NOT USE!! strewn at large.

The following commands require sudo and the disk name, or even better: the UUID:

# list UUID of all disks
sudo blkid

# or ask for a specific UUID
sudo blkid /dev/sda1

# you can also see the association here
ls -la /dev/disk/by-uuid/

# let's remember this
# /dev/sda1: LABEL="lacie" UUID="d5cc9cdd-6425-480c-bafb-9653cec72e64" TYPE="ext4" 

Now, let's get some hardware infos about our disk:

# the params we use
sudo hdparm -h
 -I   Detailed/current information directly from drive
 -C   Check drive power mode status
 -S   Set standby (spindown) timeout
 -y   Put drive in standby mode

# general information
sudo hdparm -I $disk

Configuring standby mode

We can also view and set the power mode:

# power mode status
sudo hdparm -C $disk

 drive state is:  active/idle

# put drive into standby
sudo hdparm -y $disk

 issuing standby command

# check mode
sudo hdparm -C $disk

 drive state is:  standby

Finally, we use hdparm -S <arg> to set a more aggressive standby timeout. We read the hdparm man page to get some infos about the usage and smile while reading this funky explanation:

The encoding of the timeout value is somewhat peculiar. A value of zero means "timeouts are disabled": the device will not automatically enter standby mode. Values from 1 to 240 specify multiples of 5 seconds, yielding timeouts from 5 seconds to 20 minutes. Values from 241 to 251 specify from 1 to 11 units of 30 minutes, yielding timeouts from 30 minutes to 5.5 hours. A value of 252 signifies a timeout of 21 minutes. A value of 253 sets a vendor-defined timeout period between 8 and 12 hours, and the value 254 is reserved. 255 is interpreted as 21 minutes plus 15 seconds. Note that some older drives may have very different interpretations of these values.

To permanently set harddisk options like the standby timeout, we could add an entry in /etc/hdparm.conf. However at the time of this writing, some Debian-based distros seem to lose these settings after a reboot, so we decide to add the following to /etc/rc.local:

# sleep after 10min for lacie disk
sleep 5
hdparm -S 120 /dev/disk/by-uuid/$uuid

Taming Sickbeard

There are two settings we need to consider:

  1. Search Frequency in http://pi:9094/config/search/
  2. Scan and Process in http://pi:9094/config/postProcessing/

Set the first one to 120 minutes to look for new episodes. If Scan and Process is activated, Sickbeard searches the download destination every 10 minutes for something to post-process (move to episodes location, update XBMC library). On one side, this is very convenient. However, there's currently no way to increase the timespan between the post-process scans. This means that every 10 minutes, our disk spins up from the silent standby sleep. So we disable it.

Triggering Post-Processing

Looking for a way to manually trigger the post-processing of downloaded episodes, the first stop is the official Sickbeard API. It has a lot of features, but unfortunately, post-processing currently isn't one of them.

To fill the gap in the meantime, I wrote the following simple Ruby script (Github Gist). It uses Mechanize to effectively visit our Sickbeard webapp and toggle the manual post-processing:

require "rubygems"
require "mechanize"
site = 'http://pi:9094/home/postprocess/'
user = 'xbian'
pass = 'raspberry'
downloads = '/home/xbian/downloads/tv'
agent =
agent.add_auth(site, user, pass)
agent.get(site) do |page|
  processed = page.form_with(:name => 'processForm') do |processing|
    processing.dir = downloads

Now we can run this script to trigger post-processing via cron whenever we like.