Skip to main content

Raspberry Pi Download Machine Part 2

Well SSH is Boring

I have got my RPi download machine up and running and having success, unfortunately though SSH is annoying and tedious, so I am gonna do something about it. But a disclaimer; this is my first time working with Aria2 in the most part.

RPC 

Remote Procedure Call is fancy way of saying 'make this thing make that thing do a thing'. So I ran the command to load the config file (and added to my init file) in the last post and ..... BOLLOCKS ALL.

So ran the command again, and need to check the processes (like Task Manager).

pi@raspberrypi:~ $ ps aux | grep aria2c
root       524  0.0  0.9  17028  9284 ?        Ss   21:21   0:00 aria2c --conf-path=/home/pi/.aria2/aria2.conf
pi        1008  0.0  0.2   4272  1948 pts/0    S+   21:34   0:00 grep --color=auto aria2c

There it is, that little scumbag. But still no dice. In the conf file I stated that the rpc-port to be 6800 so need to check that port. 

A quick note on ports, every service that runs on your computer and needs a connection to manage, will take a port number. This makes each service unique on the machine and therefore the IP of the host.


Hmmm ... the 6th row show the service on 6800 but for TCP6 (not gonna go into detail but need to be tcp), TO THE LOGS!!!!

pi@raspberrypi:~ $ sudo tail -f /var/log/aria2/aria.log 
2017-08-03 21:21:37.169615 [ERROR] [HttpListenCommand.cc:114] IPv4 RPC: failed to bind TCP port 6800
Exception: [SocketCore.cc:292] errorCode=1 Failed to bind a socket, cause: Name or service not known

Interesting, that's the port I need. So I stopped the service and then ran manually with alternate settings.

pi@raspberrypi:~ $ sudo service aria2 stop
pi@raspberrypi:~ $ sudo aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all

And BINGO!!! (sort of)

I went and used a WebUI to connect to the running Aria and things are looking good. Gonna do a test download. Over to r/opendirectories/ and grabbed an ebook








Reconfiguring

From seeing that my commands were wrong I realised that copying nonsense from the internet is not always the best way forward. Text after aria2c are arguments and are a way to send settings, and we can take the same arguments and put them in the conf file and just run that instead. Now I am gonna be much more fucking sensible and run manually each time changing the arguments until I get in right and then create my conf file.

Attempt 1

--enable-rpc 
--rpc-listen-all=true 
--rpc-allow-origin-all

This gives me a connection and can add downloads, but no authentication at all. There are options for a username and password but in the documentation tells us that this will be depreciated so am gonna use an rpc secret instead.

Attempt 2

--rpc-secret=bumhole

Now we are running using the secret, make sure you pick complicated passwords! Ok next I need set the default directory to the mounted drive with dir, and set the log file and log level.

Attempt 3

--dir=/home/pi/drive_caddy
--log=/var/log/aria2/aria.log
--log-level=notice


On the WebUI it can be seen that the directory is set and logging is working to that file.




Good so far, now some of the defaults are not what I am looking for. Max connections is how many connections are made to a server for downloading a file. By default is 1 but will change to 3. Also I want to attempt a download 10 times if there is an issue, and wait 30 secs between tries.

Attempt 4

--max-connection-per-server=3
--max-tries=10
--retry-wait=30

Ok that is now working, finally I want this thing to just run in the background i.e. as a daemon. 


Final Attempt

--daemon=true

SUCCESS!!!!




All left to do is put those commands (leaving out the -- at the beginning) into /home/pi/.aria2/aria2.conf

enable-rpc 
rpc-listen-all=true 
rpc-allow-origin-all
rpc-secret=bumhole
dir=/home/pi/drive_caddy
log=/var/log/aria2/aria.log
log-level=notice
max-connection-per-server=3
max-tries=10
retry-wait=30
daemon=true

And as a test rebooted the Pi .... and got fuck all. Back to the logs.

