Annotation of loncom/build/system_dependencies/sqltest.pl, revision 1.4
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);
67: unless ($perlvar{'lonRole'} eq 'library') {
68: print "SQL testing can only be run on a library server. Skipping test..\n";
69: exit 0;
70: }
71: # database test
72: my $dbh;
73: {
74: unless (
75: $dbh = DBI->connect("DBI:mysql:loncapa","www",
76: $perlvar{'lonSqlAccess'},
77: { RaiseError =>0,PrintError=>0})
78: ) {
79: print "Cannot connect to database!\n";
1.3 harris41 80: my $checkDBImodule=`perl pmvers DBI 2>/dev/null`;
81: my $checkMYSQLmodule=`perl pmvers Mysql 2>/dev/null`;
82: my $checkprocess=`/etc/rc.d/init.d/mysqld status`;
83: if (!$checkDBImodule) {
84: print "**** ERROR **** SYSTEM IS MISSING THE DBI PERL ".
85: "MODULE (DBI.pm)\n";
86: }
87: elsif (!$checkMYSQLmodule) {
88: print "**** ERROR **** SYSTEM IS MISSING THE MYSQL PERL ".
89: "MODULE (Mysql.pm)\n";
90: }
91: elsif (!-e '/etc/rc.d/init.d/mysqld') {
92: print "**** ERROR **** IT APPEARS THAT THE MYSQL SERVER HAS NOT ".
93: "BEEN INSTALLED\n";
94: }
95: elsif ($checkprocess=~/is stopped/) {
96: print "**** ERROR **** IT APPEARS THAT THE MYSQL SERVER IS NOT ".
97: "RUNNING\n";
98: print(<<END);
99: To fix temporarily, run the command:
100: /etc/rc.d/init.d/mysqld start
101:
102: You may also want to check and see that mysqld is started on boot time.
103:
104: /sbin/chkconfig --list mysqld
105:
106: This is bad output:
107: mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
108:
109: This is good output:
110: mysqld 0:off 1:off 2:off 3:on 4:on 5:on 6:off
111:
112: To configure mysqld to launch correctly upon system startup, type the command:
113: /sbin/chkconfig --level 345 mysqld on
114: END
115: }
116: else {
117: print "**** ERROR **** IT APPEARS THAT WWW\@LOCALHOST AND/OR ".
118: "PASSWORD ARE NOT CORRECTLY ENABLED\n";
119: print(<<END);
120: To diagnose, try logging in from the command line with
121: mysql -u www -p mysql
122: and use the lonSqlAccess password
123: listed in loncapa.conf (PerlSetVar lonSqlAccess ....).
124: If this does not work, you may need to REMOVE the www\@localhost MySQL user.
125: mysql -u root -p mysql
126: mysql> delete from user where user='www'
127: And then, you will need to repeat the MySQL configuration steps described at:
128: http://install.lon-capa.org/.
129:
130: **** NOTE **** ANOTHER possibility is that you are not running
131: a compatible set of DBI, Mysql perl modules and MySQL server software.
132: END
133: }
1.1 harris41 134: exit 1;
135: }
136: }
137: %perlvar=(); # undefine it
1.2 harris41 138:
139: print "SQL metadata database is found and is accessible\n";
1.1 harris41 140:
141: # --------------------------------------------------- Close database connection
142: $dbh->disconnect();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>