Forums

Foray into CGI

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Foray into CGI

Postby Charles » Sat Apr 11, 2009 5:31 pm

I made an attempt at creating .cgi scripts in Cobra on a Linux box with Apache. It ultimately failed, but I wanted to record my steps here and possibly get ideas from others.

First, I added this config in Apache's httpd.conf for a particular directory:
Code: Select all
       Options Indexes FollowSymLinks Includes +ExecCGI
       AddHandler cgi-script cgi


Then I got a "python.cgi" script working to verify that CGI worked:
Code: Select all
#!/usr/bin/python
import time
stamp = time.asctime()
print 'Content-Type: text/html\r\n\r\n'
print '<html>'
print '<body>Hello from Python at %s</body>' % stamp
print '</body>'


There was no binary install of Novell Mono for my distro, so I grabbed the Mono 2.4 source tarball and did:
Code: Select all
./configure --prefix=/usr/local
make
make check
make install


Which went fine. I then installed the last Cobra release (2009-04-07) and attempted the same type of CGI script with Cobra:
#!/usr/local/bin/cobra

class X

def main is shared
print 'Content-Type: text/html\r\n\r\n'
print '<html>'
print '<body>Hello from Cobra at [DateTime.now]</body>'
print '</body>'

This failed. It even failed to run at the command line with "./cobra-test.cgi" where almost every line generated an error, but not one from the Cobra compiler. Execution perms and file ownership were correct. Since it looked like bash was trying to read the source, I read the wikipedia page on shebang and discovered that the shebang line cannot point to another script. The "cobra" command is another script. But they say you can do this:
#!/usr/bin/env /usr/local/bin/cobra
...and indeed that works from the command line.

It failed as a .cgi script though and the error log complained that "mono" could not be found. So I changed the "cobra" script to use the full path to mono:
Code: Select all
#!/bin/bash
exec /usr/local/bin/mono "/usr/local/cobra/Cobra-0.8.0-post-2009-04-07/bin/cobra.exe" "$@"

That worked which got me to the next error:
Code: Select all
[Sat Apr 11 17:31:12 2009] [error] [client 66.171.254.110]
[Sat Apr 11 17:31:12 2009] [error] [client 66.171.254.110] GThread-ERROR **: file gthread-posix.c: line 135 (): error 'Operation not permitted' during 'pthread_getschedparam (pthread_self(), &policy, &sched)'
[Sat Apr 11 17:31:12 2009] [error] [client 66.171.254.110] aborting...
[Sat Apr 11 17:31:12 2009] [error] [client 66.171.254.110] Premature end of script headers: cobra-test.cgi

:shock: :o :?

Here is another script that cuts Cobra out. It works at the command line but chokes in Apache with the same GThread-ERROR:
Code: Select all
#!/bin/bash
echo 'Content-Type: text/html'
echo ''
/usr/local/bin/mono

I'll check with the Mono discussion forums and see if they have anything to say.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Foray into CGI

Postby Charles » Sat Apr 11, 2009 6:04 pm

Omar at Arimaa.com reports that he was able to get .cgi installed easily. His approach is to make the .cgi script very small:
Code: Select all
#!/usr/local/bin/mono foo.exe

and put all the code in "foo.cobra".

Still doesn't work for me due to the aforementioned problem with running mono from cgi, but now it becomes clear that my problem is not a general one.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 47 guests