You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Josh Narins <jn...@seniorbridge.com> on 2011/11/18 21:20:23 UTC

Apache2::PerlSections $PerlConfig

perl 5.12.3, httpd-2.2.16, mod_perl 2.0.5, RHEL5

This is part of a project to move a large a large-ish mod_perl application from mod_perl1 to 2. It's about time!

Most of the httpd.conf is read by setting $PerlConfig equal to the output of a HTML::Template in a <Perl> section.

Using a Cleanup handler and Apache2::Directive, I can see that only some PerlPassEnv, PerlOptions => '+GlobalRequest' and the <Perl> section which reads the template are defined, i.e. no locations or directives from the output of the template.

If I cut and paste the output of the template into httpd.conf, things work fine.

I've tried a few things.

my $r = Apache2::RequestUtil->request;
$r->add_config($template->output);

Which gets me

Syntax error on line 66 of /home/web/rosalind-dev9/etc/httpd/httpd.conf:
\t(in cleanup) Global $r object is not available. Set:\n\tPerlOptions +GlobalRequest\nin httpd.conf at /home/web/rosalind-dev9/etc/httpd/httpd.conf line 116.\n

This seems odd to me, because +GlobalRequest is set before the <Perl> section, and is clearly set when I check Apache2::Directive in Cleanup.

And, per this six year old bug report, http://www.gossamer-threads.com/lists/modperl/modperl/88339, I tried a begin block that redefines Apache2::PerlSections's dump_special in conjunction with lines like

@PerlConfig = split /\n/, $template->output;

Printing the contents of $template->output to the error log inside the <Perl> section produces what I expect.

If I simply cut and paste the template output into the httpd.conf, it works fine.

Any suggestions how I can fix this?





Josh Narins
Director of Application Development
SeniorBridge

845 Third Ave
7th Floor
New York, NY 10022
Tel: (212) 994-6194
Fax: (212) 994-4260
Mobile: (917) 488-6248
jnarins@seniorbridge.com
seniorbridge.com<http://www.seniorbridge.com/>

