version 1.1, 2002/05/03 23:57:19
|
version 1.10, 2003/04/12 02:45:31
|
Line 27
|
Line 27
|
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
# YEAR=2002 |
# YEAR=2002 |
# 05/03 Scott Harrison |
|
# |
# |
### |
### |
|
|
|
# POD documentation is at the end of this short module. |
|
|
package LONCAPA::Configuration; |
package LONCAPA::Configuration; |
|
|
$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/); |
$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/); |
Line 39 use strict;
|
Line 40 use strict;
|
|
|
my $confdir='/etc/httpd/conf/'; |
my $confdir='/etc/httpd/conf/'; |
|
|
# ------------------------------------ read_conf: read LON-CAPA server configuration, especially PerlSetVar values |
# ------------------- Subroutine read_conf: read LON-CAPA server configuration. |
sub read_conf { |
# This subroutine reads PerlSetVar values out of specified web server |
|
# configuration files. |
|
sub read_conf |
|
{ |
my (@conf_files)=@_; |
my (@conf_files)=@_; |
my %perlvar; |
my %perlvar; |
foreach my $filename (@conf_files) { |
foreach my $filename (@conf_files,'loncapa_apache.conf') |
open(CONFIG,'<'.$confdir.$filename) or die("Can't read access.conf"); |
{ |
while (my $configline=<CONFIG>) { |
open(CONFIG,'<'.$confdir.$filename) or |
if ($configline =~ /^[^\#]*PerlSetVar/) { |
die("Can't read $confdir$filename"); |
|
while (my $configline=<CONFIG>) |
|
{ |
|
if ($configline =~ /^[^\#]*PerlSetVar/) |
|
{ |
my ($unused,$varname,$varvalue)=split(/\s+/,$configline); |
my ($unused,$varname,$varvalue)=split(/\s+/,$configline); |
chomp($varvalue); |
chomp($varvalue); |
$perlvar{$varname}=$varvalue; |
$perlvar{$varname}=$varvalue; |
} |
} |
} |
} |
close(CONFIG); |
close(CONFIG); |
} |
} |
my $perlvarref=\%perlvar; |
my $perlvarref=\%perlvar; |
return ($perlvarref); |
return ($perlvarref); |
|
} |
|
|
|
#---------------------- Subroutine read_hosts: Read a LON-CAPA hosts.tab |
|
# formatted configuration file. |
|
# |
|
my $RequiredCount = 5; # Required item count in hosts.tab. |
|
my $DefaultMaxCon = 5; # Default value for maximum connections. |
|
my $DefaultIdle = 1000; # Default connection idle time in seconds. |
|
my $DefaultMinCon = 0; # Default value for minimum connections. |
|
sub read_hosts { |
|
my $Filename = shift; |
|
my %HostsTab; |
|
|
|
open(CONFIG,'<'.$Filename) or die("Can't read $Filename"); |
|
while (my $line = <CONFIG>) { |
|
if (!($line =~ /^\s*\#/)) { |
|
my @items = split(/:/, $line); |
|
if(scalar @items >= $RequiredCount) { |
|
if (scalar @items == $RequiredCount) { # Only required items: |
|
$items[$RequiredCount] = $DefaultMaxCon; |
|
} |
|
if(scalar @items == $RequiredCount + 1) { # up through maxcon. |
|
$items[$RequiredCount+1] = $DefaultIdle; |
|
} |
|
if(scalar @items == $RequiredCount + 2) { # up through idle. |
|
$items[$RequiredCount+2] = $DefaultMinCon; |
|
} |
|
{ |
|
my @list = @items; # probably not needed but I'm unsure of |
|
# about the scope of item so... |
|
$HostsTab{@list[0]} = \@list; |
|
} |
|
} |
|
} |
|
} |
|
close(CONFIG); |
|
my $hostref = \%HostsTab; |
|
return ($hostref); |
} |
} |
|
|
|
1; |
__END__ |
__END__ |
|
|
=pod |
=pod |
Line 71 B<LONCAPA::Configuration> - configuratio
|
Line 118 B<LONCAPA::Configuration> - configuratio
|
use lib '/home/httpd/lib/perl/'; |
use lib '/home/httpd/lib/perl/'; |
use LONCAPA::Configuration; |
use LONCAPA::Configuration; |
|
|
LONCAPA::Configuration::read_conf('access.conf','loncapa.conf'); |
|
|
|
In the future, standard invocation of the command will be: |
|
|
|
LONCAPA::Configuration::read_conf('loncapa.conf'); |
LONCAPA::Configuration::read_conf('loncapa.conf'); |
|
LONCAPA::Configuration::read_hosts(filename); |
F<access.conf> is slowly becoming deprecated. (We are currently |
|
trying to support backwards compatibility.) |
|
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
Many different parts of the LON-CAPA software need to read in the machine-specific |
Many different parts of the LON-CAPA software need to reads in the |
configuration information. These included scripts controlling the TCP/IP layer |
machine-specific configuration information. These included scripts |
(e.g. F<lonc> and F<lond>), testing scripts (e.g. test_weblayer.pl and sqltest.pl), |
controlling the TCP/IP layer (e.g. F<lonc> and F<lond>), testing scripts |
and utility scripts (e.g. clusterstatus.pl and metadata_keywords.pl). |
(e.g. test_weblayer.pl and sqltest.pl), and utility scripts |
|
(e.g. clusterstatus.pl and metadata_keywords.pl). |
|
|
The following methods are available: |
The following methods are available: |
|
|
Line 104 have been initialized from the configura
|
Line 146 have been initialized from the configura
|
in the arguments. |
in the arguments. |
|
|
If multiple file names define the same hash key, then priority is |
If multiple file names define the same hash key, then priority is |
given toward the last file name processed. |
given toward the B<last> file name processed. |
|
|
=back |
=back |
|
|
=head1 AUTHORS |
=over 4 |
|
=item $hostinfo = LONCAPA::Configuration::read_hosts(filename); |
|
|
|
The parameter is the name of a file in hosts.tab form. The file is read and |
|
parsed. The return value is a reference to a hash. The hash is indexed by |
|
host and each element of the has is in turn a reference to an anonymous list |
|
containing: |
|
|
|
=over 4 |
|
=item host |
|
The loncapa hostname of the system. (This may be different than the |
|
network hostname, see below). |
|
=item domain |
|
The loncapa domain in which the host lives. |
|
=item role |
|
The role of the system, currently allowed values are access for an |
|
access server and library for a library server. |
|
=item dns |
|
The DNS hostname of the system. |
|
=item ip |
|
The IP address corresponding to the dns hostname of the system. |
|
=item maxconn |
|
The maximum number of connections this system should hold to the |
|
target system's lond. If the file has no value, a default is supplied |
|
here by the function. |
|
=item idle |
|
The number of seconds the oldest idle connection can be idle before it |
|
should be adaptively dropped. If the file has no value, a default |
|
is supplied by the function. |
|
=item mincon |
|
The minimum number of connections this system should hold to the |
|
target system's lond. If the file has no value, a default is supplied by |
|
the funciton. |
|
|
|
=back |
|
|
|
=back |
|
|
Scott Harrison |
|
|
|
|
=head1 AUTHORS |
|
|
This library is free software; you can redistribute it and/or |
This library is free software; you can redistribute it and/or |
modify it under the same terms as LON-CAPA itself. |
modify it under the same terms as LON-CAPA itself. |