Downloading Torrents over the Web with cloud-torrent

cloud-torrent

BitTorrent is a peer to peer protocol for sharing files. There are many local clients that allow you to download files via torrents. However, there are times where you may need to download them over the web because you can’t use a local torrent client.

cloud-torrent is a web based torrent-client. It allows you to search torrent trackers, add torrent files and magnet links, and download them on your computer.

In this article we will look at installing cloud-torrent on a server running Linux. You can even run it on your own computer if it is publicly accessible with an IP address.

A word of caution though: if you’re planning to run torrent applications on your server, you may want to confirm whether your provider allows this.

Download and run cloud-torrent

Download the correct version of cloud-torrent from the releases page. Binaries are available for Intel 32- and 64-bit variants, as well as for ARM.

You should refer to the compilation instructions if you’re on an architecture for which no existing binary is available.

Having downloaded the archive, you have to unpack it, rename the binary and make it executable. To do that, run the following commands:

gzip -d cloud-torrent_linux*.gz
mv cloud-torrent_linux* cloud-torrent
chmod +x cloud-torrent

Then, run the binary:

./cloud-torrent

Now, visit http://your_server_name:3000/ with a browser. If you can see the web interface, great! However, if it’s not working for you, check that:

  • You’re not blocking traffic on port 3000 – you need to change your firewall configuration in that case.
  • You’re not running an existing service on port 3000. If this is the case, cloud-torrent will exit with an error listen tcp 0.0.0.0:3000: bind: address already in use. You can run cloud-torrent on a different port, like so:
    ./cloud-torrent -p <custom_port_number>

    The port number must be anywhere between 1025 and 65535.

To stop cloud-torrent, simply press Ctrl+C.

Auto-starting cloud-torrent

While cloud-torrent is already working nicely for you, you probably want it to be started automatically on system startup like a regular system service. You can do this quite easily.

First, you need to set up a separate user for cloud-torrent to run. While it is not strictly necessary to do so, it is generally recommended for better security.

sudo useradd -rm cloud-torrent

Next, you have to move the cloud-torrent binary to the home directory of the new user.

sudo mv cloud-torrent /home/cloud-torrent/cloud-torrent

Now, you need to configure the system to start it automatically. Depending upon the distribution’s init system, you need to follow the instructions for either systemd or sysvinit.

systemd-based systems

With a systemd-based system, this process is quite easy. Create /etc/systemd/system/cloud-torrent.service with the following contents:

[Unit]
Description=torrent web server

[Service]
Type=simple
User=cloud-torrent
WorkingDirectory=/home/cloud-torrent
ExecStart=/home/cloud-torrent/cloud-torrent

[Install]
WantedBy=multi-user.target

If you need to use a different port, you need to put in ExecStart=/home/cloud-torrent/cloud-torrent -p <port_number> instead.

Then, you need to tell systemd that you’ve created a new service file. In addition, you need to enable the service. In order to do this, run the following commands:

sudo systemctl daemon-reload
sudo systemctl enable cloud-torrent.service
sudo systemctl start cloud-torrent.service

sysvinit-based systems

For sysvinit based systems, you need to add a shell script with the following code in /etc/init.d/cloud-torrent:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          cloud-torrent
# Required-Start:    $local_fs $network $named $time $syslog
# Required-Stop:     $local_fs $network $named $time $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the cloud-torrent web server
# Description:       starts cloud-torrent using start-stop-daemon
### END INIT INFO

DESC="torrent web server"
NAME=cloud-torrent
DAEMON=/home/cloud-torrent/cloud-torrent

DAEMONUSER=cloud-torrent
PIDFILE=/var/run/$NAME.pid

STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"

test -x $DAEMON || exit 0

start() {
    start-stop-daemon --start --quiet --make-pidfile --pidfile "$PIDFILE" \
        -d "/home/$DAEMONUSER" --background --chuid "$DAEMONUSER" --oknodo --exec "$DAEMON"
}

stop() {
    start-stop-daemon --stop --quiet --pidfile "$PIDFILE" --retry="$STOP_SCHEDULE" \
        --name "$NAME" --oknodo
    rm -f "$PIDFILE"
}

status() {
    if [ -f "$PIDFILE" ]; then
        if kill -0 $(cat "$PIDFILE"); then
            echo "$NAME is running"
        else
            echo "$NAME process is dead, but pidfile exists"
        fi
    else
        echo "$NAME is not running"
    fi
}

case "$1" in
    start)
        echo "Starting $NAME $DESC..."
        start
    ;;
    stop)
        echo "Stopping $NAME $DESC..."
        stop
    ;;
    restart)
        echo "Restarting $NAME $DESC..."
        stop
        start
    ;;
    status)
        status
    ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 2
    ;;
esac

exit 0

If you need to run cloud-torrent on a different port, simply modify start() in the above shell script like so:

start-stop-daemon --start --quiet --make-pidfile --pidfile "$PIDFILE" \
 -d "/home/$DAEMONUSER" --background --chuid "$DAEMONUSER" --oknodo --exec "$DAEMON" -- -p <port_number>

Then, you need to make the script executable, and register it for automatic startup:

sudo chmod +x /etc/init.d/cloud-torrent
sudo update-rc.d cloud-torrent defaults

cloud-torrent should now be automatically started when the server boots up.

 

You will now need to configure the download directory. To do this, visit the web interface, click on the options icon (three bars), and set the download directory to a path such as /home/cloud-torrent/downloads. (See the screenshot below.)

Password protection

The current setup has a problem — anyone who visits it can use it. You can prevent this by setting a password by specifying an environment variable named AUTH.

If you’re using systemd, edit /etc/systemd/system/cloud-torrent.service and put this line in the [Service] section:

Environment="AUTH=username:password"

For sysvinit based systems, simply export the AUTH variable like you would do in a shell script:

# [previous part of shell script]
DAEMONUSER=cloud-torrent
PIDFILE=/var/run/$NAME.pid
export AUTH="username:password"
# [rest of the shell script]

Replace username and password with your own values.

Configuring HTTPS

To protect your privacy, you may want to configure HTTPS on cloud-torrent.

For systemd users this will be easy. In /etc/systemd/system/cloud-torrent.service, modify the line containing ExecStart= like so:

ExecStart=/home/cloud-torrent/cloud-torrent -k /path/to/key.pem -r /path/to/cert.pem

sysvinit users would need to modify the start-stop-daemon command in start() like so:

start-stop-daemon --start --quiet --make-pidfile --pidfile "$PIDFILE" \
 -d "/home/$DAEMONUSER" --background --chuid "$DAEMONUSER" --oknodo --exec "$DAEMON" -- -k /path/to/key.pem -r /path/to/cert.pem

Obviously, you should replace /path/to/key.pem and /path/to/cert.pem with the correct paths.

At this point, cloud-torrent should be fully set up for your use. For more configurable options, be sure to check out the --help switch.

If you liked this post, please share it 🙂

You may also like...