Home
This step depends on the webserver created in the previous step. It will serve as tracker. Torrents will be read from /srv/http/torrents and contents are written to /srv/torrent.
There are various GUI-less torrent clients available. We use transmission. Install the transmission-cl package to get the headless version. A systemd daemon file is already included, which will run the daemon as user transmission.
Start the service one time to let it create its default configuration under /var/lib/transmission/.config/transmission-daemon/.
Make a symbolic link pointing to the folder on the storage: ln -s /srv/torrent /srv/storage/torrent. Accessing this symbolic link will block until either the device timeout is reached (resulting in error) or the device is mounted.
I changed the following configuration settings:
download-dir to /srv/torrent
lpd-enabled to true
peer-port to 8900
port-forwarding-enabled to false
rpc-enabled to false (may be set to true, but rpc origin restricted to localhost)
watch-dir to /srv/http/torrents
watch-dir-enabled to true
Transmission requests rather high send and receive buffer sizes, which need to be enabled in the kernel run time configuration. Create the file /etc/sysctl.d/transmission.conf and write the following lines into it:
net.core.wmem_max = 1048576 net.core.rmem_max = 4194304
Additional configuration information can be seen on github or arch wiki.
When using the default bind of 0.0.0.0, transmission will register itself with the localhost-ip in the tracker. This causes it to not be reachable by clients recveiving the IP from the tracker. A workaround is to enter the ip of the ethernet adapter by hand. Of course this has to be repeated every time the network is changed.
So we write a script that queries for the current IP and sets it in the configuration file:
#!/bin/bash EXT_IP=`ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1` sed -i "9s/[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*/${EXT_IP}/" /var/lib/transmission/.config/transmission-daemon/settings.json
Save this script as set-ip.sh in /var/lib/transmission, make it executable and owned by transmission.
After that create an override for the transmission unit file the set the dependencies on the mount point and execute the ip script prior to starting transmission. Create the override with systemctl edit transmission:
[Unit] Requires=srv-storage.mount After=srv-storage.mount [Service] ExecStartPre=/usr/bin/bash /var/lib/transmission/set-ip.sh
The next step is to edit the mount point service, to start transmission after the mount is executed. Create an override with systemctl edit srv-storage.mount
[Unit] Wants=transmission.service
This will automatically launch transmission, as soon as /srv/storage is mounted. Which basically means transmission will not be started until the external device is plugged in and started.
Bitstorm is a simple torrent tracker written in php. Published on github. I zipped it and you can download it here. Copy announce.php into the html root. Some configuration variables are worth changing, especially location of the peers file. /dev/shm is fine, as it is world writeable and in RAM. If persistency is required it can also be written into the html root.
Set redirection URL to ./index.html. Also disable short announces.
All those rules will go into the file /etc/nft_rules/in_transmission.conf. The following ports need to be accessible:
8900 (configured port in transmission), TCP and UDP
6771 UDP for Local Peer Discovery
Port 9091 is only used on the localhost for the RPC interface.
tcp dport 8900 accept
udp dport 8900 accept
udp dport 6771 accept