Standalones as CGI

Andre Garzia andre at andregarzia.com
Wed Aug 15 01:54:01 EDT 2007


Richard,
I just spent the last three hours working this out for you. Not only because
you're my friend but because I wanted to know if it was possible.

short answer is: YES.

What is the problem with linux standalones:
They want to launch in graphical mode, they want to open the stack in X11.

How we can prevent that?
We can't.

So, how do we solve it?
1) First install Xvfb (X11 Virtual Framebuffer server). This allows you to
have an headless X11 server running, this means things are rendered on
memory and not in an actual display. Our standalones will be just as happy
running under Xvfb as they are running on X11+GTK.

2) After installing it, you need to leave it running on the server with a
command such as:

   Xvfb :1 -screen 0 800x600x8 &

This command tells Xvfb to bind itself to display 1 and configure the first
screen to 800x600 with 8bit depth. Not that this data will ever be
displayed. The trailing & is unix-speak for "move this to the background and
give me back my command line prompt".

3) Now, when Apache calls the CGI it uses it's own user and session to do
that, so you need a script launcher for the standalone, a simple script that
will tell where the X11 & Friends are and also which display to use. The one
I tried here looks like this (ps: my standalone is named teste2).

#!/bin/sh

export DISPLAY=localhost:1
export REV_GDK_PATH=/usr/lib/libgdk-x11-2.0.so.0
export REV_GTK_PATH=/usr/lib/libgtk-x11-2.0.so.0
export REV_GOBJECT_PATH=/usr/lib/libgobject-2.0.so.0
export REV_SSL_PATH=/usr/lib/libssl.so.0.9.7

./teste2

4) To call the standalone, you just call this script, in my case I called it
teste3.cgi. So if you go to http://andregarzia.com/cgi-bin/teste3.cgi you'll
see a simple text output 'stdout' thats generated by the standalone.

Tips & Tricks

With script cgis we usually use the "put" command to send data back to the
console/browser. With standalones this won't work. You need to send your
data to stdout with something like:

    write "hello, world!" to stdout

So, in the end you can run standalones. Just some minor gotchas. Xvfb starts
really fast, maybe you can even start it in your loader script and kill it
after your standalone exits, don't know, anyway, if you control your server
or are in a position to make requirements, you can require that Xvfb be
running on the server.

This would not be needed if RunRev team ships a linux engine that generates
standalones where we can use the -ui command too.

Hope this answer your question! :-)

Andre


On 8/15/07, Richard Gaskin <ambassador at fourthworld.com> wrote:
>
>
> Have any of you successfully run a standalone as a CGI on a Linux server?
>
> If so, how?
>
> --
>   Richard Gaskin
>   Managing Editor, revJournal
>   _______________________________________________________
>   Rev tips, tutorials and more: http://www.revJournal.com
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list