<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hey Tarek,<br>
    You can use combination of nginx_memc
    (<a class="moz-txt-link-freetext" href="http://wiki.nginx.org/HttpMemcModule">http://wiki.nginx.org/HttpMemcModule</a>) and nginx_lua
    (<a class="moz-txt-link-freetext" href="https://github.com/chaoslawful/lua-nginx-module">https://github.com/chaoslawful/lua-nginx-module</a>) to achieve the
    same result. <br>
    <br>
    Here is an example:<br>
    <br>
    <pre><code>location /blah {
        rewrite_by_lua '
            if($http_x_target_service == nil) then
                return
            end
            local res = ngx.location.capture("/memc/$http_x_target_service")

            if res.status != ngx.HTTP_OK then
                       ngx.exit(</code><code>ngx.</code>HTTP_SERVICE_UNAVAILABLE)
                return
        <code>    end
            if(res.body != "up") then
                </code><code>ngx.exit(</code><code>ngx.</code>HTTP_SERVICE_UNAVAILABLE)
                 return
            end
<code></code><code>        ';

        # proxy_pass
    }
</code></pre>
    <br>
    -Umesh<br>
    <br>
    On 04/01/2011 08:07 AM, Tarek Ziade wrote:
    <blockquote cite="mid:4D95BFF1.7040400@mozilla.com" type="cite">
      <pre wrap="">Hey,

I hope this is the right list for this kind of question -- seems more 
suitable than nginx@ --

I have started the development of a module that does the following:

One each request, if a X-Target-Service header is present, the module 
checks in memcached a flag. Depending on the value, it returns a 503 or 
pass the request to the upstream server.

The goal here is to manage in memcache the status of backend services 
the application uses like twitter, linkedin etc, and reject any request 
to the server if those services are down for any reason.

I would love to get some feedback/advices from anyone experimented in 
Nginx, as I am new to this and my C skills are from college ;)

The memcached code still need a few changes like catching any 
libmemcached error etc, but the nginx module logic is basically done.

the code is here: <a class="moz-txt-link-freetext" href="https://bitbucket.org/tarek/nginx-sstatus/src/">https://bitbucket.org/tarek/nginx-sstatus/src/</a>

Cheers
Tarek

</pre>
    </blockquote>
    <br>
  </body>
</html>