Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Best approach to store Application Configuration

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


online.jerry at gmail

Jul 11, 2011, 2:07 PM

Post #1 of 11 (802 views)
Permalink
Best approach to store Application Configuration

Hi All,

I am new to mod_perl (a java developer). I would like to know the best
approach to store and retrieve Applicaiton configurations that is accessible
to all packages in my mod_perl application.

My application configuration includes - Database details, Template mapping,
LDAP configuration details etc. I would like my to load all these
configuratoins when my application starts and then on, i should be able to
access these configuration from anywhere.

For Example:
my $dbDetails = ConfigUtil->getDBDetails(); //returns reference to hash
my dbUser = dbDetails->user;

I belive PerlSetVar only allows strings variables. I would like to get some
suggestions on how configuration management in mod_perl applications.

Thanks,
Jerry


James.B.Muir at hitchcock

Jul 11, 2011, 2:16 PM

Post #2 of 11 (782 views)
Permalink
RE: Best approach to store Application Configuration [In reply to]

This page describes pretty well how to set up custom configuration directives; perhaps helpful?

http://perl.apache.org/docs/2.0/user/config/custom.html

-James

From: Jerry Pereira [mailto:online.jerry [at] gmail]
Sent: Monday, July 11, 2011 5:08 PM
To: modperl [at] perl
Subject: Best approach to store Application Configuration

Hi All,

I am new to mod_perl (a java developer). I would like to know the best approach to store and retrieve Applicaiton configurations that is accessible to all packages in my mod_perl application.

My application configuration includes - Database details, Template mapping, LDAP configuration details etc. I would like my to load all these configuratoins when my application starts and then on, i should be able to access these configuration from anywhere.

For Example:
my $dbDetails = ConfigUtil->getDBDetails(); //returns reference to hash
my dbUser = dbDetails->user;

I belive PerlSetVar only allows strings variables. I would like to get some suggestions on how configuration management in mod_perl applications.

Thanks,
Jerry

IMPORTANT NOTICE REGARDING THIS ELECTRONIC MESSAGE:

This message is intended for the use of the person to whom it is addressed and may contain information that is privileged, confidential, and protected from disclosure under applicable law. If you are not the intended recipient, your use of this message for any purpose is strictly prohibited. If you have received this communication in error, please delete the message and notify the sender so that we may correct our records.


Edward.Szekeres at PERKINELMER

Jul 11, 2011, 2:21 PM

Post #3 of 11 (781 views)
Permalink
RE: Best approach to store Application Configuration [In reply to]

Database

Flatfile on disk (look up Storable module on how to save/load binary representation of PERL structures), works well if you want to have an "instant structure", but flatfiles need location on the server.

I use both regularly

From: Jerry Pereira [mailto:online.jerry [at] gmail]
Sent: Monday, July 11, 2011 5:08 PM
To: modperl [at] perl
Subject: Best approach to store Application Configuration

Hi All,

I am new to mod_perl (a java developer). I would like to know the best approach to store and retrieve Applicaiton configurations that is accessible to all packages in my mod_perl application.

My application configuration includes - Database details, Template mapping, LDAP configuration details etc. I would like my to load all these configuratoins when my application starts and then on, i should be able to access these configuration from anywhere.

For Example:
my $dbDetails = ConfigUtil->getDBDetails(); //returns reference to hash
my dbUser = dbDetails->user;

I belive PerlSetVar only allows strings variables. I would like to get some suggestions on how configuration management in mod_perl applications.

Thanks,
Jerry


mpeters at plusthree

Jul 11, 2011, 2:23 PM

Post #4 of 11 (779 views)
Permalink
Re: Best approach to store Application Configuration [In reply to]

On 07/11/2011 05:16 PM, James B. Muir wrote:
> This page describes pretty well how to set up custom configuration
> directives; perhaps helpful?
>
> http://perl.apache.org/docs/2.0/user/config/custom.html

I would almost always avoid this kind of configuration and go with an
external configuration file. Every project of any decent size will have
some scripts or processes that don't run under mod_perl and thus can't
use this apache-only configuration.

