Skip to content

Instantly share code, notes, and snippets.

@MVesuviusC
Created April 19, 2022 13:22
Show Gist options
  • Save MVesuviusC/39e2a5bcd954e5ae31672f4121c4d0a9 to your computer and use it in GitHub Desktop.
Save MVesuviusC/39e2a5bcd954e5ae31672f4121c4d0a9 to your computer and use it in GitHub Desktop.
rstudio server using singularity
singularity rstudio
modified from: https://www.rocker-project.org/use/singularity/
#!/bin/bash
#SBATCH --time=3-00:00:00
#SBATCH --signal=USR2
#SBATCH --ntasks=1
module purge
module load slurm
module load singularity
export PASSWORD=$(openssl rand -base64 8)
# get unused socket per https://unix.stackexchange.com/a/132524
# tiny race condition between the python & singularity commands
readonly PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
cat 1>&2 <<END
1. SSH tunnel from your workstation using the following command:
ssh -N -L 8787:${HOSTNAME}:${PORT} ${USER}@myhpc.dur.ac.uk
and point your web browser to http://localhost:8787
2. log in to RStudio Server using the following credentials:
user: ${USER}
password: ${PASSWORD}
When done using RStudio Server, terminate the job by:
1. Exit the RStudio Session ("power" button in the top right corner of the RStudio window)
2. Issue the following command on the login node:
scancel -f ${SLURM_JOB_ID}
END
export LANG="en_US.UTF-8"
export LC_COLLATE="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_MESSAGES="en_US.UTF-8"
export LC_MONETARY="en_US.UTF-8"
export LC_NUMERIC="en_US.UTF-8"
export LC_TIME="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
##NOTE##
# This is a local drive location I can write, you should be able
# to just set to a subfolder of your HPC home/scratch directory
export TMPDIR="/gpfs0/scratch/${USER}/rstudio-tmp"
mkdir -p "$TMPDIR/tmp/rstudio-server"
uuidgen > "$TMPDIR/tmp/rstudio-server/secure-cookie-key"
chmod 0600 "$TMPDIR/tmp/rstudio-server/secure-cookie-key"
mkdir -p "$TMPDIR/var/lib"
mkdir -p "$TMPDIR/var/run"
# Also bind data directory on the host into the Singularity container.
# By default the only host file systems mounted within the container are $HOME, /tmp, /proc, /sys, and /dev.
##NOTE##
# You may need here just to replace the fourth bind option, or drop
singularity exec \
--bind="$TMPDIR/var/lib:/var/lib/rstudio-server" \
--bind="$TMPDIR/var/run:/var/run/rstudio-server" \
--bind="$TMPDIR/tmp:/tmp" \
rstudio.simg \
rserver --www-port ${PORT} --auth-none=0 --auth-pam-helper-path=pam-helper --auth-timeout-minutes=0 --auth-stay-signed-in-days=30
printf 'rserver exited' 1>&2
### Installation of packages from the web interface overwrites local versions on the cluster and borks them
### Can't access slurm from within container....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment