12 December 2012

Installing and running Orbited and Status.net on an Ubuntu server

After messing around with a status.net install, I thought it might be fun to see if I could get live updates working using an Orbited server.

Orbited is a Python-based server that allows us to push data from the server to the browser without the browser explicitly requesting it. This means we can push live updates to users on our status.net instance as they happen.

I'm going to be setting up the Orbited server on the same machine as the status.net install, and using SSL to secure the connection for both the standard site and the orbited pushed updates. This means we're going to make some minor edits to the status.net and Orbited source code to facilitate this. There are other ways of doing this, but I found this to be the simplest.

I'll assume you've already got a working status.net install before we begin. If not, see the installation instructions on their site.

Next, we need to install python twisted, orbited and stomp:

   sudo easy_install twisted
    sudo easy_install orbited
    sudo easy_install stompservice
    sudo easy_install simplejson

Next we need to change some settings in the Orbited configuration file:

   sudo nano /etc/orbited.cfg

Linux is more efficient using epoll, so change

   reactor=select
    # reactor=kqueue
    # reactor=epoll

to

   # reactor=select
    # reactor=kqueue
    reactor=epoll

We want Orbited to run as an unprevileged user (which will be called 'orbited'), so change

   #user=orbited

to

   user=orbited

Make sure Orbited will be listening on the following ports:

   [listen]
    http://:8000
    stomp://:61613

We don't need to activate the SSL port because apache will be listening on that port and passing requests to Orbited on the same machine.

Now change the access section to allow connections to Orbited. Make sure you replace "example.com" with your domain.

   [access]
    * -> localhost:61613
    * -> example.com:61613

This allows everything (*) to connect to the local machine on port 61613. Really, we only need the local machine to be able to access those ports (as we will be using Apache to proxy requests to and from them). You can lock this down once everything is running properly.

We're done editing the config, so press ctrl + x to exit and save your changes.

Next, we need to add a system user for Orbited to run as:

   sudo useradd -r orbited

Now we can test the orbited server:

   sudo orbited

If you don't see any errors, press ctrl + c to kill the server.

Now we can edit our Apache virtualhost configuration to proxy requests for orbited. First, ensure the correct Apache modules are loaded:

   sudo a2enmod proxy
    sudo a2enmod proxy_http

Edit your site config:

   sudo nano /etc/apache2/sites-available/example.com

and add the following:

   <VirtualHost *:443>
    ...
        ProxyRequests Off
        ProxyPass /orbited/ http://127.0.0.1:8000/
        ProxyPassReverse /orbited/ http://127.0.0.1:8000/
        ProxyPass /orbited/static/ http://127.0.0.1:8000/static/
        ProxyPassReverse /orbited/static/ http://127.0.0.1:8000/static/
    ...
    </VirtualHost>

Remember, this assumes you already have your SSL certificates set up and working. You can now restart Apache for the changes to take effect.

   sudo /etc/init.d/apache2 restart

We will now edit our status.net install to use the Orbited server. First make sure status.net will load the Orbited plugin by editing the main configuration file:

   sudo nano /var/www/example.com/config.php

add at the bottom of the file:

 addPlugin('Orbited', array(
            'webserver'=>'orbited.example.com',
            'webport'=>'443'
    );

Now we will edit plugins/Orbited/OrbitedPlugin.php to ensure it uses SSL and our orbited path. Change:

 $root = 'http://'.$server.(($port == 80) ? '':':'.$port);

to

 $root = 'https://'.$server.(($port == 80) ? '':':'.$port).'/orbited';

and make sure the returned path is correct:

 return "tcp://$server:$port/orbited";

Press ctrl + x to exit and save, then edit Orbited.js to use our new Orbited path:

   sudo nano /usr/local/lib/python2.7/dist-packages/orbited-0.7.11beta3-py2.7.egg/orbited/static/Orbited.js

change

   var sessionUrl = new Orbited.URL('/tcp');

to

   var sessionUrl = new Orbited.URL('/orbited/tcp');

Exit and save again (ctrl + x). Create pid directory and make sure the orbited user owns it:

   sudo mkdir /var/run/orbited
    sudo chown orbited /var/run/orbited

Now we can create an init.d script which we can use to start and stop our Orbited server:

   sudo nano /etc/init.d/orbited

then paste the following into the file and save.

   #!/bin/bash
    # orbited daemon
    # chkconfig: 345 20 80
    # description: orbited daemon
    # processname: orbited

    DAEMON_PATH="/usr/local/bin/"

    DAEMON=orbited
    DAEMONOPTS=""

    NAME=orbited
    DESC="Orbited server"
    PIDFILE=/var/run/$NAME/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME

    case "$1" in
    start)
        printf "%-50s" "Starting $NAME..."
        cd $DAEMON_PATH
        PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
        #echo "Saving PID" $PID " to " $PIDFILE
            if [ -z $PID ]; then
                printf "%s\n" "Fail"
            else
                echo $PID > $PIDFILE
                printf "%s\n" "Ok"
            fi
    ;;
    status)
            printf "%-50s" "Checking $NAME..."
            if [ -f $PIDFILE ]; then
                PID=`cat $PIDFILE`
                if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
                    printf "%s\n" "Process dead but pidfile exists"
                else
                    echo "Running"
                fi
            else
                printf "%s\n" "Service not running"
            fi
    ;;
    stop)
            printf "%-50s" "Stopping $NAME"
                PID=`cat $PIDFILE`
                cd $DAEMON_PATH
            if [ -f $PIDFILE ]; then
                kill -HUP $PID
                printf "%s\n" "Ok"
                rm -f $PIDFILE
            else
                printf "%s\n" "pidfile not found"
            fi
    ;;

    restart)
        $0 stop
        $0 start
    ;;

    *)
            echo "Usage: $0 {status|start|stop|restart}"
            exit 1
    esac

Save the script (ctrl + x) and make it executable:

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

You should now be able to start and stop Orbited with

   sudo /etc/init.d/orbited start
    sudo /etc/init.d/orbited stop

To make orbited start when the machine boots:

   sudo update-rc.d orbited defaults

And you're done. You should now be able to log in to your status.net site and receive live updates pushed to your browser.

Post a comment

(required)

(required)

(required, not published)

(optional)