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