From cbcfdf9c54e4436d8e72600cdcb6ad6e97d88607 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra
Date: Fri, 28 Nov 2008 14:36:04 +0000
Subject: [PATCH] * $HYDRA_DATA environment variable.
---
src/Hydra/lib/Hydra.pm | 8 +++++--
src/Hydra/lib/Hydra/Controller/Root.pm | 2 +-
src/Hydra/lib/Hydra/Helper/Nix.pm | 29 ++++++++++++++++++++++++--
src/Hydra/lib/Hydra/Model/DB.pm | 6 ++----
src/Hydra/programs/Build.pl | 11 ++--------
src/Hydra/programs/Runner.pl | 22 ++++++++++++-------
src/Hydra/programs/Scheduler.pl | 11 ++--------
src/Hydra/root/product-list.tt | 8 ++++++-
8 files changed, 61 insertions(+), 36 deletions(-)
diff --git a/src/Hydra/lib/Hydra.pm b/src/Hydra/lib/Hydra.pm
index d636d06e..f9d23e6c 100644
--- a/src/Hydra/lib/Hydra.pm
+++ b/src/Hydra/lib/Hydra.pm
@@ -2,6 +2,7 @@ package Hydra;
use strict;
use warnings;
+use Hydra::Helper::Nix;
use Catalyst::Runtime '5.70';
@@ -20,8 +21,11 @@ our $VERSION = '0.01';
__PACKAGE__->config(
name => 'Hydra',
- default_view => "TT"
- );
+ default_view => "TT",
+ session => {
+ storage => getHydraPath . "/session_data"
+ }
+);
__PACKAGE__->setup();
diff --git a/src/Hydra/lib/Hydra/Controller/Root.pm b/src/Hydra/lib/Hydra/Controller/Root.pm
index 99ca01c1..ca88f4a6 100644
--- a/src/Hydra/lib/Hydra/Controller/Root.pm
+++ b/src/Hydra/lib/Hydra/Controller/Root.pm
@@ -751,7 +751,7 @@ sub closure :Local {
return error($c, "Product is not a Nix build.") if $product->type ne "nix-build";
- return error($c, "Path " . $product->path . " is no longer available.") unless Hydra::Helper::Nix::isValidPath($product->path);
+ return error($c, "Path " . $product->path . " is no longer available.") unless isValidPath($product->path);
$c->stash->{current_view} = 'Hydra::View::NixClosure';
$c->stash->{storePath} = $product->path;
diff --git a/src/Hydra/lib/Hydra/Helper/Nix.pm b/src/Hydra/lib/Hydra/Helper/Nix.pm
index 9c8df095..3b928803 100644
--- a/src/Hydra/lib/Hydra/Helper/Nix.pm
+++ b/src/Hydra/lib/Hydra/Helper/Nix.pm
@@ -1,14 +1,39 @@
package Hydra::Helper::Nix;
use strict;
+use Exporter;
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(isValidPath getHydraPath getHydraDBPath openHydraDB);
sub isValidPath {
my $path = shift;
$SIG{CHLD} = 'DEFAULT'; # !!! work around system() failing if SIGCHLD is ignored
- return system("nix-store --check-validity $path") == 0;
+ return system("nix-store --check-validity $path 2> /dev/null") == 0;
+}
+
+
+sub getHydraPath {
+ my $dir = $ENV{HYDRA_DATA};
+ die "The HYDRA_DATA environment variable is not set!\n" unless defined $dir;
+ die "The HYDRA_DATA directory does not exist!\n" unless -d $dir;
+ return $dir;
+}
+
+
+sub getHydraDBPath {
+ my $path = getHydraPath . '/hydra.sqlite';
+ die "The Hydra database ($path) not exist!\n" unless -f $path;
+ return "dbi:SQLite:$path";
+}
+
+
+sub openHydraDB {
+ my $db = Hydra::Schema->connect(getHydraDBPath, "", "", {});
+ $db->storage->dbh->do("PRAGMA synchronous = OFF;");
+ return $db;
}
1;
-
diff --git a/src/Hydra/lib/Hydra/Model/DB.pm b/src/Hydra/lib/Hydra/Model/DB.pm
index 945b6202..c7d31bfa 100644
--- a/src/Hydra/lib/Hydra/Model/DB.pm
+++ b/src/Hydra/lib/Hydra/Model/DB.pm
@@ -2,13 +2,11 @@ package Hydra::Model::DB;
use strict;
use base 'Catalyst::Model::DBIC::Schema';
+use Hydra::Helper::Nix;
__PACKAGE__->config(
schema_class => 'Hydra::Schema',
- connect_info => [
- 'dbi:SQLite:../hydra.sqlite',
-
- ],
+ connect_info => [getHydraDBPath],
);
=head1 NAME
diff --git a/src/Hydra/programs/Build.pl b/src/Hydra/programs/Build.pl
index fc4e2b14..0a13239b 100644
--- a/src/Hydra/programs/Build.pl
+++ b/src/Hydra/programs/Build.pl
@@ -4,17 +4,10 @@ use strict;
use File::Basename;
use File::stat;
use Hydra::Schema;
+use Hydra::Helper::Nix;
-my $db = Hydra::Schema->connect("dbi:SQLite:dbname=hydra.sqlite", "", "", {});
-
-$db->storage->dbh->do("PRAGMA synchronous = OFF;");
-
-
-sub isValidPath {
- my $path = shift;
- return system("nix-store --check-validity $path 2> /dev/null") == 0;
-}
+my $db = openHydraDB;
sub doBuild {
diff --git a/src/Hydra/programs/Runner.pl b/src/Hydra/programs/Runner.pl
index 2fb76b63..429ff109 100644
--- a/src/Hydra/programs/Runner.pl
+++ b/src/Hydra/programs/Runner.pl
@@ -2,13 +2,17 @@
use strict;
use Cwd;
+use File::Basename;
use POSIX qw(dup2);
use Hydra::Schema;
+use Hydra::Helper::Nix;
-my $db = Hydra::Schema->connect("dbi:SQLite:dbname=hydra.sqlite", "", "", {});
+chdir getHydraPath or die;
+my $db = openHydraDB;
-$db->storage->dbh->do("PRAGMA synchronous = OFF;");
+my $hydraHome = $ENV{"HYDRA_HOME"};
+die "The HYDRA_HOME environment variable is not set!\n" unless defined $hydraHome;
sub unlockDeadBuilds {
@@ -69,6 +73,7 @@ sub checkBuilds {
foreach my $build (@builds) {
my $logfile = getcwd . "/logs/" . $build->id;
+ mkdir(dirname $logfile);
unlink($logfile);
$build->schedulingInfo->busy(1);
$build->schedulingInfo->locker($$);
@@ -91,12 +96,13 @@ sub checkBuilds {
my $child = fork();
die unless defined $child;
if ($child == 0) {
- open LOG, ">$logfile" or die;
- POSIX::dup2(fileno(LOG), 1) or die;
- POSIX::dup2(fileno(LOG), 2) or die;
- exec("perl", "-IHydra/lib", "-w",
- "./Hydra/programs/Build.pl", $id);
- warn "cannot start build " . $id;
+ eval {
+ open LOG, ">$logfile" or die "cannot create logfile $logfile";
+ POSIX::dup2(fileno(LOG), 1) or die;
+ POSIX::dup2(fileno(LOG), 2) or die;
+ exec("perl", "-I$hydraHome/lib", "-w", "$ENV{'HYDRA_HOME'}/programs/Build.pl", $id);
+ };
+ warn "cannot start build $id: $@";
POSIX::_exit(1);
}
};
diff --git a/src/Hydra/programs/Scheduler.pl b/src/Hydra/programs/Scheduler.pl
index 231cf315..146df3b2 100644
--- a/src/Hydra/programs/Scheduler.pl
+++ b/src/Hydra/programs/Scheduler.pl
@@ -3,19 +3,12 @@
use strict;
use XML::Simple;
use Hydra::Schema;
+use Hydra::Helper::Nix;
use IPC::Run;
use POSIX qw(strftime);
-my $db = Hydra::Schema->connect("dbi:SQLite:dbname=hydra.sqlite", "", "", {});
-
-$db->storage->dbh->do("PRAGMA synchronous = OFF;");
-
-
-sub isValidPath {
- my $path = shift;
- return system("nix-store --check-validity $path 2> /dev/null") == 0;
-}
+my $db = openHydraDB;
sub captureStdoutStderr {
diff --git a/src/Hydra/root/product-list.tt b/src/Hydra/root/product-list.tt
index a50b00ce..f85570be 100644
--- a/src/Hydra/root/product-list.tt
+++ b/src/Hydra/root/product-list.tt
@@ -26,7 +26,13 @@
$ curl [% c.uri_for('/closure' build.id product.productnr) %] | gunzip | nix-store --import
The package can then be found in the path [%
- product.path %]. If you get the error message “imported
+ product.path %]. You’ll probably also want to do
+
+
nix-env -i [% product.path %]
+
+ to actually install the package in your Nix user environment.
+
+ If you get the error message “imported
archive lacks a signature”, you should make sure that you have
sufficient access rights to the Nix store, e.g., run the
command as root.