You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Stas Bekman <st...@stason.org> on 2003/12/21 10:36:12 UTC

why open_logs/post_config hooks are run only for the main server?

We have users who want to run different post_config hooks for different 
vhosts. Any chance httpd-2.0 can be changed to run the open_logs/post_config 
(or at least post_config) hooks for each vhost as well? Any reason for not 
doing that in first place?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: why open_logs/post_config hooks are run only for the main server?

Posted by Stas Bekman <st...@stason.org>.
Sander Temme wrote:
>>We have users who want to run different post_config hooks for different
>>vhosts. Any chance httpd-2.0 can be changed to run the open_logs/post_config
>>(or at least post_config) hooks for each vhost as well? Any reason for not
>>doing that in first place?
> 
> 
> You can access your virtual hosts in the post_config hook. Just iterate down
> your server_rec->next list.

Sure, we can do that. I just thought that it's something that everybody may want.

Thanks Sander.


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: why open_logs/post_config hooks are run only for the main server?

Posted by Sander Temme <sc...@covalent.net>.
> We have users who want to run different post_config hooks for different
> vhosts. Any chance httpd-2.0 can be changed to run the open_logs/post_config
> (or at least post_config) hooks for each vhost as well? Any reason for not
> doing that in first place?

You can access your virtual hosts in the post_config hook. Just iterate down
your server_rec->next list.

S.

-- 
Covalent Technologies                 sctemme@covalent.net
Engineering group                    Voice: (415) 856 4214
303 Second Street #375 South           Fax: (415) 856 4210
San Francisco CA 94107

PGP FP: 7A8D B189 E871 80CB 9521  9320 C11E 7B47 964F 31D9

=======================================================
This email message is for the sole use of the intended
recipient(s) and may contain confidential and privileged
information. Any unauthorized review, use, disclosure or
distribution is prohibited.  If you are not the intended
recipient, please contact the sender by reply email and
destroy all copies of the original message
=======================================================


Re: why open_logs/post_config hooks are run only for the main server?

Posted by Stas Bekman <st...@stason.org>.
William A. Rowe, Jr. wrote:
> At 04:47 PM 12/22/2003, Stas Bekman wrote:
> 
> 
>> I'm not sure this is a good idea to run it on the main host. If it was we
>> could just as well run post_config for each vhost as well.
> 
> 
> No, you missed my earlier point.  post_config is a run-once.  host_init is
> the run-each you requested.

but since you can iterate over vhosts from post_config, you don't really need 
a special hook. As if there was one.

>> The problem is that if that hook is configurable via a directive this
>> directive will be inherited by all vhosts if defined in the main server
>> (via the usual merge rules). And you end up running it for each vhost
>> even if you didn't intend to.
> 
> 
> Stop...  hooks aren't configured by directives as you imply.

They are in mod_perl, most of them. So that users can write they own callbacks.

> The directive is processed in some phase, but the hook runs against all.
> That's why we wondered why you couldn't loop it, although I had no
> objection to simply invoking this hook.

I wasn't sure I needed to loop. But now it seems to be a fine idea and no 
extra hook is needed.

> As a matter of fact, you give me an idea I'll discuss at the end.
> 
> As far as inheritance, hosts *should* inherit global settings unless the
> author goes to great pain to *document* and then provide such behavior.
> Intuitively folks presume inheritance within httpd.conf from global into
> each local conf.

That's correct.

>> So if adding this hook at all, it should be invoked *only* on vhosts, and
>> never on the main server [...] and then vhost_init is the right choice.
> 
> 
> No... the default server is still a server.  But you make an interesting
> point, that certain percolation occurs in the post config.  I suppose I
> would want that to happen before my handlers dealt with the per-vhost
> settings, and I would not want the changes I make to that global server to
> percolate any longer in the host_init phase.  So running the post config,
> then the host init phases makes sense for that paradigm.
> 
> If we invoke this hook for vhosts, it must be invoked on the main host.
> 
> What the handlers do should be affected by the per-host directives, and not
>  the other way around (handlers shouldn't be invoked because of per-host 
> directives.)

That's fine. I was talking about a different situation as you may have 
understood from my comments, which is not normal under plain Apache. I'm 
totally fine with the current behavior.

