Archived
1
0
forked from rarias/bscpkgs

WIP isolate execution

This commit is contained in:
2020-10-05 16:40:22 +02:00
parent 896ebd4ace
commit 2a01ee7f24
12 changed files with 145 additions and 65 deletions

View File

@@ -0,0 +1,30 @@
{
stdenv
, nixtools
, busybox
}:
{
program
, nixPrefix
, clusterName
}:
stdenv.mkDerivation {
name = "isolate";
preferLocalBuild = true;
phases = [ "unpackPhase" "installPhase" ];
src = ./.;
dontPatchShebangs = true;
programPath = "/bin/stage1";
inherit program nixPrefix clusterName nixtools busybox;
out = "$out";
installPhase = ''
substituteAllInPlace stage1
substituteAllInPlace stage2
mkdir -p $out/bin
cp stage* $out/bin/
chmod +x $out/bin/stage*
'';
}

View File

@@ -0,0 +1,23 @@
#!/bin/sh -ex
>&2 echo Running isolate stage1
>&2 echo PATH=$PATH
if [ -e /nix ]; then
>&2 echo "/nix found, aborting"
exit 1
fi
nixhome="@nixPrefix@/nix"
shell="@busybox@/bin/sh"
nixjoin="@nixPrefix@@nixtools@/bin/nix-join"
#-m @nixPrefix@ \
join_flags="
-m /etc \
-m /var/run/munge \
-m /gpfs/projects/bsc15 \
-m /bin:@nixPrefix@@busybox@/bin"
exec $nixjoin -i $join_flags $nixhome -- @out@/bin/stage2

View File

@@ -0,0 +1,16 @@
#!/bin/sh -ex
>&2 echo Running isolate stage2
>&2 echo PATH=$PATH
if [ ! -e /nix ]; then
>&2 echo "/nix not found, aborting"
exit 1
fi
if [ -e /usr ]; then
>&2 echo "Environment not isolated, aborting"
exit 1
fi
exec @program@

View File

@@ -13,6 +13,7 @@ stdenv.mkDerivation {
apps = apps;
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
dontPatchShebangs = true;
programPath = "/bin/run";
src = ./.;
@@ -20,7 +21,6 @@ stdenv.mkDerivation {
patchPhase = ''
substituteAllInPlace run
substituteAllInPlace stage2
'';
installPhase = ''
@@ -40,7 +40,6 @@ stdenv.mkDerivation {
mkdir -p $out/bin
install -m755 run $out/bin/run
install -m755 stage2 $out/bin/stage2
chmod +x $out/bin/*
# Mark the launcher for upload

View File

@@ -1,10 +1,9 @@
#!/bin/sh -ex
>&2 echo "Running launcher run stage"
env
>&2 echo "Running launcher"
if [ -e /nix ]; then
>&2 echo "Cannot use the launcher inside nix environment!"
if [ ! -e "/nix" ]; then
>&2 echo "missing /nix"
exit 1
fi
@@ -12,8 +11,10 @@ if [ -z "$GARLIC_OUT" ]; then
>&2 echo "GARLIC_OUT is not set"
exit 1
fi
mkdir -p "$GARLIC_OUT"
cd "$GARLIC_OUT"
exec nix-isolate @nixPrefix@@out@/bin/stage2
for j in @out@/apps/*; do
$j/bin/run
done

View File

@@ -1,12 +0,0 @@
#!/bin/sh -ex
>&2 echo "Running launcher stage2"
if [ ! -e "/nix" ]; then
>&2 echo "Cannot execute stage2 outside from nix environment"
exit 1
fi
for j in @out@/apps/*; do
$j/bin/run
done

View File

@@ -1,40 +0,0 @@
{
stdenv
, nixtools
}:
{
program
, clusterName
}:
stdenv.mkDerivation {
name = "nix-isolate";
preferLocalBuild = true;
phases = [ "installPhase" ];
dontPatchShebangs = true;
installPhase = ''
cat > $out <<EOF
#!/bin/sh -ex
>&2 echo Running nix-isolate stage
>&2 echo PATH=$PATH
>&2 echo Running env:
env
# We need to enter the nix namespace first, in order to have /nix
# available, so we use this hack:
if [ ! -e /nix ]; then
exec ${nixtools}/bin/${clusterName}/nix-isolate \$0
fi
if [ -e /usr ]; then
>&2 echo "Environment not isolated, aborting"
exit 1
fi
exec ${program}
EOF
chmod +x $out
'';
}

View File

@@ -0,0 +1,25 @@
{
stdenv
, nixtools
}:
{
program
, nixPrefix
, sshHost ? "mn"
, targetCluster ? "mn4"
}:
stdenv.mkDerivation {
name = "runexp";
preferLocalBuild = true;
phases = [ "unpackPhase" "installPhase" ];
dontPatchShebangs = true;
src = ./.;
inherit sshHost nixPrefix nixtools targetCluster program;
installPhase = ''
substituteAllInPlace runexp
cp runexp $out
chmod +x $out
'';
}

14
garlic/stages/runexp/runexp Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/sh
# @upload-to-mn@
# This program runs the current experiment in the ./result symlink in
# MareNostrum. Requires that you define a "mn" host in the ssh config file
# (usually in ~/.ssh/config).
nixPrefix=@nixPrefix@
nixtools=$nixPrefix@nixtools@/bin
runexp=$nixtools/@targetCluster@/runexp
>&2 echo "Launching \"$runexp @program@\" in MN"
ssh mn $runexp @program@