diff --git a/m3/rocker-seurat_4.4.3-5.2.1.strudel.yaml.j2 b/m3/rocker-seurat_4.4.3-5.2.1.strudel.yaml.j2 index 7a4ecb5..d73e108 100644 --- a/m3/rocker-seurat_4.4.3-5.2.1.strudel.yaml.j2 +++ b/m3/rocker-seurat_4.4.3-5.2.1.strudel.yaml.j2 @@ -14,7 +14,7 @@ instactions: paramscmd: cat ~/.rstudio-rocker/rserver-{jobid}.json client: cmd: null - redir: "" + redir: "{tunnelid}/" states: - RUNNING - name: View log diff --git a/rstudio.sh b/rstudio.sh index ae84f27..76b3ea9 100755 --- a/rstudio.sh +++ b/rstudio.sh @@ -36,13 +36,6 @@ else IMAGE_LOCATION="docker://$IMAGE" fi -PORT=${RSTUDIO_PORT:-8787} - -# Create a new password, or use whatever password is passed in the environment -if [[ -z "$PASSWORD" ]]; then - PASSWORD=$(openssl rand -base64 15) -fi -export PASSWORD # Use a shared cache location if unspecified # export SINGULARITY_CACHEDIR=${SINGULARITY_CACHEDIR:-"/scratch/df22/andrewpe/singularity_cache"} @@ -56,24 +49,12 @@ fi # Since we can't easily tell if we are in strudel2 we will actually check if we are in slurm (PBS should be the same) # Hardcode this to 'local' if you don't ever use an HPC cluster. if [[ -z "${SLURM_JOB_ID}" ]]; then - HPC_ENV="local" + HPC_ENV="shell" else - HPC_ENV="m3" + HPC_ENV="slurm" fi -function get_port { - # lsof doesn't return open ports for system services, so we use netstat - # until ! lsof -i -P -n | grep -qc ':'${PORT}' (LISTEN)'; - - until ! netstat -ln | grep " LISTEN " | grep -iEo ":[0-9]+" | cut -d: -f2 | grep -wqc "${PORT}"; - do - ((PORT++)) - echo "Checking port: ${PORT}" - done - echo "Got one !" -} - # Make a dir name from the IMAGE IMAGE_SLASHED=$(echo "${IMAGE}" | sed 's/:/\//g' | sed 's/\.\./__/g') R_DIRS="${HOME}/.rstudio-rocker/${IMAGE_SLASHED}/" @@ -106,7 +87,7 @@ else _cachedir=${HOME}/.apptainer/cache/ fi -if [[ $HPC_ENV == "m3" ]]; then +if [[ $HPC_ENV == "slurm" ]]; then BINDPATHS=("/fs02" "/fs03" "/fs04" "/scratch" "/scratch2" "/projects") SINGULARITY_BINDPATH="" for path in "${BINDPATHS[@]}"; do @@ -127,9 +108,18 @@ echo " Storing image in ${_cachedir}" # Test the image works, execute a no-op command ${SINGULARITY_BIN} exec "${IMAGE_LOCATION}" true +get_socketid() { + if [[ -n "$SLURM_JOB_ID" ]]; then + SOCKETID="$SLURM_JOB_ID" + else + SOCKETID="rserver" + fi +} + echo echo "Finding an available port ..." -get_port +get_socketid +SOCKET="/home/${USER}/.sock${SOCKETID}" LOCALPORT=${PORT} # LOCALPORT=8787 @@ -137,25 +127,24 @@ PUBLIC_IP=$(curl --silent https://checkip.amazonaws.com) echo "On you local machine, open an SSH tunnel like:" # echo " ssh -N -L ${LOCALPORT}:localhost:${PORT} ${USER}@m3-bio1.erc.monash.edu.au" -echo " ssh -N -L ${LOCALPORT}:localhost:${PORT} ${USER}@$(hostname -f)" +echo " ssh -N -L ${LOCALPORT}:${SOCKET} ${USER}@$(hostname -f)" echo " or" -echo " ssh -N -L ${LOCALPORT}:localhost:${PORT} ${USER}@${PUBLIC_IP}" +echo " ssh -N -L ${LOCALPORT}:${SOCKET} ${USER}@${PUBLIC_IP}" # For smux/srun/sbatch jobs, route via the login node to a the compute node where rserver runs - not working for me # echo " ssh -N -L ${LOCALPORT}:${HOSTNAME}:${PORT} ${USER}@m3.massive.org.au" echo echo "Point your web browser at http://localhost:${LOCALPORT}" echo -echo "Login to RStudio with:" -echo " username: ${USER}" -echo " password: ${PASSWORD}" -echo echo "Protip: You can choose your version of R from any of the tags listed here: https://hub.docker.com/r/rocker/rstudio/tags" echo " and set the environment variable IMAGE, eg" echo " IMAGE=rocker/rstudio:4.1.1 $(basename "$0")" echo echo "Starting RStudio Server (R version from image ${IMAGE})" + + + # Set some locales to suppress warnings export LC_CTYPE="C.UTF-8" export LC_TIME="C.UTF-8" @@ -166,10 +155,10 @@ export LC_PAPER="C.UTF-8" # shellcheck disable=SC2034 export LC_MEASUREMENT="C.UTF-8" -if [[ $HPC_ENV == 'm3' ]]; then +if [[ $HPC_ENV == 'slurm' ]]; then if [[ -n ${SLURM_JOB_ID} ]]; then # For Strudel - echo '{"password":"'"${PASSWORD}"'", "port": '"${PORT}"'}' >"${HOME}/.rstudio-rocker/rserver-${SLURM_JOB_ID}.json" + echo '{"tunnelid":"s2rtid'${SOCKETID}'", "socket":"'${SOCKET}'"}'>"${HOME}/.rstudio-rocker/rserver-${SLURM_JOB_ID}.json" fi APPTAINERENV_PASSWORD="${PASSWORD}" \ SINGULARITYENV_PASSWORD="${PASSWORD}" \ @@ -182,7 +171,7 @@ if [[ $HPC_ENV == 'm3' ]]; then --bind "${RSTUDIO_DOT_CONFIG}:/home/rstudio/.config/rstudio" \ --bind "${R_LIBS_USER}:/home/rstudio/R" \ "${IMAGE_LOCATION}" \ - rserver --auth-none=1 --auth-pam-helper-path=pam-helper --www-port="${PORT}" --server-user="${USER}" + rserver --auth-none=1 --www-socket="${SOCKET}" --server-user="${USER}" --www-root-path="s2rtid${SOCKETID}" #--bind ${RSITELIB}:/usr/local/lib/R/site-library \ else APPTAINERENV_PASSWORD="${PASSWORD}" \ @@ -196,7 +185,7 @@ else --bind "${RSTUDIO_DOT_CONFIG}:/home/rstudio/.config/rstudio" \ --bind "${R_LIBS_USER}:/home/rstudio/R" \ "${IMAGE_LOCATION}" \ - rserver --auth-none=1 --auth-pam-helper-path=pam-helper --www-port="${PORT}" --server-user="${USER}" + rserver --auth-none=1 --www-socket="${SOCKET}" --server-user="${USER}" fi printf 'rserver exited' 1>&2