> But let's imagine a scenario of dynamic vhosts, al la htaccess.  It would
> actually be quite cool in one thread to create such a dynamic host
> (propagate from some given vhost for example.)  This host init hook would
> still be run against the thread specific dynamic server record.  We could
> get away with some really cool things that way :)  Discuss ...


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: why open_logs/post_config hooks are run only for the main server?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> No... the default server is still a server.  But you make an interesting point, that
> certain percolation occurs in the post config.  I suppose I would want that to
> happen before my handlers dealt with the per-vhost settings, and I would not
> want the changes I make to that global server to percolate any longer in the
> host_init phase.  So running the post config, then the host init phases makes
> sense for that paradigm.

cool.  just to keep up, new patches attached.

> But let's imagine a scenario of dynamic vhosts, al la htaccess.  It would actually
> be quite cool in one thread to create such a dynamic host (propagate from some
> given vhost for example.)  This host init hook would still be run against the thread
> specific dynamic server record.  We could get away with some really cool things
> that way :)  Discuss ...

you'd need a way to direct requests directly to that specific thread,
though, right?  anyway, what kind of cool things?  I can see some advantage
to this oven in prefork, where you might want to dedicate a pool of children
to specific clients, but I don't really see the threaded advantages.  but I
generally don't get threaded environments anyway :)

--Geoff

Re: why open_logs/post_config hooks are run only for the main server?

Posted by "William A. Rowe, Jr." <wr...@apache.org>.
At 04:47 PM 12/22/2003, Stas Bekman wrote:

>I'm not sure this is a good idea to run it on the main host. If it was we could just as well run post_config for each vhost as well. 

No, you missed my earlier point.  post_config is a run-once.  host_init is the
run-each you requested.

>The problem is that if that hook is configurable via a directive this directive will be inherited by all vhosts if defined in the main server (via the usual merge rules). And you end up running it for each vhost even if you didn't intend to.

Stop...  hooks aren't configured by directives as you imply.

The directive is processed in some phase, but the hook runs against all.  That's
why we wondered why you couldn't loop it, although I had no objection to simply
invoking this hook.

As a matter of fact, you give me an idea I'll discuss at the end.

As far as inheritance, hosts *should* inherit global settings unless the author
goes to great pain to *document* and then provide such behavior.  Intuitively
folks presume inheritance within httpd.conf from global into each local conf.

>So if adding this hook at all, it should be invoked *only* on vhosts, and never on the main server [...] and then vhost_init is the right choice.

No... the default server is still a server.  But you make an interesting point, that
certain percolation occurs in the post config.  I suppose I would want that to
happen before my handlers dealt with the per-vhost settings, and I would not
want the changes I make to that global server to percolate any longer in the
host_init phase.  So running the post config, then the host init phases makes
sense for that paradigm.

If we invoke this hook for vhosts, it must be invoked on the main host.

What the handlers do should be affected by the per-host directives, and not
the other way around (handlers shouldn't be invoked because of per-host
directives.)

But let's imagine a scenario of dynamic vhosts, al la htaccess.  It would actually
be quite cool in one thread to create such a dynamic host (propagate from some
given vhost for example.)  This host init hook would still be run against the thread
specific dynamic server record.  We could get away with some really cool things
that way :)  Discuss ...

Bill 


Re: why open_logs/post_config hooks are run only for the main server?

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> 
> William A. Rowe, Jr. wrote:
> 
>>Only question below is should this hook always run before or after the 
>>post config hook?  My gut says after post config.
> 
> 
> just going from what you had said earlier:
> 
> 
>>It is almost worth a totally different hook entry point (before 
>>post_config) such as vhost_init which *would* be called per-vhost 
>>(starting from the main server config and working through the list.)
> 
> 
> :)
> 
> but now that I think about it, if post_config is where module init stuff
> lives, then it feels right to have vhosts initialized prior to that, since
> the new hook seems like more of a config-type thing.  but it's not hard to
> see how someone could have the opposite viewpoint, so no strong feelings
> here either way.
> 
> the only other (unrelated) thought that I had was that it might be more
> self-documenting to name it host_init rather than vhost_init, keeping it
> very obvious that it runs for the main server as well as any configured vhosts.

I'm not sure this is a good idea to run it on the main host. If it was we 
could just as well run post_config for each vhost as well. The problem is that 
if that hook is configurable via a directive this directive will be inherited 
by all vhosts if defined in the main server (via the usual merge rules). And 
you end up running it for each vhost even if you didn't intend to.

