-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start of work to add xserver support (#32)
* start of work to add xserver support Signed-off-by: vsoch <vsoch@users.noreply.github.com>
- Loading branch information
Showing
17 changed files
with
367 additions
and
176 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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
JOB_NAME="{{ jobname }}" | ||
SCRIPT_DIR="{{ scriptdir }}" | ||
mkdir -p ${SCRIPT_DIR} | ||
|
||
# Sets $PORT envar from args.port then port | ||
{% include "bash/network/set-port.sh" %} | ||
|
||
# Include Singularity cachedir if not set | ||
{% include "bash/singularity/set-cache-tmp.sh" %} | ||
|
||
# Source ~/bash_profile or ~/.profile | ||
{% include "bash/source-profile.sh" %} | ||
|
||
# Working Directory | ||
{% include "bash/set-workdir.sh" %} | ||
cd $WORKDIR | ||
|
||
echo "Job is ${JOB_NAME}" | ||
echo "Port is ${PORT}" | ||
echo "Working directory is ${WORKDIR}" | ||
echo "Script directory is ${SCRIPT_DIR}" | ||
|
||
# Create .local folder for default modules, if doesn't exist | ||
{% include "bash/python/create-local.sh" %} | ||
|
||
# username and password for django to create | ||
{% include "bash/set-user-pass.sh" %} | ||
|
||
# Load modules requested by user | ||
{% for module in args.modules %}module load {{ module }} || printf "Could not load {{ module }}\n" | ||
{% endfor %} | ||
|
||
# Add variables to PATH | ||
{% for path in paths %}export PATH={{ path }}:${PATH} | ||
{% endfor %} | ||
|
||
{% if docker %}{% include "templates/run_docker.sh" %}{% else %}{% include "templates/run_singularity.sh" %}{% endif %} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
launcher: singularity | ||
launchers_supported: | ||
- singularity | ||
- slurm | ||
script: app.sh | ||
description: Launch neurodesk (or an associated application) | ||
needs: | ||
xserver: true | ||
examples: | | ||
# Run app on login node with singularity | ||
tunel run-app waffles neurodocker | ||
# Run app on an interactive node (also with singularity) | ||
tunel run-app waffles neurodocker --launcher slurm | ||
# Force a new pull | ||
tunel run-app waffles neurodocker --pull | ||
args: | ||
- name: workdir | ||
description: Working directory for app (and to show file explorer for) | ||
- name: container | ||
description: "Change the app container used (default is demo ghcr.io/neurodesk/caid/itksnap_3.8.0:20210322)" | ||
- name: tag | ||
description: "Tag of the container to use (defaults to latest)" | ||
- name: pull | ||
description: force a new pull (even if the container already exists). |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
SIF="${SINGULARITY_CACHEDIR}/neurodesk.sif" | ||
CONTAINER="docker://{% if args.container %}{{ args.container }}{% else %}ghcr.io/neurodesk/caid/itksnap_3.8.0:{% if args.tag %}{{ args.tag }}{% else %}20210322{% endif %}{% endif %}" | ||
|
||
if command -v singularity &> /dev/null | ||
then | ||
printf "singularity pull ${CONTAINER}\n" | ||
|
||
# Only pull the container if we do not have it yet, or the user requests it | ||
if [[ ! -f "${SIF}" ]] || [[ "{{ args.pull }}" != "" ]]; then | ||
singularity pull --force ${SIF} ${CONTAINER} | ||
fi | ||
|
||
# The false at the end ensures we aren't using nginx, but rather uwsgi just with sockets | ||
printf "singularity run ${SIF}\n" | ||
# Likely we could allow some custom binds here | ||
singularity run ${SIF} | ||
|
||
else | ||
printf "Singularity is not available.\n" | ||
fi |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
__author__ = "Vanessa Sochat" | ||
__copyright__ = "Copyright 2021-2022, Vanessa Sochat" | ||
__license__ = "MPL 2.0" | ||
|
||
import os | ||
import shlex | ||
import threading | ||
import time | ||
|
||
import tunel.utils as utils | ||
from tunel.logger import logger | ||
|
||
from .base import Launcher | ||
|
||
|
||
class ContainerLauncher(Launcher): | ||
""" | ||
A container launcher has shared functions for launching a head node container. | ||
""" | ||
|
||
name = "container" | ||
|
||
def run_app(self, app): | ||
""" | ||
A Singularity app means running a container directly with some arguments, etc. | ||
""" | ||
# Make sure we set the username to the ssh | ||
self.username | ||
|
||
# Add any paths from the config | ||
paths = self.settings.get("paths", []) | ||
|
||
# Prepare dictionary with content to render into recipes | ||
render = self.prepare_render(app, paths) | ||
render[self.name] = self.name | ||
|
||
# Clean up previous sockets | ||
self.ssh.execute(["rm", "-rf", "%s/*.sock" % render["scriptdir"]]) | ||
|
||
# Load the app template | ||
template = app.load_template() | ||
result = template.render(**render) | ||
|
||
# Write script to temporary file | ||
tmpfile = utils.get_tmpfile() | ||
utils.write_file(tmpfile, result) | ||
|
||
# Copy over to server | ||
remote_script = os.path.join(self.remote_assets_dir, app.name, app.script) | ||
self.ssh.scp_to(tmpfile, remote_script) | ||
|
||
# Instead of a Singularity command, we run the script | ||
command = "%s %s %s %s" % ( | ||
self.path, | ||
self.environ, | ||
self.ssh.settings.shell, | ||
remote_script, | ||
) | ||
|
||
# An xserver launches the app directly | ||
if not app.has_xserver: | ||
logger.c.print() | ||
logger.c.print("== INSTRUCTIONS WILL BE PRINTED with a delay ==") | ||
self.print_tunnel_instructions(app, render["socket"]) | ||
self.ssh.execute(command, stream=True, xserver=app.has_xserver) | ||
|
||
def print_tunnel_instructions(self, app, socket): | ||
""" | ||
Start a separate thread to print connection details. | ||
""" | ||
thread = threading.Thread( | ||
target=post_commands, | ||
name="Logger", | ||
args=[self.ssh, app, socket], | ||
) | ||
thread.start() | ||
|
||
|
||
def post_commands(ssh, app, socket): | ||
time.sleep(10) | ||
ssh.tunnel_login_node(socket=socket, app=app) | ||
if app.post_command: | ||
logger.info("Found post command %s" % app.post_command) | ||
post = app.post_command.replace("$socket_dir", os.path.dirname(socket)) | ||
ssh.execute(shlex.split(post), stream=True) | ||
time.sleep(30) | ||
ssh.tunnel_login_node(socket=socket, app=app) |
Oops, something went wrong.