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=kqueue
    # reactor=epoll


   # reactor=select
    # reactor=kqueue

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




Make sure Orbited will be listening on the following ports:


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.

    * -> 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/
        ProxyPassReverse /orbited/
        ProxyPass /orbited/static/
        ProxyPassReverse /orbited/static/

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(

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

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


 $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


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


   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.

    # orbited daemon
    # chkconfig: 345 20 80
    # description: orbited daemon
    # processname: orbited



    DESC="Orbited server"

    case "$1" in
        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"
                echo $PID > $PIDFILE
                printf "%s\n" "Ok"
            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"
                    echo "Running"
                printf "%s\n" "Service not running"
            printf "%-50s" "Stopping $NAME"
                PID=`cat $PIDFILE`
                cd $DAEMON_PATH
            if [ -f $PIDFILE ]; then
                kill -HUP $PID
                printf "%s\n" "Ok"
                rm -f $PIDFILE
                printf "%s\n" "pidfile not found"

        $0 stop
        $0 start

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

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, not published)