You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Elizabeth Mattijsen <li...@dijkmat.nl> on 2004/01/26 01:10:39 UTC

[MP2] Setting up seperate logs for virtual hosts from a database

I have the configuration of a number of virtual hosts in a database. 
Only those virtual hosts are handled by the Apache 2 server. 
Basically, all requests are handled by the same Perl code.  And 
everything is set up from a PerlRequire file.

This is all fine and dandy, but I would like each virtual host to 
have its own access and error log.  And I'm lost in the MP2 
documentation on how to do that from the PerlRequire file.  There is 
some documentation about such a feature in Apache::PerlSections, but 
I'd rather not use Perl sections in the httpd.conf (and I'm also not 
seeing how I could use a single <Perl> section for multiple 
VirtualHosts, but then I may be a bit dense after a long day ;-).


Confused and in appreciation of anyone who could give some clarity.


Liz

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Stas Bekman <st...@stason.org>.
Elizabeth Mattijsen wrote:
> At 13:55 -0800 1/26/04, Stas Bekman wrote:
> 
>> You don't need the loop, I was talking about adding directives to an 
>> already existing vhosts.
>>
>> Just do at startup.pl or <Perl> sections:
>>
>> my $config = get_my_httpd_conf_config();
>> $s->add_config([split /\n/, $config]);
>>
>> get_my_httpd_conf_config() should return the config section as if you 
>> have written it in httpd.conf.
> 
> 
> Hmmm... I'm having trouble getting at the $s:
> 
> use Apache2 ();
> use Apache::Server ();
> my $server = Apache->server;
> __END__
> Can't locate object method "server" via package "Apache" line 3.
> 
> 
> Whereas http://perl.apache.org/docs/2.0/api/Apache.html states:
> 
> There are several modules that require the Apache class as the first 
> argument to the class methods that they define. For example 
> Apache::Server defines a class method Apache->server :
>   use Apache::Server;
>   my $server = Apache->server;


% lookup server
There is more than one class with method 'server'
try one of:
         use Apache::RequestRec ();
         use Apache::CmdParms ();
         use Apache::ServerUtil ();


You need to load 'Apache::ServerUtil'. As you know from the dev list thread, 
we are trying to make things DWIM'ish, so I won't mess with docs till we get 
it all the API changes finalized.


__________________________________________________________________
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


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Elizabeth Mattijsen <li...@dijkmat.nl>.
At 13:55 -0800 1/26/04, Stas Bekman wrote:
>You don't need the loop, I was talking about adding directives to an 
>already existing vhosts.
>
>Just do at startup.pl or <Perl> sections:
>
>my $config = get_my_httpd_conf_config();
>$s->add_config([split /\n/, $config]);
>
>get_my_httpd_conf_config() should return the config section as if 
>you have written it in httpd.conf.

Hmmm... I'm having trouble getting at the $s:

use Apache2 ();
use Apache::Server ();
my $server = Apache->server;
__END__
Can't locate object method "server" via package "Apache" line 3.


Whereas http://perl.apache.org/docs/2.0/api/Apache.html states:

There are several modules that require the Apache class as the first 
argument to the class methods that they define. For example 
Apache::Server defines a class method Apache->server :
   use Apache::Server;
   my $server = Apache->server;


Liz

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Stas Bekman <st...@stason.org>.
Elizabeth Mattijsen wrote:
> At 11:42 -0800 1/26/04, Stas Bekman wrote:
> 
>> Elizabeth Mattijsen wrote:
>>
>>> Well, the error log wouldn't be such a problem.  There is an 
>>> advantage to getting all of the errors in one place.  But the access 
>>> logs, now that would be nice...  ;-)
>>
>> At the moment you can try to traverse the servers chaing using the 
>> following idiom:
>>  my $s = Apache->server;
>>  for (;$s;$s=$s->next) {
>>    $s->add_config([....]);
>>  }
>> that gives you an access to each of the vhosts (that were configured 
>> so far), so you probably want to run this once you've added all your 
>> vhosts. Also you will have to figure out who is who, with some extra 
>> calls on $s.
> 
> 
> But that's just it.  I _don't_ have any vhosts in the config.
> 
> What I basically have is a single database that is used to build 30+ 
> different websites (mostly realtime, with some caching), each giving a 
> different view on the information in the database.  Some have all, most 
> others are limited in their view of the database.  And of course, there 
> is one such website that's actually the CMS of the database.
> 
> On server startup, the database is read and and the hostnames of 30+ 
> different sites come out (all winding up on the same IP-address). 
> Nothing about that in the config file.
> 
> Now, I really wouldn't need virtual hosts except for the fact that I 
> want to have (at least) seperate access logs for each of these 30+ 
> different sites.  The only way I figured I'd be able to do that, was by 
> creating basically dummy virtual hosts of which the only information in 
> there would be the specification of the seperate access (and possibly 
> error) log.

