Monday, August 04, 2014

HOWTO Configure a Headless Transmission Torrent Server for Mageia5

This will describe how to install and configure the Transmission torrent application on Mageia5 in a headless configuration, how to make it automatically download torrents by placing a .torrent file in a particular directory and admin the client remotely using both a cli (command line interface) and a GUI (graphical user interface) application.

Transmission has both a Homepage,  a Wiki and a Forum, so there's no lack of help and support. But as for installing it as a headless server on Mageia, all we found were HOWTOs for Debian/Ubuntu systems.


We're assuming that you have Mageia5 installed and have configured your user to use the sudo command.


INSTALL
Begin by installing the transmission daemon and the command-line client.

$ sudo urpmi transmission-daemon transmission-cli

This installs  transmission-daemon, transmission-cli and transmission-common (which is mostly the documentation). All the binaries will be found in /usr/bin. The transmission package also installs a Java-based web client at /usr/share/transmission/web/index.html.

CREATE A USER
For transmission-daemon, all settings are kept in $HOME/.config/transmission-daemon. We want to create a user named "transmission". Other distros make the "home" directory something like /usr/share/transmission or /var/lib/transmission; it can really be anything you want. For us, creating /home/transmission has a special benefit.

$ sudo adduser transmission
$ sudo passwd transmission


Having a password allows us to use scp to remotely send a .torrent file to /home/transmission/ on our remote server and the torrent will automatically start when we have properly configured the transmission-daemon to do so.

OBTAIN AN INIT.D SCRIPT
There is an Debian/ubuntu-specific init.d script available from the Transmission site, but it won't work for RedHat-derived distros like Mageia.

You can download an init.d script useful for RHEL and Fedora (and Mageia) written by Jason Friedlan. It's located at his website (his site has since disappeared, so the link is to the WaybckMachine). You'll need to copy and paste it into a text editor.

We'll need to make some changes for Mageia:

- TRANSMISSION_HOME=/var/lib/transmission
+ TRANSMISSION_HOME=/home/transmission

- DAEMON=$(which $NAME)
+ DAEMON=/usr/sbin/transmission-daemon

Save the script as transmission-daemon, change the ownership to root and make it executable, then move it it /etc/init.d.

$ sudo chown root:root transmission-daemon
$ sudo chmod +x transmission-daemon
$ sudo mv transmission-daemon /etc/init.d/


To verify that our script is valid for init.d invoke:

$ sudo chkconfig --add transmission-daemon

Now set the runlevels for transmission-daemon with:

$ sudo chkconfig --level 345 transmission-daemon on

and verify it with:

$ sudo chkconfig --list transmission-daemon

CREATE THE BASIC FILES
Now that our service is configured, let's start and stop the daemon to make certain it works.

$ sudo service transmission-daemon start
$ sudo service transmission-daemon stop


Then invoke:

$ sudo ls -al /home/transmission

This will reveal that the .config directory has been created and we will find that /home/transmission/.config/transmission/settings.json has also been created.

NOTE: With the current version of Transmission, you can only create the settings.json file by running transmission-gtk and a regular user. There does not appear to be a workaround for cli-only systems, so a local copy of the file I use is found here. You'll need to use your own PASSWORD and USERNAME.

CONFIGURE TRANSMISSION
The editable text file settings.json contains the default configuration for our daemon. It can be edited with a text editor and an explanation of the various options can be found at the Transmission Wiki.

NOTE: The current version of transmission-remote seems to have removed some functionality. I suggest you download the settings.json file I reference above and use it. You will need to edit it with the settings below and setting the username:password from the command line still works.

Some suggested changes are (the trailing commas are important!):

Add a blocklist:
- "blocklist-url": "http://www.example.com/blocklist",
+ "blocklist-url": "http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz",


Allow all users on the network to access the web interface:
- "rpc-whitelist": "127.0.0.1",
- "rpc-whitelist-enabled": true,

+ "rpc-whitelist": "*.*.*.*",
+ "rpc-whitelist-enabled": false,




Save the file and restart the service.

Setting a username and password to stop all users but us is important, but this must be done with the transmission-remote command because the password is hashed for security and not stored as plain-text.
$ su - transmission
$ transmission-remote --auth username:password


You can use the application transmission-remote to change any of the settings; look at the man page for details or at the Wiki page.

You'll need to set the home directory to auto-download any torrents. First, we'll need to enable it, then set the directory. As shown here, we'll do it on one line each:
$ su - transmission -c transmission-remote --watch-dir-enabled true
$ su - transmission -c transmission-remote --watch-dir /home/transmission


And, we'll have it keep downloaded torrents in /home/transmission/Downloads.
$ su - transmission  -c transmission-remote download-dir /home/transmission/Downloads

If you don't change a setting, transmission will use the default setting. You can see the default setting by examining the settings.json file or looking at the Wiki page referenced just above.

If you are GUI-centric and command-line-phobic, install the GTK or QT clients and as the user "transmission" use the transmission client GUI to change the settings. That's pretty easy.

NOW START TRANSMISSION
 $sudo service transmission-daemon start

  And you are ready to use it.

START TORRENTS AUTOMATICALLY

Instead of clicking on a torrent link, save the linked .torrent file instead and move it to the torrent user.

$sudo mv *.torrent /home/torrent/

NOTE: I scp the torrent file to my home directory on the remote machine that actually runs torrent-daemon and then use a crontab entry that runs every 15 minutes and moves the torrent file to /home/torrent, where it is started automatically. Of course, using the authorized keys function for ssh is necessary to fully automate this procedure, but it works quite well.

Now the download starts automatically! You can even do this from a remote computer, so if your server is at home and you are at work, just copy the .torrent file over the Internet and the download will be done by the time you get home.

To admin your Transmission server, there's the provided Java web client, or a stand-alone application called

FEEDBACK
As always, I'd appreciate any feedback, especially if I made any errors in this.

No comments: