Skip to content
Snippets Groups Projects
Commit 1e955f73 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer
Browse files

Handle no password set, use vncserver for killing

parent eed9fdf8
No related branches found
No related tags found
No related merge requests found
......@@ -37,41 +37,38 @@ MISTRAL="${USERNAME}@mistral.dkrz.de"
clean_up () {
trap - ERR EXIT
set +e
local job_id="$1"
local vnc_host_display="$2"
local xvnc_pid="$3"
local tmp_files="$4"
local tmp_files=${job_script}
echo "Removing job and temporary files."
if [[ ${vnc_host_display} && ${xvnc_pid} ]]; then
if [[ ${vnc_host_display} ]]; then
# Kill Xvnc process. Mainly done to remove lock file.
local vnc_host=${vnc_host_display%:*}
ssh ${MISTRAL} "ssh ${USERNAME}@${vnc_host} \"kill ${xvnc_pid}\"" \
2> /dev/null
local vnc_display=${vnc_host_display#*:}
ssh ${MISTRAL} "ssh ${USERNAME}@${vnc_host} \
\"/opt/TurboVNC/bin/vncserver -kill :${vnc_display}\""
fi
if [[ ${job_id} ]]; then
# Clean up temp files and cancel job
tmp_files="${tmp_files} out.${job_id} vnc_gethost.${job_id}"
ssh ${MISTRAL} "scancel ${job_id}; sleep 5" 2> /dev/null
ssh ${MISTRAL} "scancel -Q ${job_id}; sleep 1"
else
echo "Job ID not available. Make sure the vncjob is not running!"
ssh ${MISTRAL} "squeue -u ${USERNAME}"
fi
if [[ ${tmp_files} ]]; then
ssh ${MISTRAL} "cd .startvnc && rm -f ${tmp_files}" 2> /dev/null
ssh ${MISTRAL} "cd .startvnc && rm -f ${tmp_files}"
fi
# Remove local vnc PasswordFile
if [[ ${PASSWORD} = true ]]; then
rm -f ~/.vnc/passwd2
rm -f ~/.vnc/passwd2
fi
exit
}
trap 'clean_up \"${job_id}\" \"${vnc_host_display}\" \"${xvnc_pid}\" \
\"${job_script}\"' INT QUIT TERM ERR EXIT
trap clean_up INT QUIT TERM ERR EXIT
job_script=$(ssh ${MISTRAL} \
'mkdir -p .startvnc && cd .startvnc && mktemp vncjob.XXXXX')
......@@ -83,6 +80,7 @@ ssh ${MISTRAL} "cat > .startvnc/${job_script}" <<EOF
#SBATCH --time=${TIME}
#SBATCH --account=${ACCTCODE}
#SBATCH --output=out.%j
##SBATCH --dkrzepilog=0
cd \${HOME}
/opt/TurboVNC/bin/vncserver -fg -geometry ${GEOMETRY}
......@@ -96,11 +94,12 @@ ssh ${MISTRAL} "cat > .startvnc/vnc_gethost.${job_id}" <<EOF
#!/bin/bash
cd "\${0%/*}"
LOGFILE=out.${job_id}
while [ -z \${vnc_host_display} ]; do
while [[ -z \${vnc_host_display} ]] && [[ -z \${set_password} ]]; do
sleep 1
if [[ -f \${LOGFILE} ]]; then
vnc_host_display=\$(grep -Po "started on display \Kmg[0-9]+:[0-9]+" \
\${LOGFILE})
set_password=\$(grep -i password \${LOGFILE})
fi
done
echo \${vnc_host_display}
......@@ -108,7 +107,10 @@ EOF
echo "Waiting for job ${job_id} to start."
vnc_host_display=$(ssh ${MISTRAL} "/bin/bash .startvnc/vnc_gethost.${job_id}")
xvnc_pid=$(ssh ${MISTRAL} "cat .vnc/${vnc_host_display}.pid")
if [[ -z ${vnc_host_display} ]]; then
echo -e "\nSet a password for vncserver before starting the client!\n"
exit
fi
# Start VNC client
if [[ ${PASSWORD} = true ]]; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment