File:  [LON-CAPA] / loncom / build / system_dependencies / sqltest.pl
Revision 1.3: download - view: text, annotated - select for diffs
Fri May 10 01:32:38 2002 UTC (22 years, 2 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
making output of test more intelligent when DBI:mysql:loncapa
command doesn't work; BUG 428

    1: #!/usr/bin/perl
    2: #
    3: # The LearningOnline Network with CAPA
    4: #
    5: # Tests the MySQL layer of the metadata database.
    6: #
    7: # YEAR=2001
    8: # 9/25,9/30 Scott Harrison
    9: #
   10: 
   11: ###############################################################################
   12: ##                                                                           ##
   13: ## ORGANIZATION OF THIS PERL CGI SCRIPT                                      ##
   14: ##                                                                           ##
   15: ## 1. Status of this code                                                    ##
   16: ## 2. Purpose and description of program                                     ##
   17: ## 3. Modules used by this script                                            ##
   18: ## 4. Print MIME Content-type and other initialization                       ##
   19: ## 5. Make sure database can be accessed and that this is a library server   ##
   20: ##                                                                           ##
   21: ###############################################################################
   22: 
   23: # --------------------------------------------------------- Status of this code
   24: #
   25: # 1=horrible 2=poor 3=fair 4=good 5=excellent
   26: # Organization 5
   27: # Functionality 4
   28: # Has it been tested? 3
   29: #
   30: 
   31: # ------------------------------------------ Purpose and description of program
   32: #
   33: # This program tests the connection to the MySQL database.
   34: 
   35: # ------------------------------------------------- Modules used by this script
   36: use strict;
   37: use DBI;
   38: 
   39: # ---------------------------- Print MIME Content-type and other initialization
   40: $|=1;
   41: print 'Probing for SQL metadata database'."\n\n";
   42: 
   43: # --- Make sure that database can be accessed and that this is a library server
   44: # library server test
   45: my %perlvar;
   46: open (CONFIG,"/etc/httpd/conf/access.conf") || 
   47:     (print "Can't read access.conf\n" && exit);
   48: while (my $configline=<CONFIG>) {
   49:     if ($configline =~ /PerlSetVar/) {
   50: 	my ($dummy,$varname,$varvalue)=split(/\s+/,$configline);
   51:         chomp($varvalue);
   52:         $perlvar{$varname}=$varvalue;
   53:     }
   54: }
   55: close(CONFIG);
   56: unless ($perlvar{'lonRole'} eq 'library') {
   57:     print "SQL testing can only be run on a library server. Skipping test..\n";
   58:     exit 0;
   59: }
   60: # database test
   61: my $dbh;
   62: {
   63:     unless (
   64: 	    $dbh = DBI->connect("DBI:mysql:loncapa","www",
   65: 				$perlvar{'lonSqlAccess'},
   66: 				{ RaiseError =>0,PrintError=>0})
   67: 	    ) { 
   68: 	print "Cannot connect to database!\n";
   69: 	my $checkDBImodule=`perl pmvers DBI 2>/dev/null`;
   70: 	my $checkMYSQLmodule=`perl pmvers Mysql 2>/dev/null`;
   71: 	my $checkprocess=`/etc/rc.d/init.d/mysqld status`;
   72: 	if (!$checkDBImodule) {
   73: 	    print "**** ERROR **** SYSTEM IS MISSING THE DBI PERL ".
   74: 		"MODULE (DBI.pm)\n";
   75: 	}
   76: 	elsif (!$checkMYSQLmodule) {
   77: 	    print "**** ERROR **** SYSTEM IS MISSING THE MYSQL PERL ".
   78: 		"MODULE (Mysql.pm)\n";
   79: 	}
   80: 	elsif (!-e '/etc/rc.d/init.d/mysqld') {
   81: 	    print "**** ERROR **** IT APPEARS THAT THE MYSQL SERVER HAS NOT ".
   82: 		"BEEN INSTALLED\n";
   83: 	}
   84: 	elsif ($checkprocess=~/is stopped/) {
   85: 	    print "**** ERROR **** IT APPEARS THAT THE MYSQL SERVER IS NOT ".
   86: 		"RUNNING\n";
   87: 	    print(<<END);
   88: To fix temporarily, run the command:
   89:    /etc/rc.d/init.d/mysqld start
   90: 
   91: You may also want to check and see that mysqld is started on boot time.
   92: 
   93:    /sbin/chkconfig --list mysqld
   94: 
   95: This is bad output:
   96: mysqld         0:off  1:off  2:off  3:off  4:off  5:off  6:off
   97: 
   98: This is good output:
   99: mysqld         0:off  1:off  2:off  3:on   4:on   5:on   6:off
  100: 
  101: To configure mysqld to launch correctly upon system startup, type the command:
  102:    /sbin/chkconfig --level 345 mysqld on
  103: END
  104: 	}
  105: 	else {
  106: 	    print "**** ERROR **** IT APPEARS THAT WWW\@LOCALHOST AND/OR ".
  107: 		"PASSWORD ARE NOT CORRECTLY ENABLED\n";
  108: 	    print(<<END);
  109: To diagnose, try logging in from the command line with
  110:        mysql -u www -p mysql
  111: and use the lonSqlAccess password
  112: listed in loncapa.conf (PerlSetVar lonSqlAccess ....).
  113: If this does not work, you may need to REMOVE the www\@localhost MySQL user.
  114: mysql -u root -p mysql
  115: mysql> delete from user where user='www'
  116: And then, you will need to repeat the MySQL configuration steps described at:
  117:        http://install.lon-capa.org/.
  118: 
  119: **** NOTE **** ANOTHER possibility is that you are not running
  120: a compatible set of DBI, Mysql perl modules and MySQL server software.
  121: END
  122: 	}
  123: 	exit 1;
  124:     }
  125: }
  126: %perlvar=(); # undefine it
  127: 
  128: print "SQL metadata database is found and is accessible\n";
  129: 
  130: # --------------------------------------------------- Close database connection
  131: $dbh->disconnect();

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