These days streaming services are so well established that one rarely needs to fallback to file sharing. But Big Content usually decides which content is good on a whim. And if you want to watch an old movie or a special edition recording not available for streaming, well, tough luck.

When searching for BitTorrent clients I discovered that a few of them support a daemon (headless) mode, I decided on transmission because of their variety of options:

  • Daemon mode
  • Can be controlled via CLI or WUI
  • Supports DHT, µTP, encryption, magnet links, etc.
  • Watch directory for new .torrent files and start downloading when a new file is added
  • Separate directory for incomplete downloads
Ironic image of file sharing killing music.
The same tale of olde: give us your money or watch what you love die.

The first step is to install transmission. Depending on your distro, you may be able to install the daemon separately, e.g., apt-get install transmission-daemon, dnf install transmission-daemon, etc.

In my case I used the transmission slackbuild setting GTK=no as an environment variable to skip building the GTK GUI.

Add user

$ useradd --system --shell /bin/false -b /srv/torrents --user-group transmission

Setup Transmission directories

$ mkdir -p /srv/torrents/{config,download,incomplete}
$ chmod 0775 /srv/torrents /srv/torrents/*
$ chown -R transmission: /srv/torrents

Setup service script

Create the service script (/etc/rc.d/rc.transmission) and give it execution permissions.

#!/bin/sh

USER=transmission
TRANSMISSION=/usr/bin/transmission-daemon
PIDFILE=/var/run/transmission/transmission.pid
ARGS="--config-dir /srv/torrents/config --pid-file $PIDFILE"

test -f $TRANSMISSION || exit 0

transmission_start() {
    echo -n "Starting transmission: $TRANSMISSION $ARGS... "

    mkdir -p "$(dirname $PIDFILE)"
    chown $USER:$USER "$(dirname $PIDFILE)"

    su -c "$TRANSMISSION $ARGS" --shell /bin/bash $USER

    if [ $? -eq 0 ]; then
        echo "done!"
    else
        echo 1>&2 "Could not start $TRANSMISSION as $USER"
    fi
}

transmission_stop() {
    echo -n "Stopping transmission: "
    killall $(basename $TRANSMISSION)
    echo $?
}

transmission_restart() {
    transmission_stop
    transmission_start
}

case "$1" in
'start')
    transmission_start
    ;;
'stop')
    transmission_stop
    ;;
'restart')
    transmission_restart
    ;;
*)
    echo "Usage: $0 start|stop|restart"
    exit 2
    ;;
esac
exit 0

Start on boot

Edit /etc/rc.d/rc.local to start transmission if enabled:

if [ -x /etc/rc.d/rc.transmission ]; then
    /etc/rc.d/rc.transmission start
fi

"HOME TAPING IS KILLING MUSIC" (modified) by Leo Reynolds is licensed under CC BY-NC-SA 2.0 .