[http://www.seniorbridge.com/images/seniorbridgedisclaimerTAG.gif]


________________________________
SeniorBridge Statement of Confidentiality: The contents of this email message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. Any dissemination, distribution or copying of this email by an unintended or mistaken recipient is strictly prohibited. In said event, kindly reply to the sender and destroy all entries of this message and any attachments from your system. Thank you.

Re: Apache2::PerlSections $PerlConfig

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
On 11-11-21 09:49 , Perrin Harkins wrote:
> On Mon, Nov 21, 2011 at 9:03 AM, Josh Narins <jn...@seniorbridge.com> wrote:
>> So, different ways to get this config to apache include:
>>
>> my $r = Apache2::RequestUtil->request;
>> $r->add_config($template->output);
>>
>> But that results in the error "Global $r object is not available." and the server does not start.
>
> Yes, that's what I was getting at: there's no request during startup
> when your httpd.conf is being processes, so there's no $r object to
> get.
> 
> I don't use this config stuff at all, but looking in the docs I think
> this might work for you:
> 
> use Apache2::ServerUtil ();
> $s = Apache2::ServerUtil->server;
> $s->add_config($config);

You can also use the simpler :

Apache2->httpd_conf("SetEnv foo");

> - Perrin
>> The other two, similar, ways I know about involve $PerlConfig and @PerlConfig, and while neither prevents server startup, Apache2::Directive shows that they didn't do anything, with or without the hack mentioned by Randal here:
>>
>> http://www.gossamer-threads.com/lists/modperl/modperl/85304?do=post_view_threaded#85304
>>
>> And, just so we are all sure, $template->output produces both the content I expect and content that works to start the server. If I simply replace the <Perl> section with the generated output the server starts.

Have you read
<http://perl.apache.org/docs/2.0/api/Apache2/PerlSections.html#C_server_>.
The <Perl> section stuff was re-implemented from scratch between v1 and
v2, so this might be some bug.

Have you tried adding this:

 <Perl>
  print Apache2::PerlSections->dump;
 </Perl>

To the bottom of your httpd.conf, so see what gets dumped ?

Also, it would greatly help if you could post a complete example
httpd.conf (even if simplified) that demonstrates the problem you are
having.

-- 
Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/


Re: Apache2::PerlSections $PerlConfig

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, Nov 21, 2011 at 9:03 AM, Josh Narins <jn...@seniorbridge.com> wrote:
> So, different ways to get this config to apache include:
>
> my $r = Apache2::RequestUtil->request;
> $r->add_config($template->output);
>
> But that results in the error "Global $r object is not available." and the server does not start.

Yes, that's what I was getting at: there's no request during startup
when your httpd.conf is being processes, so there's no $r object to
get.

I don't use this config stuff at all, but looking in the docs I think
this might work for you:

use Apache2::ServerUtil ();
$s = Apache2::ServerUtil->server;
$s->add_config($config);

- Perrin
> The other two, similar, ways I know about involve $PerlConfig and @PerlConfig, and while neither prevents server startup, Apache2::Directive shows that they didn't do anything, with or without the hack mentioned by Randal here:
>
> http://www.gossamer-threads.com/lists/modperl/modperl/85304?do=post_view_threaded#85304
>
> And, just so we are all sure, $template->output produces both the content I expect and content that works to start the server. If I simply replace the <Perl> section with the generated output the server starts.
>
>> I'm not sure I can help with the larger issue since I always stay away
>> from $PerlConfig.  I prefer to generate the entire config file as a
>> template, so that I can use it for the front-end proxy as well.
>
>
>
> Josh Narins
> Director of Application Development
> SeniorBridge
>
> 845 Third Ave
> 7th Floor
> New York, NY 10022
> Tel: (212) 994-6194
> Mobile: (917) 488-6248
> Fax: (212) 994-4260
> jnarins@seniorbridge.com
>
> SeniorBridge
> Managing Complex Chronic Care
> http://www.seniorbridge.com
>
>
>
> SeniorBridge Statement of Confidentiality: The contents of this email message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. Any dissemination, distribution or copying of this email by an unintended or mistaken recipient is strictly prohibited. In said event, kindly reply to the sender and destroy all entries of this message and any attachments from your system. Thank you.
>

RE: Apache2::PerlSections $PerlConfig

Posted by Josh Narins <jn...@seniorbridge.com>.
> From: pharkins@gmail.com [mailto:pharkins@gmail.com] On Behalf Of
> Perrin Harkins
> Sent: Friday, November 18, 2011 5:57 PM
> To: Josh Narins
>
> On Fri, Nov 18, 2011 at 5:27 PM, Josh Narins <jn...@seniorbridge.com>
> wrote:
> > Thanks, Perrin, but the server isn't starting when I get this error.
>
> It's not?  You can't define Location blocks and the like after the
> server has started.  Maybe I'm not understanding what you're saying.

My httpd.conf has three sections. One is LoadModule perl_module modules/mod_perl.so and PerlOptions +GlobalRequest. Another is a block of PerlPassEnv, and third is a <Perl> section. The main part of the <Perl> section is to create and then get the output of an HTML::Template, which includes all the other httpd configuration, like <Locations>, rewrites, et cetera.

So, different ways to get this config to apache include:

my $r = Apache2::RequestUtil->request;
$r->add_config($template->output);

But that results in the error "Global $r object is not available." and the server does not start.

The other two, similar, ways I know about involve $PerlConfig and @PerlConfig, and while neither prevents server startup, Apache2::Directive shows that they didn't do anything, with or without the hack mentioned by Randal here:

http://www.gossamer-threads.com/lists/modperl/modperl/85304?do=post_view_threaded#85304

And, just so we are all sure, $template->output produces both the content I expect and content that works to start the server. If I simply replace the <Perl> section with the generated output the server starts.

> I'm not sure I can help with the larger issue since I always stay away
> from $PerlConfig.  I prefer to generate the entire config file as a
> template, so that I can use it for the front-end proxy as well.



Josh Narins
Director of Application Development
SeniorBridge

845 Third Ave
7th Floor
New York, NY 10022
Tel: (212) 994-6194
Mobile: (917) 488-6248
Fax: (212) 994-4260
jnarins@seniorbridge.com

SeniorBridge
Managing Complex Chronic Care
http://www.seniorbridge.com



SeniorBridge Statement of Confidentiality: The contents of this email message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. Any dissemination, distribution or copying of this email by an unintended or mistaken recipient is strictly prohibited. In said event, kindly reply to the sender and destroy all entries of this message and any attachments from your system. Thank you.

Re: Apache2::PerlSections $PerlConfig

Posted by Perrin Harkins <pe...@elem.com>.
On Fri, Nov 18, 2011 at 5:27 PM, Josh Narins <jn...@seniorbridge.com> wrote:
> Thanks, Perrin, but the server isn't starting when I get this error.

It's not?  You can't define Location blocks and the like after the
server has started.  Maybe I'm not understanding what you're saying.

I'm not sure I can help with the larger issue since I always stay away
from $PerlConfig.  I prefer to generate the entire config file as a
template, so that I can use it for the front-end proxy as well.

- Perrin

RE: Apache2::PerlSections $PerlConfig

Posted by Josh Narins <jn...@seniorbridge.com>.
> From: pharkins@gmail.com [mailto:pharkins@gmail.com] On Behalf Of Perrin Harkins
> Sent: Friday, November 18, 2011 3:41 PM
>
>> On Fri, Nov 18, 2011 at 3:20 PM, Josh Narins <jn...@seniorbridge.com> wrote:
>> my $r = Apache2::RequestUtil->request;
>> $r->add_config($template->output);
>>
>>Which gets me
>>
>> Syntax error on line 66 of /home/web/rosalind-dev9/etc/httpd/httpd.conf:
\t(in cleanup) Global $r object is not available. Set:\n\tPerlOptions +GlobalRequest\nin httpd.conf at /home/web/rosalind-dev9/etc/httpd/httpd.conf line 116.\n
>>
>> This seems odd to me, because +GlobalRequest is set before the <Perl> section, and is clearly set when I check Apache2::Directive in Cleanup.
>
> This is in your conf file, right?  There's no request yet.  I think it's just a confusing error message.
>

Thanks, Perrin, but the server isn't starting when I get this error.



I've used strace a bit, not sure this will help, but here it is.

httpd-tmpl-custom.conf is the local include file for the template, the last part of the template file. Setting $PerlConfig = $template->output is the last line of the <Perl> section.

stat("[...]/etc/httpd/httpd-tmpl-custom.conf", {st_mode=S_IFREG|0600, st_size=344, ...}) = 0
open("[...]/etc/httpd/httpd-tmpl-custom.conf", O_RDONLY) = 4
ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff28a46020) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(4, 0, SEEK_CUR)                   = 0
fstat(4, {st_mode=S_IFREG|0600, st_size=344, ...}) = 0
fcntl(4, F_SETFD, FD_CLOEXEC)           = 0
fstat(4, {st_mode=S_IFREG|0600, st_size=344, ...}) = 0
read(4, "# dev3.yaml\n#\n# Apache/mod_perl "..., 4096) = 344
read(4, "", 4096)                       = 0
fstat(4, {st_mode=S_IFREG|0600, st_size=344, ...}) = 0
close(4)                                = 0
write(2, "Syntax error on line 66 of /home"..., 73Syntax error on line 66 of /home/web/rosalind-dev9/etc/httpd/httpd.conf:
) = 73
write(2, "\\t(in cleanup) Global $r object "..., 160\t(in cleanup) Global $r object is not available. Set:\n\tPerlOptions +GlobalRequest\nin httpd.conf at /home/web/rosalind-dev9/etc/httpd/httpd.conf line 117.\n
) = 160
select(0, NULL, NULL, NULL, {0, 10000}) = 0 (Timeout)
brk(0x1f5.....) = 0x1f5 (4 times)
munmap(0x...., .....)         = 0 (14 times)
exit_group(1)                           = ?


