You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Krist van Besien <kr...@gmail.com> on 2006/08/18 12:20:19 UTC
Using "switch" in section.
Hello,
this is my first post to the mod_perl mailing list. I have been using
mod_perl for about a week now. I do however have quite a few years
Perl scripting experience.
What I am trying to do is: Make one httpd.conf that will be suitable
for all of our servers. We have about 20 (and growing) apache servers.
Their role can be terermined from their hostname, so mod_perl's <Perl>
sections seem especially well suited to do this.
Currently I have the following section in my httpd.conf:
526 <Perl>
527
528 # We get the hostname, and use it to:
529 # generate a PID file name
530 # generate log file names
531 # include a hostname dependent include file
532
533 use Sys::Hostname;
534 use Apache2::ServerRec;
535 use Apache2::ServerUtil;
536 use Switch;
537 my $VFL_hostname = hostname();
538 my $VFL_servertype = "";
539 $ServerName = $VFL_hostname;
540
541 $PidFile = "logs/$ServerName.pid";
542 $ServerName .= ".swisptt.ch";
543 print STDERR "ServerName = $ServerName\n";
544
545 switch ($VFL_hostname) {
546 case "mstvflfewprp2v" {
547 $VFL_servertype = "sony" ;
548 }
549 case /ms.vflfe(.*).v/ {
550 $VFL_servertype = $1;
551 }
552 else {
553 $VFL_servertype = "default";
554 }
555 }
556
557 my $VFL_include = "conf/$VFL_servertype.inc" ;
558 print STDERR "Including $VFL_include\n" ;
559 $Include = $VFL_include ;
560
561 $CustomLog = "logs/$VFL_hostname/access_log vfl" ;
562 $ErrorLog = "logs/$VFL_hostname/error_log" ;
563
564 my $VFL_serverroot = Apache2::ServerUtil::server_root() ;
565
566 unless ( -d "$VFL_serverroot/logs/$VFL_hostname" ) {
567 mkdir "$VFL_serverroot/logs/$VFL_hostname", 0755;
568 }
569
570 </Perl>
My problem: When I run apachectl test I get the following error:
String found where operator expected at
/opt/portal/webserver/conf/httpd.conf line 546, near "case
"mstvflfewprp2v""
(Do you need to predeclare case?)
Syntax error on line 527 of /opt/portal/webserver/conf/httpd.conf:
syntax error at /opt/portal/webserver/conf/httpd.conf line 545, near ") {"\n
And after staring at my code for hours I still can't find out what
might be the syntas errors...
- Perl version used is 5.8.5. I checked the contents of the @INC
variable (by adding a print STDERR @INC" statement in a seperate perl
section, and found out that on of the directories searched does
contains the switch.pm module.
I alos tested this piece of code by puting it in a small perl script,
and there it compiles just fine. But as part of a Perl section it does
not work. Why?
--
krist.vanbesien@gmail.com
Bremgarten b. Bern, Switzerland
Re: Using "switch" in section.
Posted by Malcolm J Harwood <mj...@liminalflux.net>.
On Friday 18 August 2006 08:17 am, Elizabeth Mattijsen wrote:
> Source filters don't work in mod_perl. Period.
That's not entirely true. I use Data::Dumper::Simple which is a source filter
and don't have any problems with it. It might not be recommended, but it's
not an absolute "will not work".
Now whether they work in <perl> sections in httpd.conf I couldn't say, not
having tried that.
--
"Let's just say that if complete and utter chaos was lightning, he'd
be the sort to stand on a hilltop in a thunderstorm wearing wet copper
armour and shouting 'All gods are bastards'."
-- Rincewind about Twoflower, The Colour of Magic
Re: Using "switch" in section.
Posted by Elizabeth Mattijsen <li...@dijkmat.nl>.
Source filters don't work in mod_perl. Period.
Because source filters don't work in string evals, and that's what
mod_perl is basically doing everywhere.
Liz
==================================================
At 1:15 PM +0200 8/18/06, Hendrik Van Belleghem wrote:
>Switch is a source filter, which basically means that the module will
>read the script source file and change it before executing. Switch
>will transform those 'case' statements into a bunch of elsif blocks. I
>assume Switch will have a hard time interpreting the httpd.conf file.
>I'm not sure how mod_perl handles the inline-perl-in-httpd.conf
>feature but I guess it'll be tricky. My 0.02 eurocents.
>
>HTH
>
>Kind regards
>
>Hendrik
>
>On 8/18/06, Krist van Besien <kr...@gmail.com> wrote:
>>Hello,
>>
>>this is my first post to the mod_perl mailing list. I have been using
>>mod_perl for about a week now. I do however have quite a few years
>>Perl scripting experience.
>>
>>What I am trying to do is: Make one httpd.conf that will be suitable
>>for all of our servers. We have about 20 (and growing) apache servers.
>>Their role can be terermined from their hostname, so mod_perl's <Perl>
>>sections seem especially well suited to do this.
>>
>>Currently I have the following section in my httpd.conf:
>>
>> 526 <Perl>
>> 527
>> 528 # We get the hostname, and use it to:
>> 529 # generate a PID file name
>> 530 # generate log file names
>> 531 # include a hostname dependent include file
>> 532
>> 533 use Sys::Hostname;
>> 534 use Apache2::ServerRec;
>> 535 use Apache2::ServerUtil;
>> 536 use Switch;
>> 537 my $VFL_hostname = hostname();
>> 538 my $VFL_servertype = "";
>> 539 $ServerName = $VFL_hostname;
>> 540
>> 541 $PidFile = "logs/$ServerName.pid";
>> 542 $ServerName .= ".swisptt.ch";
>> 543 print STDERR "ServerName = $ServerName\n";
>> 544
>> 545 switch ($VFL_hostname) {
>> 546 case "mstvflfewprp2v" {
>> 547 $VFL_servertype = "sony" ;
>> 548 }
>> 549 case /ms.vflfe(.*).v/ {
>> 550 $VFL_servertype = $1;
>> 551 }
>> 552 else {
>> 553 $VFL_servertype = "default";
>> 554 }
>> 555 }
>> 556
>> 557 my $VFL_include = "conf/$VFL_servertype.inc" ;
>> 558 print STDERR "Including $VFL_include\n" ;
>> 559 $Include = $VFL_include ;
>> 560
>> 561 $CustomLog = "logs/$VFL_hostname/access_log vfl" ;
>> 562 $ErrorLog = "logs/$VFL_hostname/error_log" ;
>> 563
>> 564 my $VFL_serverroot = Apache2::ServerUtil::server_root() ;
>> 565
>> 566 unless ( -d "$VFL_serverroot/logs/$VFL_hostname" ) {
>> 567 mkdir "$VFL_serverroot/logs/$VFL_hostname", 0755;
>> 568 }
>> 569
>> 570 </Perl>
>>
>>My problem: When I run apachectl test I get the following error:
>>
>>String found where operator expected at
>>/opt/portal/webserver/conf/httpd.conf line 546, near "case
>>"mstvflfewprp2v""
>> (Do you need to predeclare case?)
>>Syntax error on line 527 of /opt/portal/webserver/conf/httpd.conf:
>>syntax error at /opt/portal/webserver/conf/httpd.conf line 545, near ") {"\n
>>
>>And after staring at my code for hours I still can't find out what
>>might be the syntas errors...
>>
>>- Perl version used is 5.8.5. I checked the contents of the @INC
>>variable (by adding a print STDERR @INC" statement in a seperate perl
>>section, and found out that on of the directories searched does
>>contains the switch.pm module.
>>
>>I alos tested this piece of code by puting it in a small perl script,
>>and there it compiles just fine. But as part of a Perl section it does
>>not work. Why?
>>
>>--
>>krist.vanbesien@gmail.com
>>Bremgarten b. Bern, Switzerland
>>
>
>
>--
>Hendrik Van Belleghem
>Spine - The backbone for your website - http://spine.sf.net
Re: Using "switch" in section.
Posted by Hendrik Van Belleghem <he...@gmail.com>.
Hey,
Switch is a source filter, which basically means that the module will
read the script source file and change it before executing. Switch
will transform those 'case' statements into a bunch of elsif blocks. I
assume Switch will have a hard time interpreting the httpd.conf file.
I'm not sure how mod_perl handles the inline-perl-in-httpd.conf
feature but I guess it'll be tricky. My 0.02 eurocents.
HTH
Kind regards
Hendrik
On 8/18/06, Krist van Besien <kr...@gmail.com> wrote:
> Hello,
>
> this is my first post to the mod_perl mailing list. I have been using
> mod_perl for about a week now. I do however have quite a few years
> Perl scripting experience.
>
> What I am trying to do is: Make one httpd.conf that will be suitable
> for all of our servers. We have about 20 (and growing) apache servers.
> Their role can be terermined from their hostname, so mod_perl's <Perl>
> sections seem especially well suited to do this.
>
> Currently I have the following section in my httpd.conf:
>
> 526 <Perl>
> 527
> 528 # We get the hostname, and use it to:
> 529 # generate a PID file name
> 530 # generate log file names
> 531 # include a hostname dependent include file
> 532
> 533 use Sys::Hostname;
> 534 use Apache2::ServerRec;
> 535 use Apache2::ServerUtil;
> 536 use Switch;
> 537 my $VFL_hostname = hostname();
> 538 my $VFL_servertype = "";
> 539 $ServerName = $VFL_hostname;
> 540
> 541 $PidFile = "logs/$ServerName.pid";
> 542 $ServerName .= ".swisptt.ch";
> 543 print STDERR "ServerName = $ServerName\n";
> 544
> 545 switch ($VFL_hostname) {
> 546 case "mstvflfewprp2v" {
> 547 $VFL_servertype = "sony" ;
> 548 }
> 549 case /ms.vflfe(.*).v/ {
> 550 $VFL_servertype = $1;
> 551 }
> 552 else {
> 553 $VFL_servertype = "default";
> 554 }
> 555 }
> 556
> 557 my $VFL_include = "conf/$VFL_servertype.inc" ;
> 558 print STDERR "Including $VFL_include\n" ;
> 559 $Include = $VFL_include ;
> 560
> 561 $CustomLog = "logs/$VFL_hostname/access_log vfl" ;
> 562 $ErrorLog = "logs/$VFL_hostname/error_log" ;
> 563
> 564 my $VFL_serverroot = Apache2::ServerUtil::server_root() ;
> 565
> 566 unless ( -d "$VFL_serverroot/logs/$VFL_hostname" ) {
> 567 mkdir "$VFL_serverroot/logs/$VFL_hostname", 0755;
> 568 }
> 569
> 570 </Perl>
>
> My problem: When I run apachectl test I get the following error:
>
> String found where operator expected at
> /opt/portal/webserver/conf/httpd.conf line 546, near "case
> "mstvflfewprp2v""
> (Do you need to predeclare case?)
> Syntax error on line 527 of /opt/portal/webserver/conf/httpd.conf:
> syntax error at /opt/portal/webserver/conf/httpd.conf line 545, near ") {"\n
>
> And after staring at my code for hours I still can't find out what
> might be the syntas errors...
>
> - Perl version used is 5.8.5. I checked the contents of the @INC
> variable (by adding a print STDERR @INC" statement in a seperate perl
> section, and found out that on of the directories searched does
> contains the switch.pm module.
>
> I alos tested this piece of code by puting it in a small perl script,
> and there it compiles just fine. But as part of a Perl section it does
> not work. Why?
>
> --
> krist.vanbesien@gmail.com
> Bremgarten b. Bern, Switzerland
>
--
Hendrik Van Belleghem
Spine - The backbone for your website - http://spine.sf.net
Re: Using "switch" in section.
Posted by Jeff Nokes <je...@yahoo.com>.
Hi,
We have about 30 servers in our productin envrionment, and growing too. We use blocks in our configs, but we just use standard conditionals to do any switch/case decision trees (which is what Switch is doing under the hood anyway [http://faq.perl.org/perlfaq7.html#How_do_I_create_a_sw].
We found it easiest to deploy our conf files with macro substitution strings in them, and we have a Bourne shell script that iterates over the conf files, and replaces macros where appropriate; then the script will start up apache. Here's an example:
...
<VirtualHost macro_ROW_HOST:macro_APACHE_HTTP_PORT>
ServerAdmin macro_APACHE_SERVER_ADMIN
ServerName macro_ROW_HOST
...
In the Bourne shell script, each macro is tied to an inline `sed` statement that does the subsitution. The conf file goes out with a name like '_httpd.conf', and after substitution, is rewritten to 'httpd.conf'.
Works well for us. It's a single solution that solves all dynamic config issues for our dev/QA and prod envrionments.
- Jeff
----- Original Message ----
From: Krist van Besien <kr...@gmail.com>
To: modperl@perl.apache.org
Sent: Friday, August 18, 2006 3:20:19 AM
Subject: Using "switch" in <Perl> section.
Hello,
this is my first post to the mod_perl mailing list. I have been using
mod_perl for about a week now. I do however have quite a few years
Perl scripting experience.
What I am trying to do is: Make one httpd.conf that will be suitable
for all of our servers. We have about 20 (and growing) apache servers.
Their role can be terermined from their hostname, so mod_perl's <Perl>
sections seem especially well suited to do this.
Currently I have the following section in my httpd.conf:
526 <Perl>
527
528 # We get the hostname, and use it to:
529 # generate a PID file name
530 # generate log file names
531 # include a hostname dependent include file
532
533 use Sys::Hostname;
534 use Apache2::ServerRec;
535 use Apache2::ServerUtil;
536 use Switch;
537 my $VFL_hostname = hostname();
538 my $VFL_servertype = "";
539 $ServerName = $VFL_hostname;
540
541 $PidFile = "logs/$ServerName.pid";
542 $ServerName .= ".swisptt.ch";
543 print STDERR "ServerName = $ServerName\n";
544
545 switch ($VFL_hostname) {
546 case "mstvflfewprp2v" {
547 $VFL_servertype = "sony" ;
548 }
549 case /ms.vflfe(.*).v/ {
550 $VFL_servertype = $1;
551 }
552 else {
553 $VFL_servertype = "default";
554 }
555 }
556
557 my $VFL_include = "conf/$VFL_servertype.inc" ;
558 print STDERR "Including $VFL_include\n" ;
559 $Include = $VFL_include ;
560
561 $CustomLog = "logs/$VFL_hostname/access_log vfl" ;
562 $ErrorLog = "logs/$VFL_hostname/error_log" ;
563
564 my $VFL_serverroot = Apache2::ServerUtil::server_root() ;
565
566 unless ( -d "$VFL_serverroot/logs/$VFL_hostname" ) {
567 mkdir "$VFL_serverroot/logs/$VFL_hostname", 0755;
568 }
569
570 </Perl>
My problem: When I run apachectl test I get the following error:
String found where operator expected at
/opt/portal/webserver/conf/httpd.conf line 546, near "case
"mstvflfewprp2v""
(Do you need to predeclare case?)
Syntax error on line 527 of /opt/portal/webserver/conf/httpd.conf:
syntax error at /opt/portal/webserver/conf/httpd.conf line 545, near ") {"\n
And after staring at my code for hours I still can't find out what
might be the syntas errors...
- Perl version used is 5.8.5. I checked the contents of the @INC
variable (by adding a print STDERR @INC" statement in a seperate perl
section, and found out that on of the directories searched does
contains the switch.pm module.
I alos tested this piece of code by puting it in a small perl script,
and there it compiles just fine. But as part of a Perl section it does
not work. Why?
--
krist.vanbesien@gmail.com
Bremgarten b. Bern, Switzerland