Annotation of loncom/configuration/Configuration.pm, revision 1.13
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # Configuration file reader
3: #
1.13 ! raeburn 4: # $Id: Configuration.pm,v 1.12 2004/04/01 15:26:04 albertel Exp $
1.1 harris41 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:
1.7 harris41 33: # POD documentation is at the end of this short module.
34:
1.1 harris41 35: package LONCAPA::Configuration;
36:
1.13 ! raeburn 37: $VERSION = sprintf("%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/);
1.1 harris41 38:
39: use strict;
40:
1.13 ! raeburn 41: my @confdirs=('/etc/httpd/conf/','/etc/apache2/');
1.1 harris41 42:
1.7 harris41 43: # ------------------- Subroutine read_conf: read LON-CAPA server configuration.
44: # This subroutine reads PerlSetVar values out of specified web server
45: # configuration files.
1.12 albertel 46: sub read_conf {
1.1 harris41 47: my (@conf_files)=@_;
1.13 ! raeburn 48: my (%perlvar,%configdirs);
1.12 albertel 49: foreach my $filename (@conf_files,'loncapa_apache.conf') {
1.13 ! raeburn 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: open(CONFIG,'<'.$configdir.$filename) or
! 62: die("Can't read $configdir$filename");
1.12 albertel 63: while (my $configline=<CONFIG>) {
64: if ($configline =~ /^[^\#]*PerlSetVar/) {
1.1 harris41 65: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
66: chomp($varvalue);
67: $perlvar{$varname}=$varvalue;
1.12 albertel 68: }
69: }
1.1 harris41 70: close(CONFIG);
1.12 albertel 71: }
1.1 harris41 72: my $perlvarref=\%perlvar;
73: return ($perlvarref);
1.12 albertel 74: }
1.1 harris41 75:
1.9 foxr 76: #---------------------- Subroutine read_hosts: Read a LON-CAPA hosts.tab
77: # formatted configuration file.
78: #
79: my $RequiredCount = 5; # Required item count in hosts.tab.
80: my $DefaultMaxCon = 5; # Default value for maximum connections.
81: my $DefaultIdle = 1000; # Default connection idle time in seconds.
82: my $DefaultMinCon = 0; # Default value for minimum connections.
83: sub read_hosts {
84: my $Filename = shift;
85: my %HostsTab;
86:
87: open(CONFIG,'<'.$Filename) or die("Can't read $Filename");
88: while (my $line = <CONFIG>) {
1.10 foxr 89: if (!($line =~ /^\s*\#/)) {
90: my @items = split(/:/, $line);
91: if(scalar @items >= $RequiredCount) {
92: if (scalar @items == $RequiredCount) { # Only required items:
93: $items[$RequiredCount] = $DefaultMaxCon;
94: }
95: if(scalar @items == $RequiredCount + 1) { # up through maxcon.
96: $items[$RequiredCount+1] = $DefaultIdle;
97: }
98: if(scalar @items == $RequiredCount + 2) { # up through idle.
99: $items[$RequiredCount+2] = $DefaultMinCon;
100: }
101: {
102: my @list = @items; # probably not needed but I'm unsure of
103: # about the scope of item so...
1.11 matthew 104: $HostsTab{$list[0]} = \@list;
1.10 foxr 105: }
106: }
1.9 foxr 107: }
108: }
109: close(CONFIG);
110: my $hostref = \%HostsTab;
111: return ($hostref);
112: }
113:
114: 1;
1.1 harris41 115: __END__
116:
117: =pod
118:
119: =head1 NAME
120:
121: B<LONCAPA::Configuration> - configuration file reader
122:
123: =head1 SYNOPSIS
124:
125: use lib '/home/httpd/lib/perl/';
126: use LONCAPA::Configuration;
127:
1.7 harris41 128: LONCAPA::Configuration::read_conf('loncapa.conf');
1.9 foxr 129: LONCAPA::Configuration::read_hosts(filename);
1.1 harris41 130:
131: =head1 DESCRIPTION
132:
1.9 foxr 133: Many different parts of the LON-CAPA software need to reads in the
1.4 harris41 134: machine-specific configuration information. These included scripts
135: controlling the TCP/IP layer (e.g. F<lonc> and F<lond>), testing scripts
136: (e.g. test_weblayer.pl and sqltest.pl), and utility scripts
137: (e.g. clusterstatus.pl and metadata_keywords.pl).
1.1 harris41 138:
139: The following methods are available:
140:
141: =over 4
142:
143: =item $perlvarref = LONCAPA::Configuration::read_conf( @filename_list );
144:
145: On a typical LON-CAPA server, the filename list argument will consist of
146: just one element, "loncapa.conf".
147:
148: If there are multiple elements within the filename list, then these
149: filenames are processed consecutively.
150:
151: A hash reference is returned and consists of those values which
152: have been initialized from the configuration filenames indicated
153: in the arguments.
154:
155: If multiple file names define the same hash key, then priority is
1.4 harris41 156: given toward the B<last> file name processed.
1.1 harris41 157:
158: =back
1.9 foxr 159:
160: =over 4
161: =item $hostinfo = LONCAPA::Configuration::read_hosts(filename);
162:
163: The parameter is the name of a file in hosts.tab form. The file is read and
164: parsed. The return value is a reference to a hash. The hash is indexed by
165: host and each element of the has is in turn a reference to an anonymous list
166: containing:
167:
168: =over 4
169: =item host
170: The loncapa hostname of the system. (This may be different than the
171: network hostname, see below).
172: =item domain
173: The loncapa domain in which the host lives.
174: =item role
175: The role of the system, currently allowed values are access for an
176: access server and library for a library server.
177: =item dns
178: The DNS hostname of the system.
179: =item ip
180: The IP address corresponding to the dns hostname of the system.
181: =item maxconn
182: The maximum number of connections this system should hold to the
183: target system's lond. If the file has no value, a default is supplied
184: here by the function.
185: =item idle
186: The number of seconds the oldest idle connection can be idle before it
187: should be adaptively dropped. If the file has no value, a default
188: is supplied by the function.
189: =item mincon
190: The minimum number of connections this system should hold to the
191: target system's lond. If the file has no value, a default is supplied by
192: the funciton.
193:
194: =back
195:
196: =back
197:
198:
1.1 harris41 199:
200: =head1 AUTHORS
201:
202: This library is free software; you can redistribute it and/or
203: modify it under the same terms as LON-CAPA itself.
204:
205: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>