Josh Narins
Director of Application Development
SeniorBridge

845 Third Ave
7th Floor
New York, NY 10022
Tel: (212) 994-6194
Mobile: (917) 488-6248
Fax: (212) 994-4260
jnarins@seniorbridge.com

SeniorBridge
Managing Complex Chronic Care
http://www.seniorbridge.com



SeniorBridge Statement of Confidentiality: The contents of this email message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. Any dissemination, distribution or copying of this email by an unintended or mistaken recipient is strictly prohibited. In said event, kindly reply to the sender and destroy all entries of this message and any attachments from your system. Thank you.

Re: Apache2::PerlSections $PerlConfig

Posted by Perrin Harkins <pe...@elem.com>.
On Fri, Nov 18, 2011 at 3:20 PM, Josh Narins <jn...@seniorbridge.com>wrote:

> my $r = Apache2::RequestUtil->request;****
>
> $r->add_config($template->output);****
>
> ** **
>
> Which gets me****
>
> ** **
>
> Syntax error on line 66 of /home/web/rosalind-dev9/etc/httpd/httpd.conf:**
> **
>
> \t(in cleanup) Global $r object is not available. Set:\n\tPerlOptions
> +GlobalRequest\nin httpd.conf at
> /home/web/rosalind-dev9/etc/httpd/httpd.conf line 116.\n****
>
> ** **
>
> This seems odd to me, because +GlobalRequest is set before the <Perl>
> section, and is clearly set when I check Apache2::Directive in Cleanup.
>

This is in your conf file, right?  There's no request yet.  I think it's
just a confusing error message.

- Perrin