As for configuration in Perl if I were starting a new project, I'd
probably go with something like Config::Any and then pick a backend
format. But in practice it probably doesn't matter a whole lot which
config module you use as long as it's not tied to Apache. But if you
like the apache-style format you can use Config::ApacheFormat which
works well.

--
Michael Peters
Plus Three, LP


jmccarre at akamai

Jul 11, 2011, 2:26 PM

Post #5 of 11 (781 views)
Permalink
Re: Best approach to store Application Configuration [In reply to]

Hi Jerry.

I went through a couple of different approaches before settling on using YAML files to describe configuration.
There are several nice properties of YAML IMO, not least of which is arbitrary nesting so the config can closely match the software being configured.
Here is a sanitized example of my production config:

# -*- mode: perl -*-
# configuration file for XXX
config: { version: 1 }

# XYZ configuration
# across the entire XXX tier
xyz: {
# enable / disable all ...
feature_X_enabled: true,

# name of cookie(s) to emit: [xx, yy, zz]
emit_cookies: [ xx ]

# substructure configuration
sub_structures: {
disabled: {
foo: [],
bar: [],
baz: [],
}
}
}

There are several YAML readers available; I preferred YAML::XS because of its speed and correctness.
My apps need to run a long time, so they poll the configuration file every n seconds, and reload it if needed.
Overall, I was pretty happy with this approach, and so were the operations folks who have to configure the settings in production.

HTH,
-- jeff

From: Jerry Pereira <online.jerry [at] gmail<mailto:online.jerry [at] gmail>>
Date: Mon, 11 Jul 2011 16:07:58 -0500
To: "modperl [at] perl<mailto:modperl [at] perl>" <modperl [at] perl<mailto:modperl [at] perl>>
Subject: Best approach to store Application Configuration

Hi All,

I am new to mod_perl (a java developer). I would like to know the best approach to store and retrieve Applicaiton configurations that is accessible to all packages in my mod_perl application.

My application configuration includes - Database details, Template mapping, LDAP configuration details etc. I would like my to load all these configuratoins when my application starts and then on, i should be able to access these configuration from anywhere.

For Example:
my $dbDetails = ConfigUtil->getDBDetails(); //returns reference to hash
my dbUser = dbDetails->user;

I belive PerlSetVar only allows strings variables. I would like to get some suggestions on how configuration management in mod_perl applications.

Thanks,
Jerry


fred at redhotpenguin

Jul 11, 2011, 2:35 PM

Post #6 of 11 (781 views)
Permalink
Re: Best approach to store Application Configuration [In reply to]

On Mon, Jul 11, 2011 at 2:23 PM, Michael Peters <mpeters [at] plusthree> wrote:
> On 07/11/2011 05:16 PM, James B. Muir wrote:
>>
>> This page describes pretty well how to set up custom configuration
>> directives; perhaps helpful?
>>
>> http://perl.apache.org/docs/2.0/user/config/custom.html
>
> I would almost always avoid this kind of configuration and go with an
> external configuration file. Every project of any decent size will have some
> scripts or processes that don't run under mod_perl and thus can't use this
> apache-only configuration.

This kind of configuration has the advantage of avoiding the overhead
associated with PerlSetVar if I recall correctly. The downside is
that the custom config directives can be a bit tricky to setup
correctly.

> As for configuration in Perl if I were starting a new project, I'd probably
> go with something like Config::Any and then pick a backend format.

+1


online.jerry at gmail

Jul 11, 2011, 2:41 PM

Post #7 of 11 (780 views)
Permalink
Re: Best approach to store Application Configuration [In reply to]

please correct me if I am wrong, I should be using tool like
YAML/Config::General for application configuration storage and reteieval,
and load them on startup using startup.pl script? That would mean i will
have to store the name of configuration file some where (probabaly in
mod_perl configuration block in httpd.conf).

On Mon, Jul 11, 2011 at 2:26 PM, McCarrell, Jeff <jmccarre [at] akamai>wrote:

