How to Set Up Aria2 Download Manager with Web UI on Raspberry Pi

A simple guide to set up a download manager that always running on background

Today I need to download a lot of large files. It is estimated to be finished for a couple of hours. I can do that directly with my MacBook Air, but that means I need to keep it on for a long time. That is unacceptable since I need to bring my MacBook away.

Luckily, I have a Raspberry Pi that always running 24/7 at home. I can just ssh it and run wget in background, but it’s not efficient enough. I mean, I’m friendly with command line, but I want something fast. What I want is a download manager that I can access with web browser, just like transmission. But, transmission can only accept torrent files. I need it to accept more protocols, like HTTP and FTP.

So then I found aria2.

aria2 is a lightweight multi-protocol and multi-source command-line download manager. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink! But it doesn’t have official web interface.

When I read more on their website, they recommend webui-aria2 as a frontend. This web UI can manipulate aria2 via built-in JSON-RPC interface!

All right, enough with the story, let’s go straight to the solution.

Solution

First, you need to login to your Raspberry pi via ssh. Then change your working directory to home.

cd /home/pi/

Install some dependencies. We need to use git, tmux, python3, and aria2.

sudo apt update
sudo apt install git tmux python3 aria2

Download webui-aria2 to the current working directory. We can simply clone it with git.

git clone https://github.com/ziahamza/webui-aria2.git

Start aria2 as tmux session. This will run aria2 in background and listen to RPC protocol. By default the RPC will listen 6800 port. Let’s leave it to that.

tmux new -d \
    -c /home/pi/ \
    -s aria2rpc \
    'aria2c --enable-rpc --rpc-listen-all' \;

Start webui-aria2 as tmux session, too. We simply use python3 built-in HTTP server. This also will run the http server in background. We use port 8600 for HTTP server.

tmux new -d \
    -c /home/pi/webui-aria2/docs/ \
    -s aria2webui \
    'python3 -m http.server 8600' \;

That’s it, now open your Raspberry pi IP address with port 8600 from your browser. You can find out your Raspberry Pi ip address with ifconfig.

Run at startup

The solution above is enough assuming you never turn off your Raspberry pi. But it’s mostly not the case. You’re going to need to restart it once in a while. Or maybe there will be a sudden power failure. You never know.

To run the services in background, we need to create a shell script. Let’s call the script run-aria2.sh. You can edit it with nano, vim, or any text editor.

nano /home/pi/run-aria2.sh

The content is similar with previous section. Here is the command I write on it.

#!/bin/sh

# Start aria2 RPC server
tmux new -d -c /home/pi/ -s aria2rpc 'aria2c --enable-rpc --rpc-listen-all' \;

# Start webui-aria2 HTTP server
tmux new -d -c /home/pi/webui-aria2/docs/ -s aria2webui 'python3 -m http.server 8600' \;

Next thing is to make it executable with chmod.

chmod +x run-aria2.sh

In Raspbian OS, you can start a script immediately after finished booting by writing it in /etc/rc.local. So we need to execute previous shell script there. Open the file with your favorite text editor.

sudo nano /etc/rc.local

Make sure put the following line before exit 0.

su pi -c '/home/pi/run-aria2.sh &'

If you’re worry that you write it wrong, here is my rc.local content looks like.

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

su pi -c '/home/pi/run-aria2.sh &'

exit 0

Now restart your Raspberry pi to check if it works.

sudo reboot

After your Raspberry pi done restarting, it should be running in background. That’s it, enjoy your download manager!

Thanks for reading, I’ll write more articles like this in the future.