27 March 2016

Transmission in FreeBSD jail

So as mentioned in the blogpost on how to install sabnzbd in a FreeBSD jail here is a blog post which will show how to install the transmission torrent client in a FreeBSD jail.

Goal

So during the selection of the torrent client which I would be installing in a jail, I decided the following requirements should be met:
  • A webinterface to operate the application
  • The possibility to place .torrent files in a shared folder so that the client will import these automatically.
Transmission has all that!

Jail information

Here you can see the jail information I used to create the jail via the FreeNAS web interface
propertyvalue
Jailnametorrent-PRD
IPv4 address192.168.1.104
typestandard
vanillaFALSE (unchecked)

Installation

Transmission will be installed via ports. For this reason it is necessary to get the portstree in the jail. Execute the following command to do so: portsnap fetch extract.
After this is done, switch to the transmission folder in de portstree and initiate the compilation of Transmission:cd /usr/ports/net-p2p/transmission-daemon
make install clean

Configuration

After the software is compiled, the following information was shown on the screen:
"Transmission group and user created; uid = 921, gid = 921"
binary = /usr/local/bin/transmission-remote
binary = /usr/local/bin/transmission-daemon
startupscript = /usr/local/etc/rc.d/transmission
Reading the startupscript provides us more information about what paths are used for configuration. Let's just go with the defaults to get a basic setup running. Later on, watchdir should be configured, download dir should also be modified.
Defaults:
Config dir => /usr/local/etc/transmission/home
Default port the webinterface will be available on : 9091
Download dir => /usr/local/etc/transmission/home/Downloads
Add the following line to /etc/rc.conf
transmission_enable="YES"
Now start the transmission daemon by executing service transmission start. This will also create the initial configuration files in the configuration directory ( /usr/local/etc/transmission/home ). NOTE: stop the transmission daemon by executing service transmission stop prior to editing the config file, as the transmission daemon will always overwrite the config file which was used to start the daemon. Once the /usr/local/etc/transmission/home/settings.json file is modified and saved, the transmission daemon can be started again by executing service transmission start
So the initial configuration files are created, as the above note mentions the transmission service should be stopped prior to editing the configuration file, do so:
service transmission stop
cd /usr/local/etc/transmission/home
ee settings.json
Modify the following line to allow access from any computer on your LAN to access the transmission WEB UI:
"rpc-whitelist":"127.0.0.1", to
"rpc-whitelist":"127.0.0.1,192.168.1.*",
After transmission is started again (service transmission start), you should already have a working torrent server which would allow you to use the webinterface from any computer on your LAN.

Storage for downloads

If no dedicated dataset is created for the torrents downloads, this should be done first so that it later on can be attached to the jail.

Creating a dataset in FreeNAS

So in order to create a dataset, which will be intended to store the downloaded torrents on, log in to the FreeNAS web interface, move to the storage tab section, select the zpool (Fritketel in my case) and click on the Create ZFS Dataset button.


Dataset permissions

After the dataset is created, modify the permissions so that they look like the following:

Mounting the storage inside the jail

Now this dataset can be mounted inside the jail. In order to do this, navigate to the jails tab, select the newly created jail and click on the Add storage button.
Then, point the source to the newly created dataset 'Download'.


Now, inside the jail a new group called 'media' should be created with groupID 816 and the transmission user should be added to that group. This will allow the local transmission user to actually make use of the mounted dataset inside the jail. In order to create a new group 'media' with groupID 816, and the transmission user as member of the new group, execute the following inside the jail:
pw add group -n media -g 816 -M transmission

Folder structure and permissions

The last part to do is to set up a working folder structure on the dataset. I do this to logically separate all usenet and torrent downloads:
mkdir -p /media/transmission/to\ download mkdir -p /media/transmission/downloaded
Apply the appropriate user and owner on the transmission folder and its subfolders:
chown -R transmission:media /media/transmission
Apply the correct permissions on the transmission folder and its subfolders:
chmod -R 775 /media/transmission

Modifying jail bootscript

Now that transmission is configured succesfully, the dataset is created and mounted inside the jail, and a folder structure is in place it is also necessary to instruct transmission to use the new folder structure as download location. This should be done inside /etc/rc.conf. edit this file (ee /etc/rc.conf) and the following lines: transmission_watch_dir="/media/transmission/to\ download" transmission_download_dir="/media/transmission/downloaded" transmission_chown="NO" #this will prevent the downloaded files to be chown'd to transmission:transmission, but remain as how the /media/transmission/downloaded user and group owners is configured (transmission:media in this case)

Torrents can now be added via the Web UI, or by plaving the torrent file in the transmission/to download folder on the download dataset.

No comments:

Post a Comment