Commit c5385f62 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Add license, always mux

parent d99add0b
#!/bin/bash
#
# Copyright 2017
#
# Mathis Rosenhauer
# Deutsches Klimarechenzentrum GmbH
# Bundesstr. 45a
# 20146 Hamburg Germany
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# startvnc
#
# Starts vncserver on a GPU node by submitting a generated job script.
......@@ -14,50 +48,60 @@
# The vncviewer client has to support the -via option. TurboVNC,
# TigerVNC and TightVNC are known to work.
#
# Set SVNC_SSH_MUX="true" to share one ssh connection. This can speed
# up the script if ssh login is slow. If you have to use password
# authentication, you will only have to give your password twice.
set -e
# Default settings
SVNC_USERNAME="" # LDAP username
SVNC_ACCTCODE="" # project account code
SVNC_RUNTIME=240 # session run time in minutes
SVNC_QOS="normal" # quality of service
SVNC_GEOMETRY="1920x1200" # resolution of remote desktop window
SVNC_VNCVIEWER="/usr/bin/vncviewer" # path to local vncviewer
# LDAP username
SVNC_USERNAME=""
# Project account code
SVNC_ACCTCODE=""
# Session run time in minutes
SVNC_RUNTIME=240
# Quality of service
SVNC_QOS="normal"
# Resolution of remote desktop window
SVNC_GEOMETRY="1920x1200"
# Path to local vncviewer
SVNC_VNCVIEWER="/usr/bin/vncviewer"
# Uncomment this if you use TurboVNC as vncviewer
#readonly SVNC_VNC_OPTIONS="-extssh"
# Frontend host. Must be directly accessible from client. Frontend
# and node where vnc server is running need a shared home file system.
readonly SVNC_FRONTEND_HOST="mistral.dkrz.de"
# Copy vncpassword temporarily to the local workstation
readonly SVNC_PASSWORD="true"
readonly SVNC_PASSWORD="true" # copy vncpassword temporarily to
# the local workstation
readonly SVNC_SSH_MUX="true" # use sharing of multiple ssh sessions
# over a single network connection
#readonly SVNC_VNC_OPTIONS="-extssh" # uncomment this if you use
# TurboVNC as vncviewer
clean_up () {
trap - ERR EXIT
set +e
if [[ ${vnc_host} ]]; then
ssh_mistral "ssh ${vnc_host} \"/opt/TurboVNC/bin/vncserver \
-kill :${vnc_display}\""
if [[ -n ${vnc_host} ]]; then
ssh_frontend "ssh ${vnc_host} \"/opt/TurboVNC/bin/vncserver \
-kill :${vnc_display}\""
fi
echo "Removing job."
if [[ ${job_id} ]]; then
ssh_mistral "scancel -Q ${job_id}; sleep 1; \
cd .startvnc && rm -f out.${job_id}"
if [[ -n ${job_id} ]]; then
ssh_frontend "scancel -Q ${job_id}; sleep 1; \
cd .startvnc && rm -f out.${job_id}"
else
echo "Job ID not available. Make sure the vncjob is not running!"
ssh_mistral "squeue -u ${SVNC_USERNAME}"
ssh_frontend "squeue -u ${SVNC_USERNAME}"
fi
if [[ ${SVNC_SSH_MUX} = "true" ]]; then
ssh_mistral "" "-O exit"
rmdir "${ssh_socket_dir}"
fi
ssh_frontend "" "-O exit"
rmdir "${ssh_socket_dir}"
# Remove local vnc PasswordFile
if [[ ${SVNC_PASSWORD} = "true" ]]; then
......@@ -72,12 +116,10 @@ usage () {
printf -- "-v path_to_vncviewer\n-x vncviewer_options\n" >&2
}
ssh_mistral () {
local ssh_options="$2 -o ForwardX11=no"
if [[ ${SVNC_SSH_MUX} = "true" ]]; then
ssh_options+=" -o ControlPath=${ssh_socket_dir}/control:%h:%p:%r"
fi
ssh ${ssh_options} "${SVNC_USERNAME}@mistral00.dkrz.de" "$1"
ssh_frontend () {
local ssh_options="$2 -o ForwardX11=no \
-o ControlPath=${ssh_socket_dir}/control:%h:%p:%r"
ssh ${ssh_options} "${SVNC_USERNAME}@${SVNC_FRONTEND_HOST}" "$1"
}
parse_options () {
......@@ -121,17 +163,17 @@ parse_options () {
}
prepare_vncserver () {
ssh_mistral "mkdir -p .startvnc"
if ! ssh_mistral "test -s .vnc/passwd"; then
ssh_frontend "mkdir -p .startvnc"
if ! ssh_frontend "test -s .vnc/passwd"; then
echo "No VNC password found. Please set now."
ssh_mistral "salloc -Q -n1 -pgpu -A${SVNC_ACCTCODE} -- /bin/bash -c \
'ssh -tt \$SLURM_JOB_NODELIST -- mkdir -p .vnc \
&& /opt/TurboVNC/bin/vncpasswd'" "-t"
ssh_frontend "salloc -Q -n1 -pgpu -A${SVNC_ACCTCODE} -- /bin/bash -c \
'ssh -tt \$SLURM_JOB_NODELIST -- mkdir -p .vnc \
&& /opt/TurboVNC/bin/vncpasswd'" "-t"
fi
}
submit_vnc_job () {
ssh_mistral "cd .startvnc && sbatch" <<EOF
ssh_frontend "cd .startvnc && sbatch" <<EOF
#!/bin/bash -l
#SBATCH --partition=gpu
#SBATCH --ntasks=12
......@@ -148,7 +190,7 @@ EOF
get_vnc_host_and_display () {
local job_id="$1"
ssh_mistral "/bin/bash" <<EOF
ssh_frontend "/bin/bash" <<EOF
logfile=\${HOME}/.startvnc/out.${job_id}
while [[ -z \${host_and_display} ]]; do
sleep 1
......@@ -165,11 +207,8 @@ main () {
parse_options "$@"
trap clean_up INT QUIT TERM ERR EXIT
if [[ ${SVNC_SSH_MUX} = "true" ]]; then
ssh_socket_dir=$(mktemp -d "${HOME}/.ssh/socket.XXXXX")
ssh_mistral "" "-MNf"
fi
ssh_socket_dir=$(mktemp -d "${HOME}/.ssh/socket.XXXXX")
ssh_frontend "" "-MNf"
prepare_vncserver
echo "Submitting vncserver job."
......@@ -183,11 +222,11 @@ main () {
local vnc_options="${SVNC_VNC_OPTIONS} \
-via ${SVNC_USERNAME}@${vnc_host}.dkrz.de"
if [[ ${SVNC_PASSWORD} = "true" ]]; then
ssh_mistral "cat .vnc/passwd" > ${HOME}/vnc_passwd
ssh_frontend "cat .vnc/passwd" > ${HOME}/vnc_passwd
vnc_options+=" -passwd ${HOME}/vnc_passwd"
fi
${SVNC_VNCVIEWER} ${vnc_options} :${vnc_display}
"${SVNC_VNCVIEWER}" ${vnc_options} :${vnc_display}
}
main "$@"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment