Project

General

Profile

fastcgi with one FCGI process communicating thru stdin socket?

Added by Basile_S about 15 years ago

Hello All

The system I am using a virtual private server running Linux 2.6.18 with Debian/Lenny/AMD64. The lighttpd is version 1.4.22 (compiled by myself).

I am developping a small Ocamlnet2 FastCGI application to be started from lighttpd. The FCGI (ie FastCGI) application is coded in Ocaml (compiled on my desktop running Debian/Squeez/AMD64) using the Ocamlnet2 library version 2.2.9.
http://projects.camlcity.org/projects/ocamlnet.html

The web application is for a very small site [my orthodox parish, if you care; I intend to publish the code under GPLv3]; I expect much less than 1000 hits per day. I definitely don't need several FCGI processes to run concurrently, and I am coding my FCGI application taking into account that it will be running in a single process.

from what I understood about FastCGI (or SCGI on that matter), it should be possible to have the FCGI application started by lighttpd, and communicating with lighttpd (using Fastcgi protocol) on its stdin = file descriptor 0, used as a socket. And indeed the Ocamlnet2 Netcgi_fcgi module http://projects.camlcity.org/projects/dl/ocamlnet-2.2.9/doc/html-main/Netcgi_fcgi.html mention that its run function accepts an arguemt

sockaddr : tells on what socket to contact the script. If not specified, the script expects to be launched by the web server and to communicate with it through stdin. For external scripts (launched independently of the web server and possibly on a different machine), set sockaddr to the address the web server needs to connect to to talk to the script (this address must also be specified in the wen server config file).

So I am not specifying any sockaddr in my code. If you read Ocaml and know Ocamlnet, here is my current code:

let fcgi_handler  (gdat : Util.gdata_t) (cgi : Netcgi_fcgi.cgi) =
    Util.logprintf "%s start fcgi_handler\n%!" (Util.now_mail_date_string ());
  let cgienv = cgi#environment in
  let pathinfo = cgienv#cgi_path_info in
    (* pathinfo is eg "/admin" or "/wiki/foo" *)
    Util.logprintf "pathinfo=%S\n%!"  pathinfo;
    let firstword = 
    if pathinfo.[0] == '/' then
      Scanf.sscanf pathinfo "/%[a-zA-Z0-9_]" (fun s -> s)
    else Scanf.sscanf pathinfo "%[a-zA-Z0-9_]" (fun s -> s)
  in
    Util.logprintf "pathinfo 1st word=%S\n%!" firstword;
  let handler = Util.fetch_page_handler firstword in
    gdat.Util.gdat_counter <-  gdat.Util.gdat_counter + 1;
    handler gdat cgi 
;;

let main () =
  Util.logprintf "chatenay.fcgi start pid %d at %s\n" (Unix.getpid()) (Util.now_mail_date_string ());
  let gdat = { Util.gdat_counter = 0 } in
  Netcgi_fcgi.run (fcgi_handler gdat);
    Util.logprintf "chatenay.fcgi end at %s\n" (Util.now_mail_date_string ())
;;

main ();;

The point is that not FastCGI protocol communication happens, even if the FCGI application (tentatively called chatenay) is indeed started. My /etc/lighttpd/lighttpd.conf contains

#### accesslog module
accesslog.filename          = "/var/log/lighttpd/access.log" 

## the saintspierreetpaul.org virtual host domain 
$HTTP["host"] =~ "(^|\.)saintspierreetpaul\.org$" {
   server.document-root = "/var/www/saintspierreetpaul/htdocs" 
   server.accesslog = "/var/log/lighttpd/saintspierreetpaul-access.log" 
   server.errorlog = "/var/log/lighttpd/saintspierreetpaul-error.log" 
   fastcgi.debug = 1
   fastcgi.server = ( "/index.fcgi" => ( "CHATENAY_FCGI" => (
      "socket" => "/var/tmp/chatenay.socket",
      "bin-path" => "/usr/local/bin/chatenay.fcgi",
      "bin-copy-environment" => ( "PATH", "SHELL", "USER", "HOME" ),
      "max-procs" => 1
   )))
}

Indeed, the chatenay FCGI process is started, its logfile contains

chatenay.fcgi start pid 19613 at Sun, 12 Apr 2009 18:12:40 +0200

But the fcgi_handler function is not called, which means that no FCGI protocol exchange happenned.

Lighttpd error log file contains.

2009-04-12 18:12:40: (log.c.97) server started 
2009-04-12 18:12:40: (mod_fastcgi.c.1332) --- fastcgi spawning local 
    proc: /usr/local/bin/chatenay.fcgi 
    port: 0 
    socket /var/tmp/chatenay.socket 
    min-procs: 1 
    max-procs: 1 
2009-04-12 18:12:40: (mod_fastcgi.c.1357) --- fastcgi spawning 
    port: 0 
    socket /var/tmp/chatenay.socket 
    current: 0 / 1 
2009-04-12 18:12:40: (server.c.925) WARNING: unknown config-key: server.accesslog (ignored) 
2009-04-12 18:12:40: (server.c.925) WARNING: unknown config-key: server.accesslog (ignored) 

I am quite troubled that there is two instances of the chatenay FCGI process (I really want only one) and that they don't seems to recieve any FCGI communication.
Access logs are strange also

213.41.244.95 www2.saintspierreetpaul.org - [12/Apr/2009:18:13:55 +0200] "GET /index.fcgi/admin HTTP/1.1" 404 345 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.7) Gecko/2009030810 Iceweasel/3.0.7 (Debian-3.0.7-1)" 

I probably missed something obvious. Is there any way to start one single FCGI application communicating thru stdin?

Thanks for helping.

Regards.

--
Basile STARYNKEVITCH
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
  • opinions {are only mines, sont seulement les miennes} ***

Replies (2)

RE: fastcgi with one FCGI process communicating thru stdin socket? - Added by Basile_S about 15 years ago

Apparently, I need to have an empty index.fcgi file inside /var/www/saintspierreetpaul.org/htdocs/ which is the relevant server.document-root

It now catches an Ocaml exception... (I suppose by some Ocamlnet code) much better!

Regards
--
Basile STARYNKEVITCH
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
  • opinions {are only mines, sont seulement les miennes} *

RE: fastcgi with one FCGI process communicating thru stdin socket? - Added by icy about 15 years ago

Disable the check-local option in the fcgi settings (see mod_fastcgi docs). Then you don't need that empty file anymore.

    (1-2/2)