Radio Pi - Part 3

Posted November 04 2012, tagged raspberrypi, radiopi,

Burn an image to an SD card

First get the PI installed and a network interface connected.  Since I will run off WIFI, I cheated and just plugged my PI in to a TV, went through the initial configuration screen, then booted in to X and configured WIFI from there.

I now have a PI where I can connect to over SSH and will automatically connect through to a wifi network.

From this page I started tearing out a few tips

Run sudo apt-get update

Get pip installed along with easy_install, since I will need these later

sudo apt-get install python-pip python2.7-dev

sudo easy_install -U distribute


Get the latest version of Tornado.  


tar xvzf tornado-2.4.tar.gz

cd tornado*

python build

sudo python install

create the folders to hold the files

mkdir ~/www

Copy the helloworld example, from this address

    nano ~/www/   

Although tweak it slighly by allowing a port to be specified on which it will listen

import sys





Test this server works by running the file and launching the address in a browser;

    python ~/www/ 800

This is not a great script, but it will do as a test for everything else.

Stop the server for now.

    import sys

    import tornado.ioloop

    import tornado.web


    class MainHandler(tornado.web.RequestHandler):

        def get(self):

            self.write("Hello, world 1")


    application = tornado.web.Application([

        (r"/", MainHandler),



    if __name__ == "__main__":





To run and keep an eye on Tornado instance, we will use Supervisor.

    "Supervisor is a client/server system that allows its users to control a number of processes on UNIX-like operating systems."    

Using instructions on this page as a starting point:

sudo easy_install supervisor

then create a sample file in the home directory

    echo_supervisord_conf > supervisord.conf

edit the file

    nano supervisord.conf

and put the following at the bottom

    command=python /home/pi/www/ 800%(process_num)01d





then move the file to the /etc/ directory

    mv supervisord.conf /etc/supervisord.conf

Running Supervisord on boot

    sudo chmod +x /etc/init.d/supervisord

    sudo update-rc.d supervisord defaults

    sudo /etc/init.d/supervisord start

From a browser you should be able to access the script from



Following the steps on this page ( , and  I installed NGIX from source

    sudo apt-get install libpcre3-dev build-essential libssl-dev

Get the latest source and download


    tar -zxvf nginx*

    cd ngix*

./configure --help will show the options

Compile to server, I'll install to default directory, and have it run under its own user and group.  SSL is also useful

    sudo ./configure --user=nginx --group=nginx --with-http_ssl_module

    sudo make

    sudo make install

Add the user we install nginx with.

    sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx

I need a start up script to launch nginx at boot

    wget -O

    sudo mv /etc/init.d/nginx

    chmod +x /etc/init.d/nginx

    sudo /usr/sbin/update-rc.d -f nginx defaults

However since this script assumes nginx is installed in opt, we need to tweak it slightly

    sudo nano /etc/init.d/nginx

Change the paths from /opt/nginx/ to /usr/local/nginx/

Edit the nginx.conf file

    sudo nano /usr/local/nginx/conf/nginx.conf

and uncomment the line

# error_log     logs/error.log

Test starting the ngix server

    sudo /etc/init.d/nginx start

Then within a browser test the server by typing in the IP address of the computer, you should see the nice "Welcome to nginx" message

Lets stop the service, i tried

    sudo /etc/init.d/nginx stop

but site was still available, so I had to

    ps aux | grep nginx

then kill both processes

    kill [PID]

So we need to configure nginx to proxy the four tornado servers

Remove the current config file

    sudo rm /usr/local/ngix/conf/nginx.conf

Create a new file and add in the configuration

    sudo nano /usr/local/ngix/conf/nginx.conf

from this page

    copy the standard configuration file

tweak the entries to various folders so that it matches the install.  I changed the following;

error_log logs/error.log;

include /usr/local/nginx/conf/mime.types;

access_log /usr/local/nginx/logs/access.log;

I also saw an error, with

proxy_redirect  false

which I changed to

proxy_redirect  off

With everything up and running,

sudo /etc/init.d/nginx start

I saw errors

nginx: [emerg] bind() to failed (98: Address already in use)

but ignored them!

Pointing a browser at now showed the page!

Lets just issue a reboot, and see if everything comes up OK.

On reboot, Nginx did not start, although each of the tornado instances were available.  A quick search showed that it could have been a problem with the SSL certificate missing.

So from the following page I just created an SSL certificate;

cd /usr/local/nginx/conf

openssl genrsa -des3 -out server.key 1024

openssl req -new -key server.key -out server.csr

cp server.key

openssl rsa -in -out server.key

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

I've not set-up the server to use SSL, but that seemed to solve the boot issue.



comments powered by Disqus