<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>No Content, No Fuss: Mercurial FastCGI module</title>
    <link>http://anil.recoil.org/blog/articles/2006/12/27/mercurial-fastcgi-module</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Anil Madhavapeddy</description>
    <item>
      <title>Mercurial FastCGI module</title>
      <description>&lt;p&gt;Our &lt;a href="http://www.lighttpd.net"&gt;lighttpd&lt;/a&gt; setup has been very unstable in recent months, probably brought on by the load of the large &lt;a href="http://www.selenic.com/mercurial"&gt;Mercurial&lt;/a&gt; repositories &lt;a href="http://hg.recoil.org/"&gt;hosted&lt;/a&gt; on Recoil since the Google &lt;a href="http://code.google.com/soc/"&gt;Summer of Code&lt;/a&gt; mentoring.&lt;/p&gt;

&lt;p&gt;The source of the instability was really hard to track down, but it seems to be the automatic spawning of &lt;a href="http://www.fastcgi.org/"&gt;FastCGI&lt;/a&gt; processes by the web-server, and lighttpd failing to handle a &lt;a href="http://en.wikipedia.org/wiki/SIGCHLD"&gt;SIGCHLD&lt;/a&gt; somewhere when a child process crashes.  To sort this out, I just converted all the Ruby on Rails setups (this blog and &lt;a href="http://nick.recoil.org/"&gt;Nick's&lt;/a&gt;) to use an external spawn.&lt;/p&gt;

&lt;p&gt;This only leaves our Mercurial vhost &lt;a href="http://hg.recoil.org/"&gt;hg.recoil.org&lt;/a&gt; to switch to using FastCGI, and I couldn't find a module for this anywhere and so lashed up some Python glue to do the job.&lt;/p&gt;

&lt;p&gt;You can download the small distribution for Mercurial 0.9 (&lt;a href="http://anil.recoil.org/projects/hg-fcgi-0.9.tar.gz"&gt;hg-fcgi-0.9.tar.gz&lt;/a&gt;).  It has a FastCGI library written by someone else, the Python files to glue the Mercurial and FastCGI libraries together, and a simple rc script to launch the external web process.&lt;/p&gt;&lt;p&gt;Instructions are for lighttpd... install the Python files somewhere, modify them to point to the Mercurial directory, run the rc script to start the daemon, and then add something similar to the following to your lighttpd config file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;fastcgi.server = (
  ".fcgi" =&amp;gt; ( "localhost" =&amp;gt;
    ( "socket" =&amp;gt; "/var/cache/fcgi/sites/hg.recoil.org/dirsock" )),
  ".hg" =&amp;gt; ( "localhost" =&amp;gt;
    ( "socket" =&amp;gt; "/var/cache/fcgi/sites/hg.recoil.org/sock" )),
)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Also add "index.fcgi" to &lt;em&gt;index-file.names&lt;/em&gt; in the config file, and touch it in the vhost directory to create an empty file (this is to avoid getting a 404 error and instead pass it through to the FastCGI process).  Similarly, touch a .hg file for every repository you want to serve.  You could do this differently by passing through a URL prefix and modifying the Python appropriately, but I prefer finer control over what we're serving.&lt;/p&gt;

&lt;p&gt;Hope this is useful; I won't bother submitting it back to the Mercurial list as it looks like the &lt;a href="http://www.selenic.com/hg/"&gt;official hg repo&lt;/a&gt; has a different code layout; I'll check it out later on when I have a bit more time and integrate properly.&lt;/p&gt;

&lt;p&gt;I have no idea whether or not this will actually improve our stability, but it's at least easier to move onto a different web-server now that everything is FastCGI.  All I need now is an OpenBSD/php5-fastcgi port, which doesn't seem to exist (yet).&lt;/p&gt;</description>
      <pubDate>Wed, 27 Dec 2006 20:59:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c9de9f88-5d89-42ea-9430-6df6c7054109</guid>
      <author>anil@recoil.org (Anil Madhavapeddy)</author>
      <link>http://anil.recoil.org/blog/articles/2006/12/27/mercurial-fastcgi-module</link>
      <category>hacking</category>
      <category>net</category>
    </item>
  </channel>
</rss>