Argh! I misunderstood your request then :( So what Geoff said is all you need, 
I thought you already had the vhosts configured and wanted to add log files 
later on.

>> But I think we should figure out how to fix it to do the right thing, 
>> stay tuned at the dev list. See:
>> http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=107476838714506&w=2
> 
> 
> Can I add vhosts with $s->add_config?  Something like:
> 
>   $s->add_config( "VirtualHost foo.com:80" );
>   $s->add_config( "VirtualHost bar.com:80" );
> 
>  and then do the loop with $s->next?  Or am I now stretching the API 
> beyond to what was intended?

You don't need the loop, I was talking about adding directives to an already 
existing vhosts.

Just do at startup.pl or <Perl> sections:

my $config = get_my_httpd_conf_config();
$s->add_config([split /\n/, $config]);

get_my_httpd_conf_config() should return the config section as if you have 
written it in httpd.conf.

__________________________________________________________________
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


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Elizabeth Mattijsen <li...@dijkmat.nl>.
At 15:36 -0800 1/27/04, Stas Bekman wrote:
>Egor Shipovalov wrote:
>>>Can I add vhosts with $s->add_config?  Something like:
>>>
>>>   $s->add_config( "VirtualHost foo.com:80" );
>>>   $s->add_config( "VirtualHost bar.com:80" );
>>>
>>>  and then do the loop with $s->next?  Or am I now stretching the 
>>>API beyond to what was intended?
>>
>>
>>I once was in your position and found httpd_conf a lot more convenient than
>>add_config. Just feed it the text you would normally write in httpd.conf:
>>
>>foreach my $vhost (@vhosts) {
>>  $s->httpd_conf(<<EOT
>>   <VirtualHost $vhost{name}:80>
>>    ErrorLog /var/log/httpd/$vhost{name}/error.log
>>    ...usual config stuff here...   </VirtualHost>
>>EOT
>>  );
>>}
>
>$s->httpd_conf is not a mp2 API, you can use it only with Apache::compat.

Aha... well, after it didn't work right away, and add_config _did_ 
seem to work, I just didn't look any further.  A wrapper routine is 
easily written.

In any case, I have now resorted to changing the actual config file 
before actually starting with a wrapper around apachectl.  Too many 
odd things were happening and I don't have the time to look at them 
now...  ;-(


>Though I agree that requiring \@lines and not allowing $lines ala 
>mp1's httpd_conf is silly, and we should support both.

Indeed...  ;-)


Liz

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Stas Bekman <st...@stason.org>.
Egor Shipovalov wrote:
>>Can I add vhosts with $s->add_config?  Something like:
>>
>>   $s->add_config( "VirtualHost foo.com:80" );
>>   $s->add_config( "VirtualHost bar.com:80" );
>>
>>  and then do the loop with $s->next?  Or am I now stretching the API 
>>beyond to what was intended?
> 
> 
> I once was in your position and found httpd_conf a lot more convenient than
> add_config. Just feed it the text you would normally write in httpd.conf:
> 
> foreach my $vhost (@vhosts) {
>  $s->httpd_conf(<<EOT
>   <VirtualHost $vhost{name}:80>
>    ErrorLog /var/log/httpd/$vhost{name}/error.log
>    ...usual config stuff here... 
>   </VirtualHost>
> EOT
>  );
> }

$s->httpd_conf is not a mp2 API, you can use it only with Apache::compat.

Though I agree that requiring \@lines and not allowing $lines ala mp1's 
httpd_conf is silly, and we should support both.

__________________________________________________________________
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

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


RE: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Egor Shipovalov <mo...@eonline.ru>.
> Can I add vhosts with $s->add_config?  Something like:
> 
>    $s->add_config( "VirtualHost foo.com:80" );
>    $s->add_config( "VirtualHost bar.com:80" );
> 
>   and then do the loop with $s->next?  Or am I now stretching the API 
> beyond to what was intended?

I once was in your position and found httpd_conf a lot more convenient than
add_config. Just feed it the text you would normally write in httpd.conf:

foreach my $vhost (@vhosts) {
 $s->httpd_conf(<<EOT
  <VirtualHost $vhost{name}:80>
   ErrorLog /var/log/httpd/$vhost{name}/error.log
   ...usual config stuff here... 
  </VirtualHost>
EOT
 );
}

Best regards,
Egor Shipovalov.


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Elizabeth Mattijsen <li...@dijkmat.nl>.
At 11:42 -0800 1/26/04, Stas Bekman wrote:
>Elizabeth Mattijsen wrote:
>>Well, the error log wouldn't be such a problem.  There is an 
>>advantage to getting all of the errors in one place.  But the 
>>access logs, now that would be nice...  ;-)
>At the moment you can try to traverse the servers chaing using the 
>following idiom:
>  my $s = Apache->server;
>  for (;$s;$s=$s->next) {
>    $s->add_config([....]);
>  }
>that gives you an access to each of the vhosts (that were configured 
>so far), so you probably want to run this once you've added all your 
>vhosts. Also you will have to figure out who is who, with some extra 
>calls on $s.

