106 lines
2.0 KiB
Bash
Executable File
106 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
emsg() {
|
|
>&2 echo "garlicd: $@"
|
|
}
|
|
|
|
msg() {
|
|
emsg "$@"
|
|
if [ ! -z "$st" ]; then echo "garlicd: $@" >>"$st"; fi
|
|
}
|
|
|
|
if [ ! -z "$1" ]; then
|
|
>&2 echo "usage: garlicd"
|
|
exit 1
|
|
fi
|
|
|
|
export PATH="@extraPath@:$PATH"
|
|
|
|
garlic_sandbox=$(nix show-config |\
|
|
grep extra-sandbox-paths |\
|
|
grep -o '/garlic=[^ ]*' || true)
|
|
|
|
if [ -z "$garlic_sandbox" ]; then
|
|
emsg "Missing extra-sandbox-paths /garlic mountpoint"
|
|
emsg "Check the ~/.config/nix/nix.conf file"
|
|
exit 1
|
|
fi
|
|
|
|
mountdir_rel=$(echo "$garlic_sandbox" | sed 's@^/garlic=@@g')
|
|
mountdir=$(readlink -f "$mountdir_rel")
|
|
run="$mountdir/run"
|
|
completed="$mountdir/completed"
|
|
wipe="$mountdir/wipe"
|
|
st="$mountdir/st"
|
|
|
|
handle_bad_signal() {
|
|
msg "cleaning FIFO pipes"
|
|
rm -f "$run" "$completed" "$wipe"
|
|
exit 1
|
|
}
|
|
|
|
trap handle_bad_signal SIGINT
|
|
|
|
for fifo in "$run" "$completed" "$wipe"; do
|
|
if [ ! -e "$fifo" ]; then
|
|
mkfifo "$fifo"
|
|
# FIXME: Use more resctrictive permissions
|
|
chmod 666 "$fifo"
|
|
fi
|
|
done
|
|
|
|
while true; do
|
|
emsg "--- Waiting for experiments ---"
|
|
tre=$(head -1 "$run")
|
|
|
|
# Truncate state file
|
|
printf "" > "$st"
|
|
|
|
msg "Attempting to run: $tre"
|
|
msg "Copying files to MN4..."
|
|
# It fails if the user doesn't have nix-store, but is already copied
|
|
# with the post build hook
|
|
nix copy --to ssh://mn1 $tre || true
|
|
|
|
set +e
|
|
|
|
msg "Launching the experiment..."
|
|
garlic -R "$tre" 2>>"$st"
|
|
if [ "$?" != 0 ]; then
|
|
echo ERROR > "$completed"
|
|
msg "Failed to run the experiment :-("
|
|
continue
|
|
fi
|
|
|
|
msg "Fetching results..."
|
|
garlic -FKv "$tre" 2>>"$st"
|
|
|
|
if [ "$?" != 0 ]; then
|
|
echo ERROR > "$completed"
|
|
msg "The experiment failed :-("
|
|
continue
|
|
fi
|
|
|
|
set -e
|
|
|
|
msg "Signalling nix build..."
|
|
echo -n "$tre" >> "$completed"
|
|
|
|
msg "Waiting for nix to finish the build..."
|
|
|
|
tre2=$(head -1 "$wipe")
|
|
if [ "$tre" != "$tre2" ]; then
|
|
msg "error: trebuchet mismatch"
|
|
exit 1
|
|
fi
|
|
|
|
msg "Removing temporal files..."
|
|
garlic -D "$tre" 2>>"$st"
|
|
|
|
echo -n "$tre" >> "$completed"
|
|
|
|
msg "Execution completed :-)"
|
|
done
|