google-code-export / v8cgi

Automatically exported from code.google.com/p/v8cgi
BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

spawn-fcgi -f /xxxx/v8cgi -s /tmp/v8cgi.socket exits with result code 1 #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
i'm trying to use v8cgi (compiled with fcgi=1) within lighttpd, using
spawn-fcgi to create the socket and launch the fcgi.
However, i'm getting a 1 (or sometimes 2) exit code.
i don't know how to get more info about that.

The only thing i noted is that it (e.g. v8cgi example.js) runs ok from the
command line, launched from another directory (to make sure there is no
relative path problem).

would you have any idea about how i could investigate that problem ?

Original issue reported on code.google.com by holisme on 20 Apr 2009 at 7:03

GoogleCodeExporter commented 9 years ago
Unfortunately, I have no idea. Have you compiled v8cgi with FCGI support? When 
you
strace the call, is the socket created in the process? 

I use v8cgi's FCGI support only under Apache - and it works normally there.

v8cgi's FCGI library is a standard wrapper:
http://www.fastcgi.com/devkit/libfcgi/fcgi_stdio.c . I am not sure about its 
quality
and/or up-to-date-ness though. I recommend using v8cgi as either CGI, or Apache
module: both of these can be troubleshooted much more easily.

Original comment by ondrej.zara on 20 Apr 2009 at 7:09

GoogleCodeExporter commented 9 years ago
socket's created by spawn-fcgi, but something's wrong...

socket(PF_FILE, SOCK_STREAM, 0)         = 3
setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3, {sa_family=AF_FILE, path="/tmp/v8cgi.socket"}, 19) = 0
listen(3, 1024)                         = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
child_tidptr=0xb7e5fad8) = 18348
select(0, NULL, NULL, NULL, {0, 100000}) = ? ERESTARTNOHAND (To be restarted)
--- SIGCHLD (Child exited) @ 0 (0) ---
select(0, NULL, NULL, NULL, {0, 94453}) = 0 (Timeout)
waitpid(18348, [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], WNOHANG) = 18348
write(2, "spawn-fcgi: child exited with: 1"..., 33spawn-fcgi: child exited 
with: 1

Original comment by holisme on 20 Apr 2009 at 7:22

GoogleCodeExporter commented 9 years ago

Original comment by ondrej.zara on 22 Jun 2009 at 12:32

GoogleCodeExporter commented 9 years ago
As far as I can see in the code, the fcgi implementation only gets as far as to 
the
stdio inclusion and the while loop - yet not far enough: you need to get the 
script
filename inside the while loop through getenv("SCRIPT_FILENAME") before 
including it.

From my checks on lighttpd (strace, error log), the socket gets created and then
v8cgi exits with (1) obviously for not having a script filename. I would really 
like
to use v8cgi with lighttpd and fastcgi, too.

Greetings, Alex

Original comment by alex.th....@googlemail.com on 9 Jul 2009 at 6:48

GoogleCodeExporter commented 9 years ago
I managed to get it working quite easily, but at the expense of breaking the 
apache
mod_fcgi code...

Original comment by holisme on 9 Jul 2009 at 7:02

GoogleCodeExporter commented 9 years ago
It is FastCGI wrapper's responsibility to properly fill in the "extern char **
environ" array with all environment variables, relevant for current request. 

This array is processed in js_system.cc and converted into a JS array,
"[global.]system.env". Last, in v8cgi_App::findmain, this array is searched for
SCRIPT_FILENAME. If this value is not present, we are not in correct CGI 
environment.

I just tested v8cgi (svn rev. 525) with fastcgi enabled and (apache's) 
mod_fcgid -
everything works exactly as I just described :-(

Original comment by ondrej.zara on 10 Jul 2009 at 5:44

GoogleCodeExporter commented 9 years ago
Ah, I did not quite understand the meaning of exporting the environment in V8 
then -
I will send my changes as soon as I manage to get it to run with lighttpd. 
Thanks for
the information.

Original comment by alex.th....@googlemail.com on 10 Jul 2009 at 7:32

GoogleCodeExporter commented 9 years ago
please mr ondrej, try to test fast-cgi feature using another web server other 
than
apache ^^

@holisme
> I managed to get it working quite easily, but at the expense of breaking the 
apache
mod_fcgi code...
would you give me the diff parts which i should modify to get it work on 
spawn-fcgi?

Regards,
GB

Original comment by chosenpe...@gmail.com on 15 Oct 2009 at 1:21

GoogleCodeExporter commented 9 years ago
hai, i got it work if i use this kind of syntax:
$ spawn-fcgi -p 12345 /home/kyz/Repository/v8cgi/v8cgi test.sjs
spawn-fcgi: child spawned successfully: PID: 16002
$ ps aux | grep v8cgi
kyz      16002  0.0  0.0  26920  1652 ?        Ss   20:42   0:00
/home/kyz/Repository/v8cgi/v8cgi test.sjs
kyz      16241  0.0  0.0   7336   892 pts/7    S+   20:43   0:00 grep 
--color=auto v8cgi
$ spawn-fcgi -p 12346 /home/kyz/Repository/v8cgi/v8cgi test.sjs
spawn-fcgi: child spawned successfully: PID: 22288
$ ps aux | grep v8cgi
kyz      16002  0.0  0.0  26920  1652 ?        Ss   20:42   0:00
/home/kyz/Repository/v8cgi/v8cgi test.sjs
kyz      22288  0.0  0.0  26920  1648 ?        Ss   20:45   0:00
/home/kyz/Repository/v8cgi/v8cgi test.sjs
kyz      22776  0.0  0.0   7340   968 pts/7    S+   20:45   0:00 grep 
--color=auto v8cgi

should i always pass the sjs source file to the v8cgi to make it spawned 
correctly?
shouldn't the source file be passed to the v8cgi after the request was made?

sorry if i aksed too many questions, my knowldege about these kind of thing 
still too
low ^^

Original comment by chosenpe...@gmail.com on 15 Oct 2009 at 1:47

GoogleCodeExporter commented 9 years ago
You should *not* use spawn-fcgi in normal scenarios. I believe that this tool 
should
be used only for testing.

Normally, your FastCGI scripts are executable files starting with 
"#!/path/to/v8cgi".
Therefore, your webserver spawns these executables by running "/path/to/v8cgi
name_of_file".

Sample code (example.fcgi, EXECUTABLE FILE):

#!/bin/v8cgi
response.write("hi");

You point your browser to /example.fcgi, mod_fcgid handler spawns the executable
which in turn runs v8cgi with this file as its argument :)

O.

Original comment by ondrej.zara on 15 Oct 2009 at 1:53

GoogleCodeExporter commented 9 years ago
It seems you're mixing cgi and fastcgi.
Let me explain some basic stuff about fastcgi :

- using spawn-fcgi IS a normal scenario. It's a very good idea to use it 
instead of
relying on the web server for the spawning process. However common web servers 
still 
provide the ability to spawn processes themselves, simply because it's handy.

- the web server, once the initial spawning is done, talks to the spawned 
process 
through a SOCKET (file or network). This is the main advantage of fastcgi. When 
you 
browse to example.fcgi, it's alreay started and waiting for requests (in the 
main 
fcgi loop).

You'll find plenty of documentation on fastcgi.com

I'll attach some patch asap.

Original comment by holisme on 15 Oct 2009 at 2:08

GoogleCodeExporter commented 9 years ago
Please note that v8cgi's fcgi support is based _exactly_ on the client FastCGI
library from fastcgi.com. I am pretty confident about how this works, believe 
me :)

