File:  [LON-CAPA] / loncom / configuration / Configuration.pm
Revision 1.12: download - view: text, annotated - select for diffs
Thu Apr 1 15:26:04 2004 UTC (20 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_X, version_1_2_99_1, version_1_2_99_0, version_1_2_1, version_1_2_0, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, HEAD
- style police

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>