Starting the server, configuring

Requirements

You'll need at least Python 2.3 to run Snakelets.

Please consider installing the sendfile(2) system call extension module from Snakefarm.org (works on Linux) or the one from Ben Woolley (which works on Linux and BSD too). This module may improve performance and CPU utilization in some cases (experiment!). Snakelets will automatically use it if it is installed (doesn't matter which one of the two mentioned above).

Out-of-the-box startup

It is possible to start the Snakelets server out-of-the-box, without changing anything. If you don't enable the virtual host feature (see below), Snakelets will scan the "webapps" directory and will load all web applications it finds on the current host. If you have a web app named "ROOT" that one will be used as the web application for the root context '/'. You can just start the serv.py script without configuring anything and away you go. The default port number is 9080, so you can access the server with the following url: http://machinename.domain:9080/ .

Warning: the default config works but is very likely not the one that you want for your own server environment. One of the things you will have to change is removing the example plugins (if any) and webapps that come with Snakelets!

Apache?

...is not needed: Snakelets contains its own multithreaded web server. But if you still want to use Apache, you can use mod_proxy or mod_rewrite to let Apache forward certain requests to a running snakelets server behind it. Plans exist to develop a snakelets module for tighter integration in Apache, and for more performance. But for now, you'll have to use mod_proxy (or mod_rewrite).

Configuring Apache; bottom line: Set up apache to reverse-proxy everything after snake/ to Snakelets.

Warning: as the Apache manual also states, regarding the use of proxies: please secure your Apache configuration: do not let it become an open proxy server!

Edit your Apache config file. Make sure that mod_proxy is loaded in the LoadModule section.
Configure the forwarding to the Snakelets server:

ProxyRequests Off
ProxyPass /snake/ http://localhost:9080/snake/
ProxyPassReverse /snake/ http://localhost:9080/snake/

This example forwards all requests starting with '/snake/' to Snakelets. You can also configure a dedicated virtual host, for example:

<VirtualHost snakelets.host.domain>
  ServerName snakelets.host.domain
  ProxyRequests Off 
  ProxyPass / http://localhost:9080/
ProxyPassReverse / http://localhost:9080/
</VirtualHost>

Now all requests to this hostname will be passed to Snakelets.

Then run Snakelets where you set (in serv.py) bindname='localhost', serverURLprefix='/snake/' and externalPort=80. If you use the virtualhost mapping, the serverURLprefix is empty.

Note: if you are using mod_cache, you must tell it to not cache the Snakelets urls! This can be done like this:

    <IfModule mod_cache.c>
      CacheDisable /your-snakelet-url-base
    </IfModule>

If you find that your URLs are not correct in Snakelets, you also have to enable virtual hosting in Snakelets (see below) and create a virtual host entry for the 'correct' hostname (i.e. the hostname that is used in your URLs). (You can still use a different bindname such as "localhost").

Virtual Hosts

Snakelets supports virtual hosting (based on hostnames). To enable this feature you have to edit the Virtual Host configuration. It tells the server what web applications to load and to what host names they must be connected. If you have different hostnames that point to the same IP address you are able to serve different web sites this way (this only works with HTTP 1.1 browsers, but most browsers are). The configuration file is webapps/__init__.py (the webapp module init file). It contains four configuration items:

Every vhost can have a different list of webapps that are deployed on it, but a webapp can also be deployed on multiple vhosts at the same time. However, all deployed instances will be separate, unrelated copies of the webapp: if you deploy a webapp on multiple vhosts, it will be created for each vhost, and the init function will be invoked once for every copy.

Starting the server

If the virtual host config is in place, the Snakelet server is best started using the provided serv.py script. Just execute this and you're ready to go! Notice that the web applications that you configured in the virtual host config are installed automatically, any other web applications in the webapps directory are ignored. The parameters to snakeserver.server.main are:

It is also possible to use the monitor.py script. This script is designed to run on Linux, and will check if the server is active. If it's not active (or hanging) the monitor script will restart the Snakelets server (as a daemon process in the background). After starting the server it does not check anymore if it's still running, so you will have to create your own mechanism to be sure that a stopped (crashed?) server is restarted.

Logging

The server uses the standard Python logging module to log messages (if you're not using Python 2.3 or newer, you'll have to install the logging package yourself first). Logfiles appear in the "logs" directory. Logging configuration is in the "logging.cfg" file. There are a few loggers:

You can use the logging facility in your own code by doing:

import logging
log=logging.getLogger("Snakelets.logger")
log.debug("my debug message")

User libraries / modules

If you want to use a library or module from within several webapps, you don't have to include it in every webapp directory. There is a special directory "userlibs" in which you can place your modules and packages that you want to install. Snakelets adds this directory to the module search path, so you can import anything in it in your webapps without using nasty prefixes.

You can also easily upgrade libraries this way, just put the new version in userlibs instead of the older version and all your webapps that import it will instantly use the new code the next time you start the server.

Snakelets manual - Back to index