So if adding this hook at all, it should be invoked *only* on vhosts, and 
never on the main server i.e.:

+    for (s = server_conf->next; s; s = s->next) {
               ^^^^^^^^^^^^^^^^^^
+        if ( ap_run_vhost_init(pconf, plog, ptemp, s) != OK) {
+            ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
+                         0, NULL, "Unable to initialize virtual hosts\n");
+            destroy_and_exit_process(process, 1);
+       }
+    }

and then vhost_init is the right choice.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: why open_logs/post_config hooks are run only for the main server?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

William A. Rowe, Jr. wrote:
> Only question below is should this hook always run before or after the 
> post config hook?  My gut says after post config.

just going from what you had said earlier:

> It is almost worth a totally different hook entry point (before 
> post_config) such as vhost_init which *would* be called per-vhost 
> (starting from the main server config and working through the list.)

:)

but now that I think about it, if post_config is where module init stuff
lives, then it feels right to have vhosts initialized prior to that, since
the new hook seems like more of a config-type thing.  but it's not hard to
see how someone could have the opposite viewpoint, so no strong feelings
here either way.

the only other (unrelated) thought that I had was that it might be more
self-documenting to name it host_init rather than vhost_init, keeping it
very obvious that it runs for the main server as well as any configured vhosts.

--Geoff



Re: why open_logs/post_config hooks are run only for the main server?

Posted by "William A. Rowe, Jr." <wr...@apache.org>.
Only question below is should this hook always run before or after the post
config hook?  My gut says after post config.

At 11:19 AM 12/22/2003, Geoff wrote:

>I had some spare time and thought I could help with the grunt work - my try
>at a patch attached.


>+    for (s = server_conf; s; s = s->next) {
>+        if ( ap_run_vhost_init(pconf, plog, ptemp, s) != OK) {
>+            ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
>+                         0, NULL, "Unable to initialize virtual hosts\n");
>+            destroy_and_exit_process(process, 1);
>+       }
>+    }
>+
>     if ( ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
>         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
>                      NULL, "Configuration Failed\n");
>@@ -692,6 +707,14 @@
>             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
>                          0, NULL, "Unable to open logs\n");
>             destroy_and_exit_process(process, 1);
>+        }
>+
>+        for (s = server_conf; s; s = s->next) {
>+            if ( ap_run_vhost_init(pconf, plog, ptemp, s) != OK) {
>+                ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
>+                             0, NULL, "Unable to initialize virtual hosts\n");
>+                destroy_and_exit_process(process, 1);
>+            }
>         }
> 
>         if (ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {


Re: why open_logs/post_config hooks are run only for the main server?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

William A. Rowe, Jr. wrote:

> It is almost worth a totally different hook entry point (before
> post_config) such as vhost_init which *would* be called per-vhost
> (starting from the main server config and working through the list.)
> 
> I have several modules with the for (s=_server; s; s = s->next) paradigm
> that would be easier to read using such a hook.  Although I'm generally
> against adding more cpu-intensive hook phases, this is an init-only hook
> so it's much easier to implement.

I had some spare time and thought I could help with the grunt work - my try
at a patch attached.

HTH

--Geoff

Re: why open_logs/post_config hooks are run only for the main server?

Posted by "William A. Rowe, Jr." <wr...@apache.org>.
At 03:36 AM 12/21/2003, Stas Bekman wrote:
>We have users who want to run different post_config hooks for different vhosts. Any chance httpd-2.0 can be changed to run the open_logs/post_config (or at least post_config) hooks for each vhost as well? Any reason for not doing that in first place?

The issue would be that all modules presume these hooks are called once and
only once, therefore they initialize global structures presuming this entry point
won't be invoked again.

It is almost worth a totally different hook entry point (before post_config) such
as vhost_init which *would* be called per-vhost (starting from the main server
config and working through the list.)

I have several modules with the for (s=_server; s; s = s->next) paradigm that
would be easier to read using such a hook.  Although I'm generally against
adding more cpu-intensive hook phases, this is an init-only hook so it's much
easier to implement.

We might also want to revisit the child_init hook, which is once/process.
Some have asked for a per-thread init hook as well.

Bill