It’s almost too easy with a Raspberry Pi
Microservices – they help us scale our applications robustly. Here is an example of how the Raspberry Pi can be used to run such services on a cron-schedule.
I am part of Overskrift.dk – a local social media monitoring service built on a LAMP stack. We are running aggregation of content to a central database on the main server itself, but also on quite a few older laptops. They do have a couple of downsides though:
- Big (-ish)
- Clunky
- Noisy
- Power consuming
- Have mechanical harddisks
They each need PHP, cUrl and a MySQL client library installed in order to function and aggregate content – but then they are actually able to support our aggregation tasks quite nicely.
So the other day when a harddisk crashed, I came to think of the Raspberry Pi (popularly dubbed the $25 computer) – It actually set me back DKK 638,- ($95) including P&P from a danish webshop, but that was only because I insisted on a cabinet, a power supply and an SD card. Still I can get three of these for the same price as 1 very low-end netbook. An hour after the postman delivered the envelope, it was up and running aggregating away.
From my laptop I downloaded the Raspian “wheezy” SD card image – it downloads a .zip file to unzip into a .img-file. On Mac and Linux the image can easily be copied to the SD card (but taking about 20 minutes). I used this process.
Once the image was downloaded I moved the SD card to theRaspberry Pi unit, plugged a keyboard into one of the USB ports, connected my TV through the HDMI connector and powered up. First boot took about 30 seconds and took me directly to a very nice configuration UI, I set the locale and timezone and asked the ssh-daemon to start on boot.
Next step was to shut down and move the box over to a LAN connection by my modem. Now only the LAN connection and the power supply was connected.
Coming from the Ubuntu world, installing PHP, cUrl and the MySQL client libraries was a question of logging on, running
sudo apt-get update
sudo apt-get install php5 curl php5-curl php5-mysql mysql-client
Now I could simply copy my PHP code to the filesystem and set up cron jobs just as I would in Ubuntu.
UPDATE 2014-02-21: It has been almost a year since we started using Raspberry PI’s for our aggregation purposes. Since then, we’ve added a couple of pi’s for this specific purpose and retired all other aggregations machines, probably saving quite a bit on our power bill.
Add your own comment