But that's just it.  I _don't_ have any vhosts in the config.

What I basically have is a single database that is used to build 30+ 
different websites (mostly realtime, with some caching), each giving 
a different view on the information in the database.  Some have all, 
most others are limited in their view of the database.  And of 
course, there is one such website that's actually the CMS of the 
database.

On server startup, the database is read and and the hostnames of 30+ 
different sites come out (all winding up on the same IP-address). 
Nothing about that in the config file.

Now, I really wouldn't need virtual hosts except for the fact that I 
want to have (at least) seperate access logs for each of these 30+ 
different sites.  The only way I figured I'd be able to do that, was 
by creating basically dummy virtual hosts of which the only 
information in there would be the specification of the seperate 
access (and possibly error) log.


>But I think we should figure out how to fix it to do the right 
>thing, stay tuned at the dev list. See:
>http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=107476838714506&w=2

Can I add vhosts with $s->add_config?  Something like:

   $s->add_config( "VirtualHost foo.com:80" );
   $s->add_config( "VirtualHost bar.com:80" );

  and then do the loop with $s->next?  Or am I now stretching the API 
beyond to what was intended?


Liz

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Stas Bekman <st...@stason.org>.
Elizabeth Mattijsen wrote:
> At 11:07 -0800 1/26/04, Stas Bekman wrote:
> 
>> Geoffrey Young wrote:
>>
>>> Elizabeth Mattijsen wrote:
>>>
>>>> I have the configuration of a number of virtual hosts in a database.
>>>> Only those virtual hosts are handled by the Apache 2 server. Basically,
>>>> all requests are handled by the same Perl code.  And everything is set
>>>> up from a PerlRequire file.
>>>>
>>>> This is all fine and dandy, but I would like each virtual host to have
>>>> its own access and error log.  And I'm lost in the MP2 documentation on
>>>> how to do that from the PerlRequire file.  There is some documentation
>>>> about such a feature in Apache::PerlSections, but I'd rather not use
>>>> Perl sections in the httpd.conf
>>
>> I think even if you will have a separate error log files, most things 
>> will still be logged into the main error log, unless you log things 
>> explicitly via $r or $s objects. (i.e. plain perl calls like 
>> warn/die/etc. will not know where the vhost error_log is)
> 
> 
> Well, the error log wouldn't be such a problem.  There is an advantage 
> to getting all of the errors in one place.  But the access logs, now 
> that would be nice...  ;-)

At the moment you can try to traverse the servers chaing using the following 
idiom:

  my $s = Apache->server;
  for (;$s;$s=$s->next) {
    $s->add_config([....]);
  }

that gives you an access to each of the vhosts (that were configured so far), 
so you probably want to run this once you've added all your vhosts. Also you 
will have to figure out who is who, with some extra calls on $s.

