Last active
December 9, 2024 19:43
-
-
Save kaspermunch/598c3a3e3fe2107b4c046f6e3104dade to your computer and use it in GitHub Desktop.
Bash script for lauching VSCode on a GenomeDK compute node
This file contains hidden or 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
| #!/usr/bin/env bash | |
| usage=$(cat <<-END | |
| Use like this: | |
| gdk-code <memory> <walltime> <environment> <projectdir> <> ~/some/dir/on/genomedk | |
| The following needs to be part of your .ssh/config file: | |
| Host gdk | |
| HostName login.genome.au.dk | |
| User your_user_name_on_the_genomedk | |
| Host cn-* gn-* s21n* s22n* | |
| HostName %h | |
| ProxyJump gdk | |
| User your_user_name_on_the_genomedk | |
| END | |
| ) | |
| while getopts ":m:t:e:a:d:" opt; do | |
| case $opt in | |
| m) mem="$OPTARG" | |
| ;; | |
| t) walltime="$OPTARG" | |
| ;; | |
| e) environment="$OPTARG" | |
| ;; | |
| a) account="$OPTARG" | |
| ;; | |
| d) open_dir="$OPTARG" | |
| ;; | |
| h) usage | |
| exit 0;; | |
| *) usage | |
| exit 1;; | |
| esac | |
| done | |
| if [ -z "$mem" ]; then mem="8g"; fi | |
| if [ -z "$walltime" ]; then walltime="08:00:00"; fi | |
| # if [ -z "$environment" ]; then environment="base"; fi | |
| # mem=$1 | |
| # walltime=$2 | |
| # environment=$3 | |
| # account=$4 | |
| # open_dir=$5 | |
| if [ "$1" = "-h" ] || [ -z "$1" ]; then | |
| echo "$USAGE" | |
| exit | |
| fi | |
| if [ "$HOSTNAME" = "fe-ipsych-01" ]; then | |
| jobid=$(sbatch --mem-per-cpu=${mem} --cores=1 --time=${walltime} --account=${account} --wrap='sleep 6d' | awk '{print $4}') | |
| echo "Submitted job with id: ${jobid}" | |
| while [ -z "${is_running}" ]; do | |
| sleep 5 | |
| is_running=$(jobinfo ${jobid} | grep RUNNING) | |
| done | |
| node=$(jobinfo $jobid | grep Nodes | awk '{print $3}') | |
| echo "Job allocated core on node ${node}" | |
| conda run -n $environment ~/ChrXh2/VSCode-linux-x64/bin/code --folder-uri "vscode-remote://ssh-remote+${node}${open_dir}" | |
| else | |
| jobid=$(ssh gdk "sbatch --mem-per-cpu=${mem} --cores=1 --time=${walltime} --account=${account} --wrap='sleep 6d'" | awk '{print $4}') | |
| echo "Submitted job with id: ${jobid}" | |
| while [ -z "${is_running}" ]; do | |
| sleep 5 | |
| is_running=$(ssh gdk "jobinfo ${jobid}" | grep RUNNING) | |
| done | |
| node=$(ssh gdk "jobinfo $jobid" | grep Nodes | awk '{print $3}') | |
| echo "Job allocated core on node ${node}" | |
| conda run -n $environment code --folder-uri "vscode-remote://ssh-remote+${node}${open_dir}" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment