File:  [LON-CAPA] / loncom / metadata_database / configure_mysql_db.pl
Revision 1.4: download - view: text, annotated - select for diffs
Tue May 31 02:40:08 2011 UTC (12 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, HEAD, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
- TYPE=MYISAM was replaced with ENGINE=MYISAM in MySQL 4.
- TYPE was deprecated in 4 and 5.0/5.1.  It is no longer supported in 5.5.

    1: #!/usr/bin/perl -w
    2: # The LearningOnline Network 
    3: # Red Hat 7.3 installation script
    4: #
    5: # $Id: configure_mysql_db.pl,v 1.4 2011/05/31 02:40:08 raeburn Exp $
    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: # http://www.lon-capa.org/
   26: #
   27: use strict;
   28: use lib '/home/httpd/lib/perl/';
   29: use LONCAPA::Configuration;
   30: 
   31: my $runstatus = shift();
   32: if (! defined($runstatus)) {
   33:     $runstatus = 'firstrun';
   34: }
   35: my $rhver=`perl ../build/distprobe`;
   36: my $rpmname;
   37: if ($rhver eq 'redhat9') {
   38:     $rpmname = "perl-DBD-MySQL-2.9002-1.i386.rpm";
   39: } else {
   40:     $rpmname = "perl-DBD-MySQL-1.2216-4.i386.rpm";
   41: }
   42: 
   43: my $perlvar = &LONCAPA::Configuration::read_conf('loncapa.conf');
   44: delete($perlvar->{'lonReceipt'}); # remove since sensitive and not needed
   45: 
   46: ##
   47: ## Set up mysql to run on boot
   48: ##
   49: my $add_result = system("/sbin/chkconfig --add mysqld 2>/dev/null");
   50: my $on_result = system("/sbin/chkconfig mysqld on 2>/dev/null");
   51: if ($add_result != 0 || $on_result != 0) {
   52:     print "Your system is misconfigured.  ".
   53:         "You do not have MySQL installed.\n";
   54:     exit 1;
   55: }
   56: 
   57: ##
   58: ## Make sure it is running now
   59: ##
   60: my $status = system("/etc/rc.d/init.d/mysqld status 1>/dev/null");
   61: if ($status != 0) {
   62:     print(`/etc/rc.d/init.d/mysqld restart`);
   63:     print("Waiting 5 seconds for mysql daemon to restart.\n");
   64:     sleep 5;
   65:     my $status = system("/etc/rc.d/init.d/mysqld status");
   66:     if ($status != 0) {
   67:         die "Unable to start mysql daemon\nHalting\n";
   68:     }
   69: }
   70: 
   71: ##
   72: ## Make sure the mysql is configured
   73: ##
   74: if ($runstatus eq 'firstrun' && (! exists($perlvar->{'lonSqlAccess'}) || 
   75:                                  ! defined($perlvar->{'lonSqlAccess'}))) {
   76:     ##
   77:     ## Get root password for mysql client
   78:     print <<END;
   79: Please enter a root password for the MySQL database.
   80: It does not have to match your root account password, but you will need
   81: to remember it.
   82: END
   83:     my $rootpass = <>;
   84:     chomp $rootpass;
   85:     print("\n");
   86: 
   87:     my $extraargs;
   88:     if ($rhver eq 'redhat9') { $extraargs=",'Y','Y'"; }
   89:     print("Starting mysql client and setting up permissions\n");
   90:     open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n";
   91:     print MYSQL <<"ENDMYSQLPERMISSIONINIT";
   92: CREATE DATABASE IF NOT EXISTS loncapa;
   93: USE mysql;
   94: INSERT IGNORE INTO user (Host, User, Password)
   95:     VALUES ('localhost','www',password('localhostkey'));
   96: INSERT IGNORE INTO db VALUES ('localhost','loncapa','www',
   97:     'Y','Y','Y','Y','Y','Y','N','Y','Y','Y'$extraargs);
   98: SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass');
   99: DELETE FROM user WHERE host<>'localhost';
  100: FLUSH PRIVILEGES;
  101: EXIT
  102: ENDMYSQLPERMISSIONINIT
  103:     $perlvar->{'lonSqlAccess'} = 'localhostkey';
  104: }
  105: 
  106: my $dbi_is_present = eval "use DBI;"; # will be defined on error
  107: if (defined($dbi_is_present)) {
  108:     print "Your system is misconfigured.  ".
  109:         "You are missing the perl DBI package\n";
  110:     exit 1;
  111: } else {
  112:     use DBI;
  113: }
  114: 
  115: my $dbh;
  116: my $MySQL_Check = eval '$dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar->{\'lonSqlAccess\'});';
  117: if (! defined($MySQL_Check)) {
  118:     if ($runstatus ne 'firstrun') {
  119:         print "Your system is misconfigured.\n";
  120:         exit 1;
  121:     }
  122:     #
  123:     # Try to install from the current directory.  
  124:     # This is potentially dangerous
  125:     my $install_result = system("rpm -Uvh $rpmname 2>/dev/null 1>/dev/null");
  126:     if (defined($install_result) && $install_result ne '0') {
  127:         print "Your system is misconfigured.  ".
  128:             "You are missing the perl DBD MySQL package\n";
  129:         exit 1;
  130:     }
  131:     exec "./".$0." secondrun";
  132: }
  133: 
  134: use DBI;
  135: $dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar->{'lonSqlAccess'});
  136: if (! defined($dbh)) {
  137:     die "Unable to connect to mysql database.\n";
  138: }
  139: $dbh->do(<<ENDDBINIT);
  140: CREATE TABLE IF NOT EXISTS metadata (title TEXT, 
  141:                                      author TEXT, 
  142:                                      subject TEXT, 
  143:                                      url TEXT, 
  144:                                      keywords TEXT, 
  145:                                      version TEXT, 
  146:                                      notes TEXT, 
  147:                                      abstract TEXT, 
  148:                                      mime TEXT, 
  149:                                      language TEXT, 
  150:                                      creationdate DATETIME, 
  151:                                      lastrevisiondate DATETIME, 
  152:                                      owner TEXT, 
  153:                                      copyright TEXT, 
  154:                                      FULLTEXT idx_title (title), 
  155:                                      FULLTEXT idx_author (author), 
  156:                                      FULLTEXT idx_subject (subject), 
  157:                                      FULLTEXT idx_url (url), 
  158:                                      FULLTEXT idx_keywords (keywords), 
  159:                                      FULLTEXT idx_version (version), 
  160:                                      FULLTEXT idx_notes (notes), 
  161:                                      FULLTEXT idx_abstract (abstract), 
  162:                                      FULLTEXT idx_mime (mime), 
  163:                                      FULLTEXT idx_language (language), 
  164:                                      FULLTEXT idx_owner (owner), 
  165:                                      FULLTEXT idx_copyright (copyright)
  166:                                      ) ENGINE=MYISAM
  167: ENDDBINIT
  168: 
  169: $dbh->do(<<ENDDBINIT);
  170: CREATE TABLE IF NOT EXISTS dynamicmetadata (url TEXT NOT NULL, 
  171:                                             count INT UNSIGNED,
  172:                                             num_uses INT UNSIGNED,
  173:                                             clear REAL UNSIGNED,
  174:                                             depth REAL UNSIGNED,
  175:                                             helpful REAL UNSIGNED,
  176:                                             correct REAL UNSIGNED,
  177:                                             technical REAL UNSIGNED,
  178:                                             avetries REAL UNSIGNED,
  179:                                             stdno INT UNSIGNED)
  180: 
  181: ENDDBINIT
  182: 
  183: if ($dbh->err) {
  184:     print "Error creating tables: ".$dbh->errstr()."\n";
  185: }
  186: $dbh->disconnect();
  187: 
  188: 

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