[Midnightbsd-cvs] mports: magus.pl: Try to recover from a dropped DB connection.
ctriv at midnightbsd.org
ctriv at midnightbsd.org
Tue Sep 9 11:46:51 EDT 2008
Log Message:
-----------
Try to recover from a dropped DB connection.
Don't use /usr/mports for the loopback, set up a mports tree in
/usr/magus/slave-data.
Don't flush locks on a machine level. This is in anticipation of running
more than one magus process on a machine.
Modified Files:
--------------
mports/Tools/magus/slave:
magus.pl (r1.19 -> r1.20)
-------------- next part --------------
Index: magus.pl
===================================================================
RCS file: /home/cvs/mports/Tools/magus/slave/magus.pl,v
retrieving revision 1.19
retrieving revision 1.20
diff -L Tools/magus/slave/magus.pl -L Tools/magus/slave/magus.pl -u -r1.19 -r1.20
--- Tools/magus/slave/magus.pl
+++ Tools/magus/slave/magus.pl
@@ -48,8 +48,33 @@
my @origARGV = @ARGV;
my $self = '/usr/mports/Tools/magus/slave/magus.pl';
+my $Lock;
-main();
+while (1) {
+ eval {
+ main();
+ exit(0);
+ };
+
+ if ($@) {
+ # Check ping in case a dropped DB caused some other exception.
+ if ($@ =~ m/DBI/ || !Magus::DBI->ping) {
+ while (1) {
+ report(err => "Could not connect to database ($@) waiting $Magus::Config{'DoneWaitPeriod'} seconds");
+ sleep($Magus::Config{'DoneWaitPeriod'});
+ last if Magus::DBI->ping;
+ }
+
+ if ($Lock) {
+ $Lock->port->reset;
+ $Lock->delete;
+ }
+ # back up to the main() call we go.
+ } else {
+ die $@;
+ }
+ }
+}
=head1 magus.pl
@@ -102,6 +127,9 @@
next;
}
+ # stick the current lock in the global, so we can flush it if need be.
+ $Lock = $lock;
+
report('info', "Starting test run for: %s", $lock->port);
run_test($lock);
@@ -109,6 +137,7 @@
report('info', 'Run completed for: %s', $lock->port);
$lock->delete;
+ undef $Lock;
}
}
@@ -117,13 +146,15 @@
=head3 Exiting
Note that all the locks associated with this machine will be deleted at
-script exit. If you are running two copies of this script on one machine,
-make sure to assign them different machine IDs in the master database.
+script exit.
=cut
END {
- Magus::Lock->search(machine => $Magus::Machine)->delete_all;
+ if ($Lock) {
+ $Lock->port->reset;
+ $Lock->delete;
+ }
}
@@ -181,7 +212,7 @@
insert_results($port, $results);
};
- if ($@) {
+ if ($@ && $@ !~ m/DBI/) {
handle_exception($@, $lock);
}
@@ -373,11 +404,11 @@
sub handle_exception {
my ($error, $lock) = @_;
+
+ die $error if $error =~ m/DBI/;
if ($error =~ m/SIGINT/) {
- $lock->port->events->delete_all;
- $lock->port->status('untested');
- $lock->port->update;
+ $lock->port->reset;
report('debug', 'Exiting 0 from SIGINT (prior result for %s deleted).', $lock->port);
exit 0;
@@ -397,7 +428,7 @@
sub get_current_run {
my $current = Magus::Run->latest($Magus::Machine) || return;
- my $tree_id = get_tree_id('/usr/mports') || 0;
+ my $tree_id = get_tree_id("$Magus::Config{'SlaveDataDir'}/mports") || 0;
if ($current != $Magus::Machine->run || $tree_id != $current) {
$Magus::Machine->run($current);
@@ -406,21 +437,24 @@
my $tarball = $current->tarballpath;
report(debug => "Downloading tree ID $current: $tarball");
+
+ my $dir = $Magus::Config{'SlaveDataDir'} || die "SlaveDataDir is not set!\n";
- chdir('/usr');
+ mkdir($dir);
+ chdir($dir) || die "Couldn't chdir to $dir: $!\n";
if (system("/usr/bin/fetch -p $tarball") != 0) {
die "Couldn't fetch $tarball";
}
-
- report(debug => "Deleting old /usr/mports");
- rmtree('/usr/mports');
-
+ report(debug => "Deleting old $dir/mports");
+ rmtree('$dir/mports');
report(debug => "Extracting %s", $current->tarball);
system('/usr/bin/tar xf ' . $current->tarball);
-
+
+ unlink($current->tarball);
+
report(debug => "Reloading self.");
exec($self, @origARGV);
}
More information about the Midnightbsd-cvs
mailing list