RE: Set DocumentRoot from modperl

2000-04-04 Thread Doug MacEachern

On Tue, 4 Apr 2000, Karyn Ulriksen wrote:

> Which handler would be appropriate to do the cleanup on this?

you register the cleanup function from whatever handler changes
document_root.  that'll happen at the same time as PerlCleanupHandler,
which is after PerlLogHandler.

>> my $old_docroot = $r->document_root;
>> $r->register_cleanup(sub { shift->document_root($old_docroot) });




RE: Set DocumentRoot from modperl

2000-04-04 Thread Karyn Ulriksen

Which handler would be appropriate to do the cleanup on this?

-Original Message-
From: Doug MacEachern [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 02, 2000 10:39 PM
To: Serge document_root;
$r->register_cleanup(sub { shift->document_root($old_docroot) });

the lifetime of conf->ap_document_root is longer than that of r->pool, so
it can't be used to allocate the string copy.
we could use the server pool, which isn't destroyed until the server is
restarted, but then each time you set document_root, the server would
"leak" memory.
to workaround, the new document_root is saved in a Perl variable
$Apache::Server::DocumentRoot

--- src/modules/perl/Apache.xs  2000/04/03 04:48:52 1.92
+++ src/modules/perl/Apache.xs  2000/04/03 05:36:56
@@ -783,8 +783,26 @@
 Apacher
 
 const char *
-document_root(r)
+document_root(r, ...)
 Apacher
+
+PREINIT:
+core_server_config *conf;
+
+CODE:
+conf = (core_server_config *)
+  get_module_config(r->server->module_config, &core_module);
+
+RETVAL = conf->ap_document_root;
+
+if (items > 1) {
+SV *doc_root = perl_get_sv("Apache::Server::DocumentRoot", TRUE);
+sv_setsv(doc_root, ST(1));
+conf->ap_document_root = SvPVX(doc_root);
+}
+
+OUTPUT:
+RETVAL



Re: Set DocumentRoot from modperl

2000-04-02 Thread Doug MacEachern

there have been several requests for the ability to modify the
DocumentRoot, i reckon it's about time we allow that.

caveats:
if you want the DocumentRoot to be reset to the original value after the
request is over, you'll have to do that yourself, something like:
my $old_docroot = $r->document_root;
$r->register_cleanup(sub { shift->document_root($old_docroot) });

the lifetime of conf->ap_document_root is longer than that of r->pool, so
it can't be used to allocate the string copy.
we could use the server pool, which isn't destroyed until the server is
restarted, but then each time you set document_root, the server would
"leak" memory.
to workaround, the new document_root is saved in a Perl variable
$Apache::Server::DocumentRoot

--- src/modules/perl/Apache.xs  2000/04/03 04:48:52 1.92
+++ src/modules/perl/Apache.xs  2000/04/03 05:36:56
@@ -783,8 +783,26 @@
 Apacher
 
 const char *
-document_root(r)
+document_root(r, ...)
 Apacher
+
+PREINIT:
+core_server_config *conf;
+
+CODE:
+conf = (core_server_config *)
+  get_module_config(r->server->module_config, &core_module);
+
+RETVAL = conf->ap_document_root;
+
+if (items > 1) {
+SV *doc_root = perl_get_sv("Apache::Server::DocumentRoot", TRUE);
+sv_setsv(doc_root, ST(1));
+conf->ap_document_root = SvPVX(doc_root);
+}
+
+OUTPUT:
+RETVAL




RE: Set DocumentRoot from modperl

2000-03-28 Thread Serge


Thanks everybody for your suggestions. I actually went through the past
threads on that topic, and it seems to me it always sparks much
discussion!!

Karyn> I believe he is trying to do this 'on the fly' without reboot for
Karyn> the new configs.

Exactly.

Karyn> I beat my head on this pretty good before and ended having to invest
Karyn> in the development to make it work, but the development really
Karyn> wasn't that ugly and it works like a champ.  Just make sure you have
Karyn> some kind of caching mechanism (or figure out how to use the apache
Karyn> pools) so that you aren't hitting the database for every http
Karyn> request.

I actually use some caching, so I don't expect to have much penalties from 
it.

I finally decided to rewrite the URI translation handler in perl
at first, and later on directly in C for best performance. This approach
will also allow me to tune the translation stage to my particular case
and remove all the little inefficiencies (extra stat()'s) there.
As opposed to your case I don't have downstream frontpage or CGI, so I
guess I don't need to worry about passing along the DOCUMENT_ROOT correctly.
Though as you say it would be nice to simplify the whole process in
the future.

Cheers,
Serge

Karyn> I didn't find too many people who really understood what the
Karyn> benefits are of doing this.  I guess if someone did, it would be
Karyn> more accessible in Apache itself.  The benefits in management,
Karyn> scalability, and minimizing downtime by those idiots ... I mean
Karyn> customers ... who do stupid things like delete their htdocs
Karyn> directories and cause the whole rebooting process to fail.
Karyn> If any of the big guys are listening, this is big on my wish list
Karyn> for upcoming apache adds.  I've committed myself to bellying up to
Karyn> the bar to learn C just so I can do something like this using the
Karyn> apache engine.

Karyn> - Karyn

Karyn> -Original Message- From: Michael
Karyn> [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 28, 2000 2:03
Karyn> PM To: [EMAIL PROTECTED] Subject: RE: Set DocumentRoot from modperl


>> Sergio,
>> 
>> I just walked this route...
>> 
>> The long and short is that it can't be done anything close to feasably.

Karyn> There is a work around to this. If you use the syntax


Karyn> perlcode perlcode require 'somefile.cgi'; more perl more perl

Karyn> then the cgi script gets imported into the environment and RUN with
Karyn> the current document root rather than the one for modperl for the
Karyn> whole system. Yeah, it's messy and require was not intended to be
Karyn> used quite that way, but it works!

>>  You'll have to write your own URI Translator and alter some code so
>> that you can introduce your DOCUMENT_ROOT down the line to things like
>> the mod_cgi etc.  If you search the mod_perl forum, you'll see some
>> handy code that one of the gurus around here provided me use the NOTES
>> table.
>> 
>> BTW, if you're introducing FrontPage to your masses.  You'll have to
>> re-write your own fpcount.exe.  The codes not available and it's
>> anybody's guess where the hell it actually gets the document root from
>> (I even encoded it into the mod_frontpage.c module without success) and
>> naturally the source isn't available.
>> 
>> Have fun.  I did!
>> 
>> 
>> - Best regards,
>> 
>> Karyn Ulriksen Chief Systems Architect PublicHost 22 Mauchly, Suite 200
>> Irvine, California 92618 USA Phone: (949) 743-2000 email:
>> [EMAIL PROTECTED] URL: http://www.publichost.com
>> 
>> 
>> 
>> -Original Message- From: Serge > [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 28, 2000 1:45 PM To:
>> [EMAIL PROTECTED] Subject: Set DocumentRoot from modperl
>> 
>> 
>> 
>> Hi, I am trying to find a way of setting DocumentRoot (and possibly
>> Alias) directly from modperl in order to implement dynamically generated
>> virtual hosting. The thing is that my virtualhost parameters comes from
>> a database and may change anytime (so I can't restart Apache in
>> general), so it is difficult to implement with Apache virtual host
>> rewrite, mod_rewrite or even  directives in httpd.conf. I tried to
>> use subprocess_env to set this variable, but it is useful only for
>> cgi-scripts, not perl or C handlers since it sets the Environment
>> variable only.
>> 
>> Is the only solution to rewrite the URI translation phase so it does not
>> use DocumentRoot directive??
>> 
>> -- 
>> Serge Barbosa Da Torre - [EMAIL PROTECTED]
>> 
>> "It's not easy, being green."  -- Kermit the Frog
>> 

-- 
Serge Barbosa Da Torre  -  [EMAIL PROTECTED]

"It's not easy, being green."
-- Kermit the Frog



RE: Set DocumentRoot from modperl

2000-03-28 Thread Michael

> I believe he is trying to do this 'on the fly' without reboot for
> the new configs.
> 
Oh, maybe I misunderstood. 
The problem I had was executing code that needed to know the document 
root which seems to point to the main mod_perl doc root rather than 
the root of the particular virtual root. That is what my work around 
covers.

Michael

[EMAIL PROTECTED]



RE: Set DocumentRoot from modperl

2000-03-28 Thread Karyn Ulriksen

I believe he is trying to do this 'on the fly' without reboot for the new
configs.

If you know how to do this with a require in the configs, I'd sure like to
hear more.

I beat my head on this pretty good before and ended having to invest in the
development to 
make it work, but the development really wasn't that ugly and it works like
a champ.  Just make sure you have some kind of caching mechanism (or figure
out how to use the apache pools) so that you aren't hitting the database for
every http request.

I didn't find too many people who really understood what the benefits are of
doing this.  I guess if someone did, it would be more accessible in Apache
itself.  The benefits in management, scalability, and minimizing downtime by
those idiots ... I mean customers ... who do stupid things like delete their
htdocs directories and cause the whole rebooting process to fail.

If any of the big guys are listening, this is big on my wish list for
upcoming apache adds.  I've committed myself to bellying up to the bar to
learn C just so I can do something like this using the apache engine.

- Karyn

-Original Message-
From: Michael [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 28, 2000 2:03 PM
To: [EMAIL PROTECTED]
Subject: RE: Set DocumentRoot from modperl


> Sergio,
> 
>I just walked this route...
> 
>The long and short is that it can't be done anything close to
>feasably.

There is a work around to this. If you use the syntax


perlcode
perlcode
require 'somefile.cgi';
more perl
more perl

then the cgi script gets imported into the environment and RUN with 
the current document root rather than the one for modperl for the 
whole system. Yeah, it's messy and require was not intended to be 
used quite that way, but it works!

> 
>You'll have to write your own URI Translator and alter some code
>so that
> you can 
>introduce your DOCUMENT_ROOT down the line to things like the
>mod_cgi
> etc.  If you 
>search the mod_perl forum, you'll see some handy code that one of
>the
> gurus 
>around here provided me use the NOTES table.
> 
>BTW, if you're introducing FrontPage to your masses.  You'll have
>to
> re-write your 
>own fpcount.exe.  The codes not available and it's anybody's
>guess where
> the hell 
>it actually gets the document root from (I even encoded it into
>the
> mod_frontpage.c
>module without success) and naturally the source isn't available.
> 
>Have fun.  I did!
> 
> 
> - Best regards,
> 
> Karyn Ulriksen
> Chief Systems Architect
> PublicHost
> 22 Mauchly, Suite 200
> Irvine, California  92618 USA
> Phone: (949) 743-2000
> email: [EMAIL PROTECTED]
> URL:  http://www.publichost.com
> 
> 
> 
> -Original Message-
> From: Serge mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 28, 2000 1:45 PM To: [EMAIL PROTECTED]
> Subject: Set DocumentRoot from modperl
> 
> 
> 
> Hi,
> I am trying to find a way of setting DocumentRoot (and possibly
> Alias) directly from modperl in order to implement dynamically
> generated virtual hosting. The thing is that my virtualhost
> parameters comes from a database and may change anytime (so I can't
> restart Apache in general), so it is difficult to implement with
> Apache virtual host rewrite, mod_rewrite or even  directives
> in httpd.conf. I tried to use subprocess_env to set this variable,
> but it is useful only for cgi-scripts, not perl or C handlers since
> it sets the Environment variable only.
> 
> Is the only solution to rewrite the URI translation phase so it does
> not use DocumentRoot directive??
> 
> -- 
> Serge Barbosa Da Torre-  [EMAIL PROTECTED]
> 
> "It's not easy, being green."
>   -- Kermit the Frog
> 



RE: Set DocumentRoot from modperl

2000-03-28 Thread Michael

> Sergio,
> 
>I just walked this route...
> 
>The long and short is that it can't be done anything close to
>feasably.

There is a work around to this. If you use the syntax


perlcode
perlcode
require 'somefile.cgi';
more perl
more perl

then the cgi script gets imported into the environment and RUN with 
the current document root rather than the one for modperl for the 
whole system. Yeah, it's messy and require was not intended to be 
used quite that way, but it works!

> 
>You'll have to write your own URI Translator and alter some code
>so that
> you can 
>introduce your DOCUMENT_ROOT down the line to things like the
>mod_cgi
> etc.  If you 
>search the mod_perl forum, you'll see some handy code that one of
>the
> gurus 
>around here provided me use the NOTES table.
> 
>BTW, if you're introducing FrontPage to your masses.  You'll have
>to
> re-write your 
>own fpcount.exe.  The codes not available and it's anybody's
>guess where
> the hell 
>it actually gets the document root from (I even encoded it into
>the
> mod_frontpage.c
>module without success) and naturally the source isn't available.
> 
>Have fun.  I did!
> 
> 
> - Best regards,
> 
> Karyn Ulriksen
> Chief Systems Architect
> PublicHost
> 22 Mauchly, Suite 200
> Irvine, California  92618 USA
> Phone: (949) 743-2000
> email: [EMAIL PROTECTED]
> URL:  http://www.publichost.com
> 
> 
> 
> -Original Message-
> From: Serge mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 28, 2000 1:45 PM To: [EMAIL PROTECTED]
> Subject: Set DocumentRoot from modperl
> 
> 
> 
> Hi,
> I am trying to find a way of setting DocumentRoot (and possibly
> Alias) directly from modperl in order to implement dynamically
> generated virtual hosting. The thing is that my virtualhost
> parameters comes from a database and may change anytime (so I can't
> restart Apache in general), so it is difficult to implement with
> Apache virtual host rewrite, mod_rewrite or even  directives
> in httpd.conf. I tried to use subprocess_env to set this variable,
> but it is useful only for cgi-scripts, not perl or C handlers since
> it sets the Environment variable only.
> 
> Is the only solution to rewrite the URI translation phase so it does
> not use DocumentRoot directive??
> 
> -- 
> Serge Barbosa Da Torre-  [EMAIL PROTECTED]
> 
> "It's not easy, being green."
>   -- Kermit the Frog
> 



Re: Set DocumentRoot from modperl

2000-03-28 Thread Rodney Broom \(OE\)

- Original Message -
From: "Serge 


> ...parameters comes from a database
> ...so I can't restart Apache in general

I'll readilly admit that I don't actually know about the specific
performance hits here, but at my last job we did our entire config in Perl.
Yes, we just kicked the server after changes. In fact, the jobs that made
the changes kicked the server them selves.

If you are only having to restart a few times a day, this may be a fast way
to avoid a bunch of devel.

Rodney




RE: Set DocumentRoot from modperl

2000-03-28 Thread Karyn Ulriksen

Sergio,

   I just walked this route...

   The long and short is that it can't be done anything close to feasably.

   You'll have to write your own URI Translator and alter some code so that
you can 
   introduce your DOCUMENT_ROOT down the line to things like the mod_cgi
etc.  If you 
   search the mod_perl forum, you'll see some handy code that one of the
gurus 
   around here provided me use the NOTES table.

   BTW, if you're introducing FrontPage to your masses.  You'll have to
re-write your 
   own fpcount.exe.  The codes not available and it's anybody's guess where
the hell 
   it actually gets the document root from (I even encoded it into the
mod_frontpage.c
   module without success) and naturally the source isn't available.

   Have fun.  I did!

-
Best regards,

Karyn Ulriksen
Chief Systems Architect
PublicHost
22 Mauchly, Suite 200
Irvine, California  92618 USA
Phone: (949) 743-2000
email: [EMAIL PROTECTED]
URL:  http://www.publichost.com



-Original Message-
From: Serge mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 28, 2000 1:45 PM
To: [EMAIL PROTECTED]
Subject: Set DocumentRoot from modperl



Hi,
I am trying to find a way of setting DocumentRoot (and possibly Alias)
directly from modperl in order to implement dynamically generated 
virtual hosting.
The thing is that my virtualhost parameters comes from a database and
may change anytime (so I can't restart Apache in general), so it is 
difficult to implement with Apache virtual host rewrite, mod_rewrite 
or even  directives in httpd.conf.
I tried to use subprocess_env to set this variable, but it is useful
only for cgi-scripts, not perl or C handlers since it sets the Environment
variable only.

Is the only solution to rewrite the URI translation phase so it does not
use DocumentRoot directive??

-- 
Serge Barbosa Da Torre  -  [EMAIL PROTECTED]

"It's not easy, being green."
-- Kermit the Frog