File:
[LON-CAPA] /
loncom /
configuration /
Configuration.pm
Revision
1.14:
download - view:
text,
annotated -
select for diffs
Thu Aug 30 20:19:35 2007 UTC (17 years, 5 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_99_1,
version_2_5_99_0,
version_2_12_X,
version_2_11_X,
version_2_11_6_msu,
version_2_11_6,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
bz6209-base,
bz6209,
bz5969,
bz2851,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
- support having override PerlSetVar set in loncapa_apache_local*.conf
1: # The LearningOnline Network with CAPA
2: # Configuration file reader
3: #
4: # $Id: Configuration.pm,v 1.14 2007/08/30 20:19:35 albertel Exp $
5: #
6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29: # YEAR=2002
30: #
31: ###
32:
33: # POD documentation is at the end of this short module.
34:
35: package LONCAPA::Configuration;
36:
37: $VERSION = sprintf("%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/);
38:
39: use strict;
40:
41: my @confdirs=('/etc/httpd/conf/','/etc/apache2/');
42:
43: # ------------------- Subroutine read_conf: read LON-CAPA server configuration.
44: # This subroutine reads PerlSetVar values out of specified web server
45: # configuration files.
46: sub read_conf {
47: my (@conf_files)=@_;
48: my (%perlvar,%configdirs);
49: foreach my $filename (@conf_files,'loncapa_apache.conf') {
50: my $configdir = '';
51: $configdirs{$filename} = [@confdirs];
52: while ($configdir eq '' && @{$configdirs{$filename}} > 0) {
53: my $testdir = shift(@{$configdirs{$filename}});
54: if (-e $testdir.$filename) {
55: $configdir = $testdir;
56: }
57: }
58: if ($configdir eq '') {
59: die("Couldn't find a directory containing $filename");
60: }
61: &process_file($configdir.$filename,\%perlvar);
62: if ($filename eq 'loncapa_apache.conf') {
63: my @files = glob($configdir.'loncapa_apache_local*.conf');
64: foreach my $file (@files) {
65: &process_file($file,\%perlvar);
66: }
67: }
68: }
69: return (\%perlvar);
70: }
71:
72: # --------------- Subroutine process_file: helper routine
73: # This subroutine does the actual file reading and reads PerlSetVar discovery
74: # specified file, arguments are the filename and a ref to a hash to
75: # place the values in
76: sub process_file {
77: my ($file,$perlvar) = @_;
78: open(my $config,'<',$file) or
79: die("Can't read $file");
80: while (my $configline=<$config>) {
81: if ($configline =~ /^[^\#]*PerlSetVar/) {
82: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
83: chomp($varvalue);
84: $perlvar->{$varname}=$varvalue;
85: }
86: }
87: close($config);
88: }
89:
90: #---------------------- Subroutine read_hosts: Read a LON-CAPA hosts.tab
91: # formatted configuration file.
92: #
93: my $RequiredCount = 5; # Required item count in hosts.tab.
94: my $DefaultMaxCon = 5; # Default value for maximum connections.
95: my $DefaultIdle = 1000; # Default connection idle time in seconds.
96: my $DefaultMinCon = 0; # Default value for minimum connections.
97: sub read_hosts {
98: my $Filename = shift;
99: my %HostsTab;
100:
101: open(CONFIG,'<'.$Filename) or die("Can't read $Filename");
102: while (my $line = <CONFIG>) {
103: if (!($line =~ /^\s*\#/)) {
104: my @items = split(/:/, $line);
105: if(scalar @items >= $RequiredCount) {
106: if (scalar @items == $RequiredCount) { # Only required items:
107: $items[$RequiredCount] = $DefaultMaxCon;
108: }
109: if(scalar @items == $RequiredCount + 1) { # up through maxcon.
110: $items[$RequiredCount+1] = $DefaultIdle;
111: }
112: if(scalar @items == $RequiredCount + 2) { # up through idle.
113: $items[$RequiredCount+2] = $DefaultMinCon;
114: }
115: {
116: my @list = @items; # probably not needed but I'm unsure of
117: # about the scope of item so...
118: $HostsTab{$list[0]} = \@list;
119: }
120: }
121: }
122: }
123: close(CONFIG);
124: my $hostref = \%HostsTab;
125: return ($hostref);
126: }
127:
128: 1;
129: __END__
130:
131: =pod
132:
133: =head1 NAME
134:
135: B<LONCAPA::Configuration> - configuration file reader
136:
137: =head1 SYNOPSIS
138:
139: use lib '/home/httpd/lib/perl/';
140: use LONCAPA::Configuration;
141:
142: LONCAPA::Configuration::read_conf('loncapa.conf');
143: LONCAPA::Configuration::read_hosts(filename);
144:
145: =head1 DESCRIPTION
146:
147: Many different parts of the LON-CAPA software need to reads in the
148: machine-specific configuration information. These included scripts
149: controlling the TCP/IP layer (e.g. F<lonc> and F<lond>), testing scripts
150: (e.g. test_weblayer.pl and sqltest.pl), and utility scripts
151: (e.g. clusterstatus.pl and metadata_keywords.pl).
152:
153: The following methods are available:
154:
155: =over 4
156:
157: =item $perlvarref = LONCAPA::Configuration::read_conf( @filename_list );
158:
159: On a typical LON-CAPA server, the filename list argument will consist of
160: just one element, "loncapa.conf".
161:
162: If there are multiple elements within the filename list, then these
163: filenames are processed consecutively.
164:
165: A hash reference is returned and consists of those values which
166: have been initialized from the configuration filenames indicated
167: in the arguments.
168:
169: If multiple file names define the same hash key, then priority is
170: given toward the B<last> file name processed.
171:
172: =back
173:
174: =over 4
175: =item $hostinfo = LONCAPA::Configuration::read_hosts(filename);
176:
177: The parameter is the name of a file in hosts.tab form. The file is read and
178: parsed. The return value is a reference to a hash. The hash is indexed by
179: host and each element of the has is in turn a reference to an anonymous list
180: containing:
181:
182: =over 4
183: =item host
184: The loncapa hostname of the system. (This may be different than the
185: network hostname, see below).
186: =item domain
187: The loncapa domain in which the host lives.
188: =item role
189: The role of the system, currently allowed values are access for an
190: access server and library for a library server.
191: =item dns
192: The DNS hostname of the system.
193: =item ip
194: The IP address corresponding to the dns hostname of the system.
195: =item maxconn
196: The maximum number of connections this system should hold to the
197: target system's lond. If the file has no value, a default is supplied
198: here by the function.
199: =item idle
200: The number of seconds the oldest idle connection can be idle before it
201: should be adaptively dropped. If the file has no value, a default
202: is supplied by the function.
203: =item mincon
204: The minimum number of connections this system should hold to the
205: target system's lond. If the file has no value, a default is supplied by
206: the funciton.
207:
208: =back
209:
210: =back
211:
212:
213:
214: =head1 AUTHORS
215:
216: This library is free software; you can redistribute it and/or
217: modify it under the same terms as LON-CAPA itself.
218:
219: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>