> Hi Jerry.
>
> I went through a couple of different approaches before settling on using
> YAML files to describe configuration.
> There are several nice properties of YAML IMO, not least of which is
> arbitrary nesting so the config can closely match the software being
> configured.
> Here is a sanitized example of my production config:
>
> # -*- mode: perl -*-
> # configuration file for XXX
> config: { version: 1 }
>
> # XYZ configuration
> # across the entire XXX tier
> xyz: {
> # enable / disable all ...
> feature_X_enabled: true,
>
> # name of cookie(s) to emit: [xx, yy, zz]
> emit_cookies: [ xx ]
>
> # substructure configuration
> sub_structures: {
> disabled: {
> foo: [],
> bar: [],
> baz: [],
> }
> }
> }
>
> There are several YAML readers available; I preferred YAML::XS because of
> its speed and correctness.
> My apps need to run a long time, so they poll the configuration file every
> n seconds, and reload it if needed.
> Overall, I was pretty happy with this approach, and so were the operations
> folks who have to configure the settings in production.
>
> HTH,
> -- jeff
>
> From: Jerry Pereira <online.jerry [at] gmail>
> Date: Mon, 11 Jul 2011 16:07:58 -0500
> To: "modperl [at] perl" <modperl [at] perl>
>
> Subject: Best approach to store Application Configuration
>
> Hi All,
>
> I am new to mod_perl (a java developer). I would like to know the best
> approach to store and retrieve Applicaiton configurations that is accessible
> to all packages in my mod_perl application.
>
> My application configuration includes - Database details, Template mapping,
> LDAP configuration details etc. I would like my to load all these
> configuratoins when my application starts and then on, i should be able to
> access these configuration from anywhere.
>
> For Example:
> my $dbDetails = ConfigUtil->getDBDetails(); //returns reference to hash
> my dbUser = dbDetails->user;
>
> I belive PerlSetVar only allows strings variables. I would like to get some
> suggestions on how configuration management in mod_perl applications.
>
> Thanks,
> Jerry
>



--
Your clothes may be the latest in style but you aint completely dressed
until you wear a smile!
Keep smiling : )


James.B.Muir at hitchcock

Jul 11, 2011, 2:42 PM

Post #8 of 11 (783 views)
Permalink
RE: Best approach to store Application Configuration [In reply to]

The PerlSetVar overhead occurs on every request, whereas the overhead associated with using the custom configuration occurs once when Apache is started.
-James


-----Original Message-----
From: Fred Moyer [mailto:fred [at] redhotpenguin]
Sent: Monday, July 11, 2011 5:35 PM
To: Michael Peters
Cc: James B. Muir; Jerry Pereira; modperl [at] perl
Subject: Re: Best approach to store Application Configuration

On Mon, Jul 11, 2011 at 2:23 PM, Michael Peters <mpeters [at] plusthree> wrote:
> On 07/11/2011 05:16 PM, James B. Muir wrote:
>>
>> This page describes pretty well how to set up custom configuration
>> directives; perhaps helpful?
>>
>> http://perl.apache.org/docs/2.0/user/config/custom.html
>
> I would almost always avoid this kind of configuration and go with an
> external configuration file. Every project of any decent size will have some
> scripts or processes that don't run under mod_perl and thus can't use this
> apache-only configuration.

This kind of configuration has the advantage of avoiding the overhead
associated with PerlSetVar if I recall correctly. The downside is
that the custom config directives can be a bit tricky to setup
correctly.

> As for configuration in Perl if I were starting a new project, I'd probably
> go with something like Config::Any and then pick a backend format.

+1

IMPORTANT NOTICE REGARDING THIS ELECTRONIC MESSAGE:

This message is intended for the use of the person to whom it is addressed and may contain information that is privileged, confidential, and protected from disclosure under applicable law. If you are not the intended recipient, your use of this message for any purpose is strictly prohibited. If you have received this communication in error, please delete the message and notify the sender so that we may correct our records.


jmccarre at akamai

Jul 11, 2011, 3:03 PM

Post #9 of 11 (783 views)
Permalink
Re: Best approach to store Application Configuration [In reply to]

Naming the path to the config file in an httpd conf will certainly work.
In my case, the path the config file is hard coded in the method that reads the config as it is not something that changes.

