-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite fork adapter to use Singularity in PID namespace mode
- Adds Singularity to ensure that daemons are killed - Improves timeout - Adds SSH option to improve user experience on round robin systems
- Loading branch information
Morgan Rodgers
committed
Sep 24, 2019
1 parent
03d3efb
commit f2b4b55
Showing
3 changed files
with
130 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
#!/bin/bash | ||
hostname | ||
|
||
# Put the script into a temp file on localhost | ||
<% if debug %> | ||
tmp_file=$(mktemp -p "$HOME") | ||
singularity_tmp_file=$(mktemp -p "$HOME" --suffix '_sing') | ||
tmux_tmp_file=$(mktemp -p "$HOME" --suffix "_tmux") | ||
<% else %> | ||
tmp_file=$(mktemp) | ||
singularity_tmp_file=$(mktemp) | ||
tmux_tmp_file=$(mktemp) | ||
<% end %> | ||
cat << HEREDOC > "$tmp_file" | ||
|
||
# Create an executable to run in a tmux session | ||
cat << TMUX_LAUNCHER > "$tmux_tmp_file" | ||
#!/bin/bash | ||
<%= cd_to_workdir %> | ||
<%= environment %> | ||
<%= timeout_cmd %> | ||
<%= environment %> | ||
# Redirect stdout and stderr to separate files for all commands run within the curly braces | ||
# https://unix.stackexchange.com/a/6431/204548 | ||
# Swap sterr and stdout after stdout has been redirected | ||
# https://unix.stackexchange.com/a/61932/204548 | ||
({ | ||
<%= script_content %> | ||
timeout <%= script_timeout %>s <%= singularity_bin %> exec --pid <%= singularity_image %> /bin/bash --login $singularity_tmp_file | ||
} | tee "<%= output_path %>") 3>&1 1>&2 2>&3 | tee "<%= error_path %>" | ||
# Exit the tmux session when we are complete | ||
exit 0 | ||
HEREDOC | ||
TMUX_LAUNCHER | ||
|
||
# Create an executable for Singularity to run | ||
cat << SINGULARITY_LAUNCHER > "$singularity_tmp_file" | ||
<%= script_content %> | ||
SINGULARITY_LAUNCHER | ||
|
||
# Run the script inside a tmux session | ||
chmod +x "$tmp_file" | ||
<%= tmux_bin %> new-session -d -s "<%= session_name %>" "$tmp_file" | ||
chmod +x "$singularity_tmp_file" | ||
chmod +x "$tmux_tmp_file" | ||
<%= tmux_bin %> new-session -d -s "<%= session_name %>" "$tmux_tmp_file" | ||
|
||
# Remove the file | ||
<% if ! debug %> | ||
# Wait 1 second to ensure that tmux session has started before the file is removed | ||
(sleep 1; rm -f "$tmp_file") & | ||
(sleep 1; rm -f "$tmux_tmp_file"; rm -f "$singularity_tmp_file") & | ||
<% end %> |