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

Avoid using temp files

parent 6ddb72e5
No related branches found
No related tags found
No related merge requests found
......@@ -39,26 +39,21 @@ readonly SVNC_SSH_MUX="true" # use sharing of multiple ssh sessions
clean_up () {
trap - ERR EXIT
set +e
local tmp_files="${job_script_name}"
if [[ ${vnc_host} ]]; then
ssh_mistral "ssh ${vnc_host} \"/opt/TurboVNC/bin/vncserver \
-kill :${vnc_display}\""
fi
echo "Removing job and temporary files."
echo "Removing job."
if [[ ${job_id} ]]; then
tmp_files="${tmp_files} out.${job_id} gethost.${job_id}"
ssh_mistral "scancel -Q ${job_id}; sleep 1"
ssh_mistral "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}"
fi
if [[ -n ${tmp_files} ]]; then
ssh_mistral "cd .startvnc && rm -f ${tmp_files}"
fi
if [[ ${SVNC_SSH_MUX} = "true" ]]; then
ssh_mistral "" "-O exit"
rmdir "${ssh_socket_dir}"
......@@ -125,7 +120,8 @@ parse_options () {
fi
}
check_vnc_password () {
prepare_vncserver () {
ssh_mistral "mkdir -p .startvnc"
if ! ssh_mistral "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 \
......@@ -134,13 +130,8 @@ check_vnc_password () {
fi
}
get_job_script_name () {
ssh_mistral "mkdir -p .startvnc && cd .startvnc && mktemp vncjob.XXXXX"
}
submit_vnc_job () {
local job_script_name="$1"
ssh_mistral "cat > .startvnc/${job_script_name}" <<EOF
ssh_mistral "cd .startvnc && sbatch" <<EOF
#!/bin/bash -l
#SBATCH --partition=gpu
#SBATCH --ntasks=12
......@@ -153,13 +144,11 @@ submit_vnc_job () {
cd \${HOME}
/opt/TurboVNC/bin/vncserver -fg -geometry "${SVNC_GEOMETRY}" -localhost
EOF
ssh_mistral "cd .startvnc && sbatch ${job_script_name}"
}
get_vnc_host_and_display () {
local job_id="$1"
ssh_mistral "cat > .startvnc/gethost.${job_id}" <<EOF
#!/bin/bash
ssh_mistral "/bin/bash" <<EOF
logfile=\${HOME}/.startvnc/out.${job_id}
while [[ -z \${host_and_display} ]]; do
sleep 1
......@@ -170,7 +159,6 @@ while [[ -z \${host_and_display} ]]; do
done
echo \${host_and_display}
EOF
ssh_mistral "/bin/bash .startvnc/gethost.${job_id}"
}
main () {
......@@ -182,11 +170,10 @@ main () {
ssh_mistral "" "-MNf"
fi
check_vnc_password
prepare_vncserver
job_script_name=$(get_job_script_name)
echo "Submitting vncserver job."
job_id=$(submit_vnc_job "${job_script_name}")
job_id=$(submit_vnc_job)
echo "Waiting for job ${job_id} to start."
local host_and_display=$(get_vnc_host_and_display "$job_id")
......
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