Here is on of my httpd conf file (a separate file loaded in the http configuration directory so your install process doesn't have to change the actual httpd.conf):
PerlModule Your::App
PerlPostConfigHandler Your::App::httpd_start

<Location /foo/app>
SetHandler modperl
PerlResponseHandler +Your::App

# Apache::DBI needs GlobalRequest
PerlOptions +GlobalRequest
</Location>

The httpd_start method gets called at apache startup time, and reads the config in once.

Also, one other possible advantage to YAML is that YAML is not perl, so if you have a mixed language env,
it is easy to share/move/port your config to the language of your choice.
YAML has pretty good support across the common languages you will find in the LAMP world.

BTW, if you haven't already done so, I recommend becoming familiar with the handlers and their life cycles:
http://perl.apache.org/docs/2.0/user/handlers/server.html
http://perl.apache.org/docs/2.0/user/handlers/http.html#HTTP_Request_Cycle_Phases

Have fun,

-- jeff

From: Jerry Pereira <online.jerry [at] gmail<mailto:online.jerry [at] gmail>>
Date: Mon, 11 Jul 2011 16:41:13 -0500
To: Jeff McCarrell <jmccarre [at] akamai<mailto:jmccarre [at] akamai>>
Cc: "modperl [at] perl<mailto:modperl [at] perl>" <modperl [at] perl<mailto:modperl [at] perl>>
Subject: Re: Best approach to store Application Configuration

please correct me if I am wrong, I should be using tool like YAML/Config::General for application configuration storage and reteieval, and load them on startup using startup.pl<http://startup.pl> script? That would mean i will have to store the name of configuration file some where (probabaly in mod_perl configuration block in httpd.conf).


mpeters at plusthree

Jul 11, 2011, 3:14 PM

Post #10 of 11 (781 views)
Permalink
Re: Best approach to store Application Configuration [In reply to]

On 07/11/2011 05:41 PM, Jerry Pereira wrote:
> please correct me if I am wrong, I should be using tool like
> YAML/Config::General for application configuration storage and
> reteieval, and load them on startup using startup.pl <http://startup.pl>
> script?

Yes.

> That would mean i will have to store the name of configuration
> file some where (probabaly in mod_perl configuration block in httpd.conf).

Again, if you think about just using a mod_perl specific way of doing
this you'll leave all of your non-mod_perl stuff out in the cold and any
project of significant size is going to have some non-mod_perl processes
involved somewhere.

I prefer to use environment variables if you need to specify the
location of a config file. These are available no matter where you're
running (in mod_perl you'll want to use a PerlPassEnv directive so the
mod_perl side sees it).

--
Michael Peters
Plus Three, LP


k.ghadami at ibson

Jul 11, 2011, 3:33 PM

Post #11 of 11 (779 views)
Permalink
Re: Best approach to store Application Configuration [In reply to]

Hi Jerry,
I use JSON:XS in my framework, but
before writing a hole framework from the scratch, think about using
catalyst.
regards keywan




Am 11.07.2011 23:07, schrieb Jerry Pereira:
> Hi All,
>
> I am new to mod_perl (a java developer). I would like to know the best
> approach to store and retrieve Applicaiton configurations that is accessible
> to all packages in my mod_perl application.
>
> My application configuration includes - Database details, Template mapping,
> LDAP configuration details etc. I would like my to load all these
> configuratoins when my application starts and then on, i should be able to
> access these configuration from anywhere.
>
> For Example:
> my $dbDetails = ConfigUtil->getDBDetails(); //returns reference to hash
> my dbUser = dbDetails->user;
>
> I belive PerlSetVar only allows strings variables. I would like to get some
> suggestions on how configuration management in mod_perl applications.
>
> Thanks,
> Jerry
>


--
Mit freundlichen Grüßen
Keywan Ghadami
Telefon +49 (0)75 31 / 81 39 7 95
Fax +49 (0)75 31 / 81 39 7 89
Anschrift
ibson
Fritz-Arnold-Str. 23
D-78467 Konstanz

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.