But I think we should figure out how to fix it to do the right thing, stay 
tuned at the dev list. See:
http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=107476838714506&w=2

__________________________________________________________________
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


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Elizabeth Mattijsen <li...@dijkmat.nl>.
At 11:07 -0800 1/26/04, Stas Bekman wrote:
>Geoffrey Young wrote:
>>Elizabeth Mattijsen wrote:
>>>I have the configuration of a number of virtual hosts in a database.
>>>Only those virtual hosts are handled by the Apache 2 server. Basically,
>>>all requests are handled by the same Perl code.  And everything is set
>>>up from a PerlRequire file.
>>>
>>>This is all fine and dandy, but I would like each virtual host to have
>>>its own access and error log.  And I'm lost in the MP2 documentation on
>>>how to do that from the PerlRequire file.  There is some documentation
>>>about such a feature in Apache::PerlSections, but I'd rather not use
>>>Perl sections in the httpd.conf
>I think even if you will have a separate error log files, most 
>things will still be logged into the main error log, unless you log 
>things explicitly via $r or $s objects. (i.e. plain perl calls like 
>warn/die/etc. will not know where the vhost error_log is)

Well, the error log wouldn't be such a problem.  There is an 
advantage to getting all of the errors in one place.  But the access 
logs, now that would be nice...  ;-)


>>try $s->add_config - it injects configurations right into the server (in
>>.htaccess-like fashion, with the same protections).  be sure to check the
>>return value unless you're using current CVS.
>That won't work at the server startup. Your $s acquired via 
>Apache->server is the base server. I've raised this issue on the dev 
>list, awaiting your comments. That issue also relates to the problem 
>I've mentioned above.

If necessary, I will just have to add a step that would generate the 
config file from the database seperately (e.g. by hacking 
bin/apachectl) before starting the actual apache process.  But that 
would be very hackish... ;-)


Liz

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> 
> Elizabeth Mattijsen wrote:
> 
>>I have the configuration of a number of virtual hosts in a database.
>>Only those virtual hosts are handled by the Apache 2 server. Basically,
>>all requests are handled by the same Perl code.  And everything is set
>>up from a PerlRequire file.
>>
>>This is all fine and dandy, but I would like each virtual host to have
>>its own access and error log.  And I'm lost in the MP2 documentation on
>>how to do that from the PerlRequire file.  There is some documentation
>>about such a feature in Apache::PerlSections, but I'd rather not use
>>Perl sections in the httpd.conf

I think even if you will have a separate error log files, most things will 
still be logged into the main error log, unless you log things explicitly via 
$r or $s objects. (i.e. plain perl calls like warn/die/etc. will not know 
where the vhost error_log is)

> try $s->add_config - it injects configurations right into the server (in
> .htaccess-like fashion, with the same protections).  be sure to check the
> return value unless you're using current CVS.

That won't work at the server startup. Your $s acquired via Apache->server is 
the base server. I've raised this issue on the dev list, awaiting your 
comments. That issue also relates to the problem I've mentioned above.

__________________________________________________________________
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


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [MP2] Setting up seperate logs for virtual hosts from a database

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

Elizabeth Mattijsen wrote:
> I have the configuration of a number of virtual hosts in a database.
> Only those virtual hosts are handled by the Apache 2 server. Basically,
> all requests are handled by the same Perl code.  And everything is set
> up from a PerlRequire file.
> 
> This is all fine and dandy, but I would like each virtual host to have
> its own access and error log.  And I'm lost in the MP2 documentation on
> how to do that from the PerlRequire file.  There is some documentation
> about such a feature in Apache::PerlSections, but I'd rather not use
> Perl sections in the httpd.conf

try $s->add_config - it injects configurations right into the server (in
.htaccess-like fashion, with the same protections).  be sure to check the
return value unless you're using current CVS.

> (and I'm also not seeing how I could use
> a single <Perl> section for multiple VirtualHosts, but then I may be a
> bit dense after a long day ;-).

see Tie::DxHash - it lets you preserve order _and_ multiple keys in hashes,
which is just what you need here.

> 
> 
> Confused and in appreciation of anyone who could give some clarity.

HTH :)

--Geoff


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html