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 <[EMAIL PROTECTED]>
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?

-- 
[EMAIL PROTECTED]
Bremgarten b. Bern, Switzerland



Reply via email to