Deploying Knoboo

This a description of how to deploy Knoboo to run behind Apache, under a sub-url (e.g., http://example.org/interactive/. This lets you add Knoboo as an additional feature to your site, rather than it being the whole site.

My motivation for this is the Computational Astrophysics Data Analysis Center (CADAC); with Knoboo up and running, I can provide the engines (kernels) with read-only access to the CADAC data. I see Knoboo as a mechanism for publishing both data, and interactive analysis of the data, beyond fixed HTML forms.

System Set Up

The deployment target is a pair of dual-processor, 64-bit Opteron nodes, both running Ubuntu 8.04. One node is the "front-end", running the Knoboo application server, and is on the public network; the other will be the kernel server, and is on a private network, using the application server as its gateway. For right now, we're actually going to run the kernel server and the application server on the front-end, to keep things simple. Later, I'll show you how to deploy the kernel server in a chrooted jail.

Create Run Directory

Knoboo started out as a desktop application, driven by a local web server. This means that it was built with a single user in mind, and keeps all of the run-time information in the user's home directory. This is fine, but I prefer to have services keep their data under /var, along with the other services. (Yes, I know that /srv and /data are also used, but I like to stick with /var.) And, I want the service to run under its own, non-privileged, system account.

The easiest way to get both of these needs met is to add a new user, and give it home in /var/lib (this is the same place services like MySQL keep their data).

$ sudo mkdir /var/lib/knoboo
$ sudo useradd -d /var/lib/knoboo knoboo-app
$ sudo chown knoboo-app:knoboo-app /var/lib/knoboo

Install Knoboo

Before installing Knoboo, make sure you have the dependencies, as listed on the front page of the Knoboo Trac site.

Ubunut 8.04 ships with Python 2.5, and you can get Twisted and SQLAlchemy using Synaptic (sudo apt-get install twisted, sudo apt-get install python-sqlalchemy).

Once you have the dependencies, check out a copy of the trunk, and do the install.

$ svn co svn://www.knoboo.com/trunk/knoboo
$ cd knoboo
knoboo $ sudo python setup.py install

Testing Knoboo

With Knoboo installed, you can start it up and test it. (Since I'm logged in to the remote machine using ssh, I start up Firefox with the --no-remote switch to access services on the remote machine as local.)

knoboo $ knobood 
Enter your Sage installation full path or hit 'Enter'
(can be changed later in '$HOME/.knoboo/kernel/kernel.conf'):

knoboo $ firefox --no-remote &
knoboo $ 

Knoboo running on localhost

Looks like things are working, and we can shutdown the server. Killing knobood is a bit of pain right now. I'm overdue to submit a kill and restart patch.

knoboo $ ps aux | grep knobood
rpwagner 20566  0.0  0.9 123756 19952 ?        S    10:24   0:00 /usr/bin/python /usr/bin/knobood
knoboo $ kill 20566

URLs and Files Configuration

For my server, I want Knoboo to be running under /interactive/. I also want all of the static media (JavaScript, CSS, etc.) to be served by Apache. There are now flags to configure both of these options, namely --url_root and --url_static_root.

knoboo $ knobood --help
Usage: knobood [options]
Options:
      --secure            Use HTTPS SSL
  -r, --proxy             Use in reverse proxy configuration
  -d, --devel_mode        Development mode
  -n, --nodaemon          don't daemonize
  -h, --host=             
  -p, --port=             Port number to listen on
  -k, --kernel_host=      kernel Server host
  -q, --kernel_port=      Kernel Server port
      --static_path=      Static path for web server
  -u, --url_root=         Root url path for web server [default: /]
  -s, --url_static_root=  Static root url path for web server [default: /]
  -e, --env_path=         Path containing config, tac, and db [default:
                          /home/rpwagner/.knoboo/knoboo]
      --version           
      --help              Display this help and exit.

Static Files

As of today --url_static_root is working, but the static files still have absolute path references, so we'll put our static files where Knoboo expects them, in a directory named static/, in Apache's document root. Before we do this, we need to make one change to a JavaScript file, and add the URL where the application server will be running under.

Around line 95 in knoboo/static/js/bookshelf.js, you'll find var nbpath = 'notebook/'+nbid;; change this to var nbpath = '/interactive/notebook/'+nbid;, where /interactive is the location you'll have the application server running.

Now we can copy static content to it's new location.

knoboo $ cd knboo
knoboo/knoboo $ sudo cp -r static/ /var/www/

Eventually, you'll be able to specify the URL to the static files at installation time, and the paths will be updated appropriately, and the files will be copied to their destination.

Configure Apache

We now need to configure Apache to do a ProxyPass between our desired URL, and the knobood daemon. (Proxies can open up security holes, so if you don't know about using proxies with Apache, read up on it.) Assuming you have mod_proxy set up appropriately for your host (virtual or otherwise), these two lines in your Apache configuration file should do it:

    ProxyPass /interactive/ http://localhost:8000/
    ProxyPassReverse /interactive/ http://localhost:8000/

You can adjust them to use the URL of your choice, and if you run knobood on a different port number.

Launching the daemon

Final step: start the service as the user created earlier. Not very tricky, but make sure you specify the URL root!

$ sudo su - knoboo-app
$ pwd
/var/lib/knoboo
$ knobood -u /interactive/ 
Enter your Sage installation full path or hit 'Enter'
(can be changed later in '$HOME/.knoboo/kernel/kernel.conf'):

$

Test it Out!

Head to your new server, create an account, and try it out! (You'll probably need to create an account first.) Here's what things looked like for me. (Note: Plotting in Matplotlib seems to messed up right now, I need to ask the Knoboo developers about that. It's fine when running standalone, but not with the URL root.) Later on, I'll add a page about putting Knoboo's kernel server on the firewalled host.

Login

Knoboo login

Bookshelf

Knoboo bookshelf

Notebook

Knoboo notebook

Attachments