From 0384ae84eb65f4dce9617c73224096d300cbfc62 Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 5 Nov 2007 18:36:52 +0000 Subject: [PATCH] backporting PGPASSWORD addition and the settings tester script git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2@8004 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Application/Storage/Publisher/metabib.pm | 27 +- Open-ILS/src/sql/Pg/build-db.sh | 40 +-- Open-ILS/src/support-scripts/settings-tester.pl | 320 +++++++++++++++++++++ 3 files changed, 351 insertions(+), 36 deletions(-) create mode 100755 Open-ILS/src/support-scripts/settings-tester.pl diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm index 57acb40d7c..589e30087c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm @@ -1794,11 +1794,8 @@ sub postfilter_search_multi_class_fts { AND br.deleted IS FALSE AND cn.deleted IS FALSE AND cp.call_number = cn.id - AND ( cn.owning_lib = d.id - OR ( cp.circ_lib = d.id - AND cp.deleted IS FALSE - ) - ) + AND cp.circ_lib = d.id + AND cp.deleted IS FALSE $avail_filter LIMIT 1 ) @@ -2235,17 +2232,15 @@ sub biblio_search_multi_class_fts { FROM ($select) s LEFT OUTER JOIN $source_table src ON (s.source = src.id) WHERE EXISTS ( - SELECT 1 - FROM $asset_call_number_table cn, - $asset_copy_table cp, - $descendants d - WHERE cn.record = s.id - AND cp.call_number = cn.id - AND cn.deleted IS FALSE - AND ( cn.owning_lib = d.id - OR ( cp.circ_lib = d.id - AND cp.deleted IS FALSE - ) + SELECT 1 + FROM $asset_call_number_table cn, + $asset_copy_table cp, + $descendants d + WHERE cn.record = s.id + AND cp.call_number = cn.id + AND cn.deleted IS FALSE + AND cp.circ_lib = d.id + AND cp.deleted IS FALSE ) $avail_filter LIMIT 1 diff --git a/Open-ILS/src/sql/Pg/build-db.sh b/Open-ILS/src/sql/Pg/build-db.sh index 7a53b8565c..563a0ad60e 100755 --- a/Open-ILS/src/sql/Pg/build-db.sh +++ b/Open-ILS/src/sql/Pg/build-db.sh @@ -1,27 +1,27 @@ #!/bin/sh # args: {db-host} {db-port} {db-name} {db-user} {db-password} {db-version} -echo "You may be prompted several times for your database password..." +# echo "You may be prompted several times for your database password..." -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 000.english.pg$6.fts-config.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 001.schema.offline.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 002.schema.config.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 005.schema.actors.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 006.schema.permissions.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 006.data.permissions.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 010.schema.biblio.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 011.schema.authority.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 020.schema.functions.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 030.schema.metabib.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 040.schema.asset.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 070.schema.container.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 080.schema.money.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 090.schema.action.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 000.english.pg$6.fts-config.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 001.schema.offline.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 002.schema.config.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 005.schema.actors.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 006.schema.permissions.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 006.data.permissions.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 010.schema.biblio.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 011.schema.authority.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 020.schema.functions.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 030.schema.metabib.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 040.schema.asset.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 070.schema.container.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 080.schema.money.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 090.schema.action.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 500.view.cross-schema.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 500.view.cross-schema.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 800.fkeys.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 900.audit-functions.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 901.audit-tables.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 800.fkeys.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 900.audit-functions.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 901.audit-tables.sql -PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f reporter-schema.sql +PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f reporter-schema.sql diff --git a/Open-ILS/src/support-scripts/settings-tester.pl b/Open-ILS/src/support-scripts/settings-tester.pl new file mode 100755 index 0000000000..bb3c60ae43 --- /dev/null +++ b/Open-ILS/src/support-scripts/settings-tester.pl @@ -0,0 +1,320 @@ +#!/usr/bin/perl +# vim:noet:ts=4: + +BEGIN { + eval "use OpenSRF::Utils::Config;"; + die "Please ensure that /openils/lib/perl5 is in your PERL5LIB environment variable. + You must run this script as the 'opensrf' user.\n" if ($@); + eval "use Error qw/:try/;"; + die "Please install Error.pm.\n" if ($@); + eval "use UNIVERSAL::require;"; + die "Please install the UNIVERSAL::Require perl module.\n" if ($@); + eval "use Getopt::Long;"; + die "Please install the Getopt::Long perl module.\n" if ($@); + eval "use Net::Domain;"; + die "Please install the Net::Domain perl module.\n" if ($@); +} + +my $output = ''; +my $perloutput = ''; + +my ($gather, $hostname, $core_config, $tmpdir) = + (0, Net::Domain::hostfqdn(), '/openils/conf/opensrf_core.xml', '/tmp/'); + +GetOptions( + 'gather' => \$gather, + 'hostname=s' => \$hostname, + 'config_file=s' => \$core_config, + 'tempdir=s' => \$tmpdir, +); + +while (my $mod = ) { + chomp $mod; + my @list = split / /, $mod; + + my $ok = 0; + for my $m (@list) { + $ok++ if ($m->use); + print "$m version ".${$m."::VERSION"}."\n" unless ($@); + } + + unless ($ok) { + if (@list == 1) { + warn "Please install $mod\n"; + $perloutput .= "Please install the $mod Perl module.\n"; + } else { + warn "Please install one of the following modules: $mod\n"; + $perloutput .= "Please install one of the following modules: $mod\n"; + } + } + +} + +use OpenSRF::Transport::SlimJabber::Client; +use OpenSRF::Utils::SettingsParser; +use OpenSRF::Utils::SettingsClient; +use Data::Dumper; +use DBI; + +(my $conf_dir = $core_config) =~ s#(.*)/.*#$1#; + + +OpenSRF::Utils::Config->load(config_file => $core_config); +my $conf = OpenSRF::Utils::Config->current; +my $j_username = $conf->bootstrap->username; +my $j_password = $conf->bootstrap->passwd; +my $j_port = $conf->bootstrap->port; +my $j_domain = $conf->bootstrap->domains->[0]; +my $settings_config = $conf->bootstrap->settings_config; +my $logfile = $conf->bootstrap->logfile; +(my $log_dir = $logfile) =~ s#(.*)/.*#$1#; + + +print "\nChecking Jabber connection\n"; +# connect to jabber +my $client = OpenSRF::Transport::SlimJabber::Client->new( + port => $j_port, + username => $j_username, + password => $j_password, + host => $j_domain, + resource => 'test123' +); + + +my $je = undef; +try { + unless($client->initialize()) { + $je = "* Unable to connect to jabber server $j_domain\n"; + warn "* Unable to connect to jabber server $j_domain\n"; + } +} catch Error with { + $je = "* Error connecting to jabber:\n" . shift() . "\n"; + warn "* Error connecting to jabber:\n" . shift() . "\n"; +}; + +print "* Jabber successfully connected\n" unless ($je); +$output .= ($je) ? $je : "* Jabber successfully connected\n"; + +my $xmlparser = XML::LibXML->new(); +my $osrfxml = $xmlparser->parse_file($settings_config); + +print "\nChecking database connections\n"; +# Check database connections +my @databases = $osrfxml->findnodes('//database'); +foreach my $database (@databases) { + my $db_name = $database->findvalue("./db"); + if (!$db_name) { + $db_name = $database->findvalue("./name"); + } + my $db_host = $database->findvalue("./host"); + my $db_port = $database->findvalue("./port"); + my $db_user = $database->findvalue("./user"); + my $db_pw = $database->findvalue("./pw"); + my $osrf_xpath; + foreach my $node ($database->findnodes("ancestor::node()")) { + next unless $node->nodeType == XML::LibXML::XML_ELEMENT_NODE; + $osrf_xpath .= "/" . $node->nodeName; + } + $output .= test_db_connect($db_name, $db_host, $db_port, $db_user, $db_pw, $osrf_xpath); +} + +print "\nChecking database drivers to ensure matches \n"; +# Check database drivers +# if language eq 'C', driver eq 'pgsql' +# if language eq 'perl', driver eq 'Pg' +my @drivers = $osrfxml->findnodes('//driver'); +foreach my $driver_node (@drivers) { + my $language; + my $driver_xpath; + my @driver_xpath_nodes; + foreach my $node ($driver_node->findnodes("ancestor::node()")) { + next unless $node->nodeType == XML::LibXML::XML_ELEMENT_NODE; + $driver_xpath .= "/" . $node->nodeName; + push @driver_xpath_nodes, $node->nodeName; + } + my $lang_xpath; + my $driver = $driver_node->findvalue("child::text()"); + while (pop(@driver_xpath_nodes) && scalar(@driver_xpath_nodes) > 0 && !$language) { + $lang_xpath = "/" . join('/', @driver_xpath_nodes) . "/language"; + my @lang_nodes = $osrfxml->findnodes($lang_xpath); + next unless scalar(@lang_nodes > 0); + $language = $lang_nodes[0]->findvalue("child::text()"); + } + my $result; + if ($driver eq "pgsql") { + if ($language eq "C") { + $result = "* OK: $driver language is $language in $lang_xpath\n"; + } else { + $result = "* ERROR: $driver language is $language in $lang_xpath\n"; + warn $result; + } + } elsif ($driver eq "Pg") { + if ($language eq "perl") { + $result = "* OK: $driver language is $language in $lang_xpath\n"; + } elsif ($driver_xpath =~ /reporter/) { + $result = "* OK: $driver language is undefined for reporter base configuration\n"; + } else { + $result = "* ERROR: $driver language is $language in $lang_xpath\n"; + warn $result; + } + } else { + $result = "* ERROR: Unknown driver $driver in $driver_xpath\n"; + warn $result; + } + print $result; + $output .= $result; +} + +print "\nChecking libdbi and libdbi-drivers\n"; +$output .= check_libdbd(); + +print "\nChecking hostname\n"; +my @hosts = $osrfxml->findnodes('/opensrf/hosts/*'); +foreach my $host (@hosts) { + next unless $host->nodeType == XML::LibXML::XML_ELEMENT_NODE; + my $osrfhost = $host->nodeName; + my $he; + if ($osrfhost ne $hostname && $osrfhost ne "localhost") { + $result = " * ERROR: expected hostname '$hostname', found '$osrfhost' in section of opensrf.xml\n"; + warn $result; + $he = 1; + } elsif ($osrfhost eq "localhost") { + $result = " * OK: found hostname 'localhost' in section of opensrf.xml\n"; + } else { + $result = " * OK: found hostname '$hostname' in section of opensrf.xml\n"; + } + print $result unless $he; + $output .= $result; +} + + +if ($gather) { + get_debug_info( $tmpdir, $log_dir, $conf_dir, $perloutput, $output ); +} + +sub test_db_connect { + my ($db_name, $db_host, $db_port, $db_user, $db_pw, $osrf_xpath) = @_; + + my $dsn = "dbi:Pg:dbname=$db_name;host=$db_host;port=$db_port"; + my $de = undef; + my $dbh, $encoding; + try { + $dbh = DBI->connect($dsn, $db_user, $db_pw); + unless($dbh) { + $de = "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n"; + warn "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n"; + } + my $sth = $dbh->prepare("show server_encoding"); + $sth->execute; + $sth->bind_col(1, \$encoding); + $sth->fetch; + $sth->finish; + $dbh->disconnect; + } catch Error with { + $de = "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n" . shift() . "\n"; + warn "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n" . shift() . "\n"; + }; + print "* $osrf_xpath :: Successfully connected to database $dsn\n" unless ($de); + if ($encoding !~ m/(utf-?8|unicode)/i) { + $de .= "* ERROR: $osrf_xpath :: Database $dsn has encoding $encoding instead of UTF8 or UNICODE.\n"; + warn "* ERROR: $osrf_xpath :: Database $dsn has encoding $encoding instead of UTF8 or UNICODE.\n"; + } else { + print " * Database has the expected server encoding $encoding.\n"; + } + return ($de) ? $de : "* $osrf_xpath :: Successfully connected to database $dsn with encoding $encoding\n"; + +} + +sub check_libdbd { + my $results; + my $de = undef; + my @location = `locate libdbdpgsql.so |grep -v home`; # simple(ton) attempt to filter out build versions + if (scalar(@location) > 1) { + + my $res = "Found more than one location for libdbdpgsql.so. + We have found that system packages don't link against libdbi.so; + therefore, we strongly recommend compiling libdbi and libdbi-drivers from source.\n"; + $results .= $res; + print $res; + } + foreach my $loc (@location) { + my @linkage = `ldd $loc`; + if (!grep(/libdbi/, @linkage)) { + my $res = "$loc was not linked against libdbi - you probably need to compile libdbi-drivers from source with the --enable-libdbi configure switch.\n"; + $results .= $res; + print $res; + } + } + return $results; +} + +sub get_debug_info { + my $temp_dir = shift; # place we can write files + my $log = shift; # location of the log directory + my $config = shift; # location of the config files + my $perl_test = shift; # output from the Perl prereq testing + my $config_test = shift; # output from the config file testing + + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + my $oils_time = sprintf("%04d-%02d-%02d_%02dh-%02d-%02d", $year+1900, $mon, $mday, $hour, $min, $sec); + + # evil approach that requires no other Perl dependencies + chdir($temp_dir); + my $oils_debug_dir = "$temp_dir/oils_$oils_time"; + + # Replace with something Perlish + mkdir($oils_debug_dir) or die $!; + + # Replace with File::Copy + system("cp $log/*log $oils_debug_dir"); + + # Passwords will go through in the clear for now + system("cp $config/*xml $oils_debug_dir"); + + # Get Perl output + open(FH, ">", "$oils_debug_dir/perl_test.out") or die $!; + print FH $perl_test; + close(FH); + + # Get XML output + open(FH, ">", "$oils_debug_dir/xml_test.out") or die $!; + print FH $config_test; + close(FH); + + # Tar this up - does any system not have tar? + system("tar czf oils_$oils_time.tar.gz oils_$oils_time"); + + # Clean up after ourselves, somewhat dangerously + system("rm -fr $oils_debug_dir"); + + print "Wrote your debug information to $temp_dir/oils_$oils_time.tar.gz.\n"; +} + +__DATA__ +LWP::UserAgent +XML::LibXML +XML::LibXSLT +Net::Server::PreFork +Cache::Memcached +Class::DBI +Class::DBI::AbstractSearch +Template +DBD::Pg +Net::Z3950 Net::Z3950::ZOOM +MARC::Record +MARC::Charset +MARC::File::XML +Text::Aspell +CGI +DateTime::TimeZone +DateTime +DateTime::Format::ISO8601 +Unix::Syslog +GD::Graph3d +JavaScript::SpiderMonkey +Log::Log4perl +Email::Send +Text::CSV +Text::CSV_XS +Spreadsheet::WriteExcel::Big +Tie::IxHash -- 2.11.0