2017-08-04 16:25:51.008095 [ERROR] [HttpListenCommand.cc:114] IPv4 RPC: failed to bind TCP port 6800
Exception: [SocketCore.cc:292] errorCode=1 Failed to bind a socket, cause: Name or service not known
2017-08-04 16:25:51.011044 [NOTICE] [HttpListenCommand.cc:111] IPv6 RPC: listening on TCP port 6800

Balls. Same issue I had before of 'Failed to bind socket'. Before getting pissed off I remembered that I have seen this type of issue before,  basically Aria2 needs to use the network interface on the startup script, but it's run before the interface has initialised. Quick hack, put a delay in the startup script, highlight in yellow below.


pi@raspberrypi:~ $ sudo nano /etc/init.d/aria2

#! /bin/sh
# /etc/init.d/aria2
### BEGIN INIT INFO
# Provides:          aria2
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: aria2
### END INIT INFO

CONF_PATH=/home/pi/.aria2/aria2.conf

case "$1" in
    start)
        echo "Starting aria2 with custom configuration"
sleep 50
        aria2c --conf-path=$CONF_PATH
        ;;
    stop)
        echo "Stopping aria2"
        killall aria2c
        ;;
    *)
        echo "Usage: /etc/init.d/aria2 {start|stop}"
        exit 1
        ;;
esac

exit 0

ONE MORE REBOOT AND WE HAVE MOTHERFUCKING SUCCESS!!!!

Connecting and Downloading

Now in a glorious position to send downloads, but how can we achieve this. Well we need a client to connect. For myself I am using Aria2App on Android in the Google Play Store, alternatively if you are on iOS go have a little cry in the corner cos you ain't got shit.

In the App click the + icon and choose the condition for the app to be active. I have chosen WiFi and added my WiFi name.



Next Under Connection select WebSocket, Enter the IP address of the Pi, Port 6800 and leave /jsonrpc.



Under Authentication Select Token and put in your secret.



And then click the Tick at the top.

For usage I find myself a link and now for option on open I get Aria2App as an option, if not (like pdf's just download)I just copy the url and then just swap back to the app and add. Job issa good'un.


Where to go now?

Now we have a machine to smash out downloads at home, but what about away from home? Anything interesting to say then let me know @the1kingdom on Twitter.

Comments

Popular posts from this blog

Raspberry Pi Download Machine Part 1

Yet Another Raspberry Pi Project Kodi builds, weird fucking robots and classic gaming always seems to be the theme of RPi projects. But a stat I would like to know is how many are just sat in a drawer somewhere. Anyway I am part of that number, until now. I manage to find a 4TB drive and managed to blag a caddy, so with this triangle of 'crap hanging around' I thought I'd build a downloader. Open Directories So I first had the idea from the sub-reddit open directories , here storage devices are opened up to the internet without a morsel of authentication. Google comes along and indexes them and you can go and find them. Decent ones find themselves on this sub of which I assume stays up until the user realises that there broadband is getting absolutely raped. So I wanted to be able to get a URL from a server and just throw it in a WebUI and get it to auto download and ping me when all is finished.  First Steps So to start off I downloaded Raspbian

Adventures with Pillow Part 1

I am in the middle of building an app and need to put together several promo videos for Twitter and Instagram, and man it is boring. So I thought 'how can I automate this process?', so welcome to this post. What I am going for is a selection of images, greyscaled flipping through with our logo on the front. So my approach was to use python, pillow and ffmpeg to build something. This could be disastrous. Images To start a few pre-flight checks, a variable for the test image and to check for/create a processed folder for the final images to go. import os , errno from PIL import Image , ImageFont , ImageDraw testImage = 'test.png' cwd = os.getcwd() image_dir = os.path.join(cwd , 'images' ) default_dir = os.path.join(cwd , 'processed' ) try : os.makedirs(default_dir) except OSError as e: if e.errno != errno.EEXIST: raise I am going to build a function that will do all of the processing, but first going to run on one image b