Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
ssh_scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sofiane Bendoukha
ssh_scripts
Commits
c5385f62
Commit
c5385f62
authored
7 years ago
by
Mathis Rosenhauer
Browse files
Options
Downloads
Patches
Plain Diff
Add license, always mux
parent
d99add0b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
startvnc
+85
-46
85 additions, 46 deletions
startvnc
with
85 additions
and
46 deletions
startvnc
+
85
−
46
View file @
c5385f62
#!/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
"
$@
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment