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
python setup.py build
sudo python setup.py install
create the folders to hold the files
Copy the helloworld example, from this address
Although tweak it slighly by allowing a port to be specified on which it will listen
Test this server works by running the file and launching the address in a browser;
python ~/www/helloworld.py 800
This is not a great script, but it will do as a test for everything else.
Stop the server for now.
self.write("Hello, world 1")
application = tornado.web.Application([
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
and put the following at the bottom
command=python /home/pi/www/helloworld.py 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 helloworld.py script from
Following the steps on this page (http://library.linode.com/web-servers/nginx/installation/ubuntu-10.04-lucid#sph_installing-nginx-from-the-source-distribution , and http://www.thegeekstuff.com/2011/07/install-nginx-from-source/) I installed NGIX from source
sudo apt-get install libpcre3-dev build-essential libssl-dev
Get the latest source and download
tar -zxvf nginx*
./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 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 init-deb.sh http://library.linode.com/assets/660-init-deb.sh
sudo mv init-deb.sh /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
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 http://www.tornadoweb.org/documentation/overview.html?highlight=production#running-tornado-in-production
copy the standard configuration file
tweak the entries to various folders so that it matches the install. I changed the following;
I also saw an error, with
which I changed to
With everything up and running,
sudo /etc/init.d/nginx start
I saw errors
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
but ignored them!
Pointing a browser at http://192.168.1.81 now showed the helloworld.py 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;
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -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.