6 #FIXME: use Test::More or any kind of Test module instead of eval/die if
9 eval "use OpenSRF::Utils::Config;";
10 die "Please ensure that /openils/lib/perl5 is in your PERL5LIB environment variable.
11 You must run this script as the 'opensrf' user.\n" if ($@);
12 eval "use Error qw/:try/;";
13 die "Please install Error.pm.\n" if ($@);
14 eval "use UNIVERSAL::require;";
15 die "Please install the UNIVERSAL::require perl module.\n" if ($@);
16 eval "use Getopt::Long;";
17 die "Please install the Getopt::Long perl module.\n" if ($@);
18 eval "use Net::Domain;";
19 die "Please install the Net::Domain perl module.\n" if ($@);
26 my ($gather, $hostname, $core_config, $tmpdir) =
27 (0, Net::Domain::hostfqdn(), '/openils/conf/opensrf_core.xml', '/tmp/');
31 'hostname=s' => \$hostname,
32 'config_file=s' => \$core_config,
33 'tempdir=s' => \$tmpdir,
36 while (my $mod = <DATA>) {
38 my @list = split / /, $mod;
44 my $version = $m->VERSION;
45 print "$m version $version\n" if ($version);
51 warn "Please install $mod\n";
52 $perloutput .= "Please install the $mod Perl module.\n";
54 warn "Please install one of the following modules: $mod\n";
55 $perloutput .= "Please install one of the following modules: $mod\n";
61 use OpenSRF::Transport::SlimJabber::Client;
62 use OpenSRF::Utils::SettingsParser;
63 use OpenSRF::Utils::SettingsClient;
67 (my $conf_dir = $core_config) =~ s#(.*)/.*#$1#;
68 OpenSRF::Utils::Config->load(config_file => $core_config);
69 my $conf = OpenSRF::Utils::Config->current;
70 my $settings_config = $conf->bootstrap->settings_config;
71 my $logfile = $conf->bootstrap->logfile;
72 (my $log_dir = $logfile) =~ s#(.*)/.*#$1#;
74 my $xmlparser = XML::LibXML->new();
75 my $confxml = $xmlparser->parse_file($core_config);
76 my $confxpc = XML::LibXML::XPathContext->new($confxml);
78 foreach my $section (qw/opensrf gateway/) {
79 my $j_username = $confxpc->find("/config/$section/username");
80 my $j_password = $confxpc->find("/config/$section/passwd");
81 my $j_port = $confxpc->find("/config/$section/port");
82 # We should check for a domains element to catch likely upgrade errors
83 my $j_domain = $confxpc->find("/config/$section/domain");
84 check_jabber($j_username, $j_password, $j_domain, $j_port);
87 my @routers = $confxpc->findnodes("/config/routers/router");
88 foreach my $router (@routers) {
89 my $j_username = $router->findvalue("./transport/username");
90 my $j_password = $router->findvalue("./transport/password");
91 my $j_port = $router->findvalue("./transport/port");
92 # We should check for a domains element to catch likely upgrade errors
93 my $j_domain = $router->findvalue("./transport/server");
94 check_jabber($j_username, $j_password, $j_domain, $j_port);
97 my $osrfxml = $xmlparser->parse_file($settings_config);
98 print "\nChecking database connections\n";
99 # Check database connections
100 my @databases = $osrfxml->findnodes('//database');
102 # If we have no database connections, this is probably the OpenSRF version
105 my $de = "* WARNING: There are no database connections defined in " .
106 "opensrf.xml. These are defined in services such as " .
107 "open-ils.cstore and open-ils.reporter. Please ensure that " .
108 "your opensrf_core.xml and opensrf.xml configuration files " .
109 "are based on the examples shipped with Evergreen instead of " .
115 foreach my $database (@databases) {
116 my $db_name = $database->findvalue("./db");
118 $db_name = $database->findvalue("./name");
120 my $db_host = $database->findvalue("./host");
121 my $db_port = $database->findvalue("./port");
122 my $db_user = $database->findvalue("./user");
123 my $db_pw = $database->findvalue("./pw");
124 if (!$db_pw && $database->parentNode->parentNode->nodeName eq 'reporter') {
125 $db_pw = $database->findvalue("./password");
127 my $de = "* WARNING: Deprecated <password> element used for the " .
128 "<reporter> entry. Please use <pw> instead.\n";
135 foreach my $node ($database->findnodes("ancestor::node()")) {
136 next unless $node->nodeType == XML::LibXML::XML_ELEMENT_NODE;
137 $osrf_xpath .= "/" . $node->nodeName;
139 $output .= test_db_connect($db_name, $db_host, $db_port, $db_user, $db_pw, $osrf_xpath);
142 print "\nChecking database drivers to ensure <driver> matches <language>\n";
143 # Check database drivers
144 # if language eq 'C', driver eq 'pgsql'
145 # if language eq 'perl', driver eq 'Pg'
146 my @drivers = $osrfxml->findnodes('//driver');
147 foreach my $driver_node (@drivers) {
150 my @driver_xpath_nodes;
151 foreach my $node ($driver_node->findnodes("ancestor::node()")) {
152 next unless $node->nodeType == XML::LibXML::XML_ELEMENT_NODE;
153 $driver_xpath .= "/" . $node->nodeName;
154 push @driver_xpath_nodes, $node->nodeName;
157 my $driver = $driver_node->findvalue("child::text()");
158 while (pop(@driver_xpath_nodes) && scalar(@driver_xpath_nodes) > 0 && !$language) {
159 $lang_xpath = "/" . join('/', @driver_xpath_nodes) . "/language";
160 my @lang_nodes = $osrfxml->findnodes($lang_xpath);
161 next unless scalar(@lang_nodes > 0);
162 $language = $lang_nodes[0]->findvalue("child::text()");
164 if ($driver eq "pgsql") {
165 if ($driver_xpath =~ m#/reporter/#) {
166 $result = "* ERROR: reporter application must use driver 'Pg', but '$driver' is defined\n";
168 } elsif ($language eq "C") {
169 $result = "* OK: $driver language is $language in $lang_xpath\n";
171 $result = "* ERROR: $driver language is $language in $lang_xpath\n";
174 } elsif ($driver eq "Pg") {
175 if ($driver_xpath =~ m#/reporter/#) {
176 $result = "* OK: $driver language is undefined for reporter base configuration\n";
177 } elsif ($language eq "perl") {
178 $result = "* OK: $driver language is $language in $lang_xpath\n";
180 $result = "* ERROR: $driver language is $language in $lang_xpath\n";
184 $result = "* ERROR: Unknown driver $driver in $driver_xpath\n";
191 print "\nChecking libdbi and libdbi-drivers\n";
192 $output .= check_libdbd();
194 print "\nChecking hostname\n";
195 my @hosts = $osrfxml->findnodes('/opensrf/hosts/*');
196 foreach my $host (@hosts) {
197 next unless $host->nodeType == XML::LibXML::XML_ELEMENT_NODE;
198 my $osrfhost = $host->nodeName;
200 if ($osrfhost ne $hostname && $osrfhost ne "localhost") {
201 $result = " * ERROR: expected hostname '$hostname', found '$osrfhost' in <hosts> section of opensrf.xml\n";
204 } elsif ($osrfhost eq "localhost") {
205 $result = " * OK: found hostname 'localhost' in <hosts> section of opensrf.xml\n";
207 $result = " * OK: found hostname '$hostname' in <hosts> section of opensrf.xml\n";
209 print $result unless $he;
213 # Check for oils_web.xml, required for acquisitions and many administration
214 # interfaces as of Evergreen 1.6
215 if (!-T '/openils/conf/oils_web.xml') {
216 my $de = "* WARNING: As of Evergreen 1.6, /openils/conf/oils_web.xml " .
217 "is a required configuration file. Copying " .
218 "/openils/conf/oils_web.xml.example should resolve this " .
226 get_debug_info( $tmpdir, $log_dir, $conf_dir, $perloutput, $output );
229 sub test_db_connect {
230 my ($db_name, $db_host, $db_port, $db_user, $db_pw, $osrf_xpath) = @_;
232 my $dsn = "dbi:Pg:dbname=$db_name;host=$db_host;port=$db_port";
234 my ($dbh, $encoding, $langs);
235 $dbh = DBI->connect($dsn, $db_user, $db_pw);
237 # Short-circuit if we didn't connect successfully
239 $de = "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n";
240 warn "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n";
244 # Get server encoding
245 my $sth = $dbh->prepare("SHOW server_encoding");
247 $sth->bind_col(1, \$encoding);
251 # Get list of server languages
252 $sth = $dbh->prepare("SELECT lanname FROM pg_catalog.pg_language");
254 $langs = $sth->fetchall_arrayref([0]);
258 print "* $osrf_xpath :: Successfully connected to database $dsn\n" unless ($de);
261 if ($encoding !~ m/(utf-?8|unicode)/i) {
262 $de .= "* ERROR: $osrf_xpath :: Database $dsn has encoding $encoding instead of UTF8 or UNICODE.\n";
263 warn "* ERROR: $osrf_xpath :: Database $dsn has encoding $encoding instead of UTF8 or UNICODE.\n";
265 print " * Database has the expected server encoding $encoding.\n";
268 my $result = check_db_langs($langs);
274 return ($de) ? $de : "* $osrf_xpath :: Successfully connected to database $dsn with encoding $encoding\n";
283 # Ensure the following PostgreSQL languages have been enabled
290 foreach my $lang (@$langs) {
291 my $lower = lc($$lang[0]);
292 $languages{$lower} = 1;
295 foreach my $lang (keys %languages) {
296 if (!$languages{$lang}) {
297 $errors .= " * ERROR: Language '$lang' is not enabled in the target database\n";
305 my ($j_username, $j_password, $j_domain, $j_port) = @_;
306 print "\nChecking Jabber connection for user $j_username, domain $j_domain\n";
309 my $client = OpenSRF::Transport::SlimJabber::Client->new(
311 username => $j_username,
312 password => $j_password,
314 resource => 'test123'
320 unless($client->initialize()) {
321 $je = "* Unable to connect to jabber server $j_domain\n";
322 warn "* Unable to connect to jabber server $j_domain\n";
325 $je = "* Error connecting to jabber:\n" . shift() . "\n";
326 warn "* Error connecting to jabber:\n" . shift() . "\n";
329 print "* Jabber successfully connected\n" unless ($je);
330 $output .= ($je) ? $je : "* Jabber successfully connected\n";
335 my @location = `/sbin/ldconfig --print | grep libdbdpgsql`; # simple(ton) attempt to filter out build versions
337 # This is pretty distro-specific, but let's worry about other distros and operating systems when we get there
338 my $res = "libdbi PostgreSQL driver not found in shared library path;
339 you may need to edit /etc/ld.so.conf or add an entry to /etc/ld.so.conf.d/
340 and run 'ldconfig' as root\n";
344 if ($location[0] !~ m#/usr/local/lib/dbd/#) {
345 my $res = "libdbdpgsql.so was not found in /usr/local/libdbi/dbd/
346 We have found that system packages don't link against libdbi.so;
347 therefore, we strongly recommend compiling libdbi and libdbi-drivers from source.\n";
351 if ($results eq '') {
352 $results = " * OK - found locally installed libdbi.so and libdbdpgsql.so in shared library path\n";
359 my $temp_dir = shift; # place we can write files
360 my $log = shift; # location of the log directory
361 my $config = shift; # location of the config files
362 my $perl_test = shift; # output from the Perl prereq testing
363 my $config_test = shift; # output from the config file testing
365 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
366 my $oils_time = sprintf("%04d-%02d-%02d_%02dh-%02d-%02d", $year+1900, $mon, $mday, $hour, $min, $sec);
368 # evil approach that requires no other Perl dependencies
370 my $oils_debug_dir = "$temp_dir/oils_$oils_time";
372 # Replace with something Perlish
373 mkdir($oils_debug_dir) or die $!;
375 # Replace with File::Copy
376 system("cp $log/*log $oils_debug_dir");
378 # Passwords will go through in the clear for now
379 system("cp $config/*xml $oils_debug_dir");
382 open(FH, ">", "$oils_debug_dir/perl_test.out") or die $!;
387 open(FH, ">", "$oils_debug_dir/xml_test.out") or die $!;
388 print FH $config_test;
391 # Tar this up - does any system not have tar?
392 system("tar czf oils_$oils_time.tar.gz oils_$oils_time");
394 # Clean up after ourselves, somewhat dangerously
395 system("rm -fr $oils_debug_dir");
397 print "Wrote your debug information to $temp_dir/oils_$oils_time.tar.gz.\n";
403 XML::LibXML::XPathContext
408 Class::DBI::AbstractSearch
411 Net::Z3950 Net::Z3950::ZOOM
419 DateTime::Format::ISO8601
420 DateTime::Format::Mail
423 JavaScript::SpiderMonkey
428 Spreadsheet::WriteExcel::Big