mod_perl and access to the parent processes environment?

mod_perl and access to the parent processes environment?

am 19.07.2006 22:41:16 von Robert Nicholson

So how can I set up the environment prior to launching httpd so that
these values are available in stanza's in httpd.conf?

It doesn't look like this is possible.

It looks like the only thing I can do is say

-Ddefinesomething

and then in httpd.conf

ifdefined definesomething
do something

but I need to do more than this.

I want to be able to pass information from the script that launches
httpd and have that information available within a stanza.

Re: mod_perl and access to the parent processes environment?

am 20.07.2006 02:09:10 von Big and Blue

robert@elastica.com wrote:
> So how can I set up the environment prior to launching httpd so that
> these values are available in stanza's in httpd.conf?

Set an environment variable then access it via %ENV?

> I want to be able to pass information from the script that launches
> httpd and have that information available within a stanza.

You could also, of course, just include a file into httpd.conf which has
the relevant values set. If necessary this included file could be created
with the relevant values added in dynamically by the startup script.



--
Just because I've written it doesn't mean that
either you or I have to believe it.

Re: mod_perl and access to the parent processes environment?

am 20.07.2006 13:23:14 von mumia.w.18.spam+nospam.usenet

On 07/19/2006 07:09 PM, Big and Blue wrote:
> robert@elastica.com wrote:
>> So how can I set up the environment prior to launching
>> httpd so that these values are available in
>> stanza's in httpd.conf?
>
> Set an environment variable then access it via %ENV?
>
>> I want to be able to pass information from the script
>> that launches httpd and have that information available
>> within a stanza.
>
> You could also, of course, just include a file into
> httpd.conf which has the relevant values set. If necessary
> this included file could be created with the relevant
> values added in dynamically by the startup script.
>

That won't work out well because the server would have to be
restarted.

Robert, instead I suggest you modify an .htaccess file
instead. Htaccess files are re-read on each access. However, I
doubt you need to do this. Probably anything you can do in a
section of an Apache config file can also be done in a
custom perl-handler.

HTH

Re: mod_perl and access to the parent processes environment?

am 21.07.2006 01:22:36 von Big and Blue

Mumia W. wrote:
>
> That won't work out well because the server would have to be
> restarted.

The original question was:

>> So how can I set up the environment prior to launching
>> httpd.

"prior to launching" indicates to me that this is a one-off setting at
startup.

--
Just because I've written it doesn't mean that
either you or I have to believe it.

Re: mod_perl and access to the parent processes environment?

am 22.07.2006 08:15:50 von robert.nicholson

Yes the general idea is that I set the environment up with the host
specific info or at the very least hostname of the server i'm starting
and then pull that out of %ENV later. Now I know I can use
getbyhostname in a block but I wanted to know if my
stanza should be able to pull out of %ENV anything that I've
PerlPassEnv'd. Because when I tried this it doesn't work.

Right now I have the startup script process a dictionary and uses
Tempate Toolkit to generate the configuration files upon startup. It's
a very flexible approach but I wanted to know if the above approach was
possible because I wanted another solution instead of relying on
statically generated configuration files.. Strictly speaking they are
dynamic but I was trying to come up with a solution that could reuse
the same httpd.conf across all servers. I just need to have port,
hostname amongst other things. (assume port could vary across servers,
unlikely though)

That said I find a solution where I can pass thru environment vars when
I start httpd and to then evaluate those vars quite simple and elegant
for my needs. Despite the fact that I've invested some time in coding
the existing template based generation approach.

1. I want to setenv VAR some value and I use PerlPassEnv in http.conf
should I then be able to find $VAR in %ENV in any stanza? Or is
PerlPassEnv only used to pass thru variables to perl handlers for
request processing with mod perl?


Big and Blue wrote:
> Mumia W. wrote:
> >
> > That won't work out well because the server would have to be
> > restarted.
>
> The original question was:
>
> >> So how can I set up the environment prior to launching
> >> httpd.
>
> "prior to launching" indicates to me that this is a one-off setting at
> startup.
>
> --
> Just because I've written it doesn't mean that
> either you or I have to believe it.

Re: mod_perl and access to the parent processes environment?

am 23.07.2006 02:31:09 von Big and Blue

robert.nicholson@gmail.com wrote:
>
> Yes the general idea is that I set the environment up with the host
> specific info or at the very least hostname of the server i'm starting
> and then pull that out of %ENV later. Now I know I can use
> getbyhostname in a block but I wanted to know if my
> stanza should be able to pull out of %ENV anything that I've
> PerlPassEnv'd. Because when I tried this it doesn't work.

As I mentioned before, you can always get a script, run at startup, to
do anything you want ie: the startup script does a gethostbyname() call and
writes the result into an Apache config file which you then include into
your static Apache config file. Then you don't need to worry about what is
and is not in %ENV and don't need PerlPassEnv (or PerlSetEnv) statements at all.


--
Just because I've written it doesn't mean that
either you or I have to believe it.

Re: mod_perl and access to the parent processes environment?

am 23.07.2006 03:27:44 von robert.nicholson

Well lets say that you have any number of servers sharing the same set
of files. exception configuration. You still need to know how to
include this host specific file unless you expect it to be only used by
one server at any given time.

Assume ServerRoot is the same for all servers.

Big and Blue wrote:
> robert.nicholson@gmail.com wrote:
> >
> > Yes the general idea is that I set the environment up with the host
> > specific info or at the very least hostname of the server i'm starting
> > and then pull that out of %ENV later. Now I know I can use
> > getbyhostname in a block but I wanted to know if my
> > stanza should be able to pull out of %ENV anything that I've
> > PerlPassEnv'd. Because when I tried this it doesn't work.
>
> As I mentioned before, you can always get a script, run at startup, to
> do anything you want ie: the startup script does a gethostbyname() call and
> writes the result into an Apache config file which you then include into
> your static Apache config file. Then you don't need to worry about what is
> and is not in %ENV and don't need PerlPassEnv (or PerlSetEnv) statements at all.
>
>
> --
> Just because I've written it doesn't mean that
> either you or I have to believe it.

Re: mod_perl and access to the parent processes environment?

am 23.07.2006 07:42:19 von mumia.w.18.spam+nospam.usenet

On 07/22/2006 01:15 AM, robert.nicholson@gmail.com wrote:
> Yes the general idea is that I set the environment up with
> the host specific info or at the very least hostname of the
> server i'm starting and then pull that out of %ENV later.
> Now I know I can use getbyhostname in a block but I
> wanted to know if my stanza should be able to pull
> out of %ENV anything that I've PerlPassEnv'd. Because when
> I tried this it doesn't work.
> [...]

And I didn't work when I tried it. From what I can tell, very
little of the environment is available within sections.
As an alternative, you can probably place your configuration
in an external config file, such as /var/wwwconfig/config.pl.
Then in your section, you could execute it using "do" e.g.:

/var/wwwconfig/config.pl:
$Port = 8080;

/etc/apache2/httpd.conf:
....

do '/var/wwwconfig/config.pl';



HTH

Re: mod_perl and access to the parent processes environment?

am 25.07.2006 01:49:05 von Big and Blue

robert.nicholson@gmail.com wrote:
>
> Well lets say that you have any number of servers sharing the same set
> of files. exception configuration. You still need to know how to
> include this host specific file unless you expect it to be only used by
> one server at any given time.

I'll assume that by "any number of servers" you mean different instances
of httpd running.

That means each of them has a separate startup script somewhere along
the startup path, and that one can create, on the fly, the relevant include
file to be included by a static name. The rest of the config file(s) can
be shared.



--
Just because I've written it doesn't mean that
either you or I have to believe it.