Tag Archives: opensource

Using Inets – Erlang’s Builtin Web Daemon

A feature I’ve been meaning to add to Open Server Platform for a while is a web management system, where an administrator can login and manage the cluster and the servlets running on it. I’d like there to be a user friendly interface for administrators to start, stop and migrate servlets across the different nodes of the system and a way to upload a servlet file and have it compiled and distributed across the cluster.

The simplest way to start serving web content with Erlang is to use the inets server and the httpd service. This is a HTTP/1.1 server built into the Erlang distribution that supports some more advanced features, most interesting of all, the ability to use Erlang to dynamically generate content. It is however very poorly documented, and there are a few very annoying things I came across that I’m posting to hopefully help anyone else trying to get it working.

  1. The order of modules in the {modules, []} directive matters, if you want to have mod_dir work, it needs to be specified *AFTER* the mod_alias.
  2. The logging is rather horrid, the transfer.log will not log anything except for HTTP 200 for every request, even if it failed.
  3. You must specify {bind_address, any} in the configuration to use the httpd:reload_config function, otherwise it will return {error, not_started}
  4. If you just want to server static content, you will need at a minimum the following modules: mod_get, mod_head, mod_log, mod_actions and mod_range. However, adding mod_alias is recommended along with the {directory_index, ["index.html"]} directive to stop it from failing (HTTP 500) on a directory request.
  5. To use dynamic content, create a module that exports callbacks of the form: function(SessionID, _Env, _Input). To write Str back to the client, use the mod_esi:deliver(SessionID, Str) function.

I hope that this helps out!

Peace and chow,

Ranok

Git and Wiki Wide Web

I admit it, I’ve finally jumped on the Git bandwagon. After toying with SVN and Darcs, I was convinced when I saw a screen-cast about branching and merging and how it makes the kind of random, skitzo programming that I do very easy and very maintainable. I started using it at work to keep track of some files as a test and finally bit the bullet and signed up for a GitHub account. Once I had gotten setup, I made a few repositories to upload some code I had made for my high school senior project, code that I haven’t looked at in years and probably never will again. Then I decided to share something a bit more exciting, Wiki Wide Web‘s bleeding edge source code. After some quick review to ensure I cleared the code of any hard coded passwords, I committed the source.

One thing I like about putting your code on a site like GitHub is that it guilts you into cleaning it up. If you hope that people are going to see it, then you feel slightly pushed to make an effort to clean it up. That pressure lead me to add some installation instructions and a make file for the Firefox extension, and clean up some code.

Peace and chow,

Ranok