Also please have a look on how FastCGI is supported in v8cgi.cc, line #42. If
compiled with FastCGI support, v8cgi is supposed (via means of the fcgi 
library) to
wait until a request is made and sent to v8cgi through a socket.

Original comment by ondrej.zara on 15 Oct 2009 at 5:25

GoogleCodeExporter commented 9 years ago
Sorry for this, it was just a wicked way to complain about the dependency on 
mod_fcgid 
: it shouldn't. I'll spend some time patching this.

Original comment by holisme on 15 Oct 2009 at 5:30

GoogleCodeExporter commented 9 years ago
oic, so we can't use v8cgi as spawner of our script passed by web server?
we should provide the initial script just like my working example?
spawn-fcgi /path-to/v8cgi dummyscriptparameter.ssjs
we should make dummyscriptparameter.ssjs process (and validate) the urls etc 
passed
by web server to make it correct output?

Original comment by chosenpe...@gmail.com on 16 Oct 2009 at 12:13

GoogleCodeExporter commented 9 years ago
ok i finally got it working T_T thanks God.. everybody say yay ^^

requirement: 
nginx or other web server with fcgi support
v8
v8cgi 
spawn-fcgi 
a js script that handle the requests, in this example 
/home/kyz/Projects/site/index.esp

======
init script:

#!/bin/sh
ESP_SCRIPT='/home/kyz/Projects/site/index.esp'
V8C_SCRIPT="/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data 
`which
v8cgi` $ESP_SCRIPT"
KIL_SCRIPT="killall -v -9 `which v8cgi`"
RETVAL=0
case "$1" in
  start)
        $V8C_SCRIPT
        RETVAL=$?
        ;;
  stop)
        $KIL_SCRIPT
        RETVAL=$?
        ;;
  restart)
        $KIL_SCRIPT
        $V8C_SCRIPT
        RETVAL=$?
        ;;
  *)
        echo "Usage: v8fcgi {start|stop|restart}"
        exit 1
        ;;
  esac
ps aux | grep $ESP_SCRIPT | grep `which v8cgi`
exit $RETVAL

======
index.esp

#!/usr/local/bin/v8cgi
system.stdout(JSON.stringify(system.env));
response.write( '<html><body>' );
response.write( HTML.dump(global) ); // scary but needed for debug
response.write( '</body></html>' );

======
nginx sites-available/default, add:
        location ~ \.(sjs|ssjs|esp)$ {
                fastcgi_pass 127.0.0.1:9000;
                #fastcgi_index index.esp;    # i don't think this useful?
                #fastcgi_param SCRIPT_FILENAME
/usr/local/www/nginx$fastcgi_script_name; # what this one for?
                include fastcgi_params;                                                 
        }                  

Original comment by chosenpe...@gmail.com on 16 Oct 2009 at 3:35

GoogleCodeExporter commented 9 years ago
spawn-fcgi doesnt work without arguments because of the way cgi.init() works.
if (result) { exit(result); } causes v8cgi to exit if it is called without any 
arguments.

For use with fastcgi, i think it is safe to comment the exit line out because 
we do
not expect any arguments on init.

Works well after that. :)

Original comment by hle...@gmail.com on 18 Feb 2010 at 7:02

GoogleCodeExporter commented 9 years ago
Fixed in r779. Please re-test :)

Original comment by ondrej.zara on 22 Feb 2010 at 3:20

GoogleCodeExporter commented 9 years ago
Works ok :)

Original comment by hle...@gmail.com on 2 Mar 2010 at 4:20

GoogleCodeExporter commented 9 years ago

Original comment by ondrej.zara on 2 Mar 2010 at 5:42