-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingularity_start_horae.sh
91 lines (65 loc) · 3.08 KB
/
singularity_start_horae.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#! /usr/bin/env bash
# mount project folder inside container:
export PROJECT_FOLDER="/projects/academic/adamw/"
# path to singularity container file. If you want to use a different image, you'll need
# to update this line.
#export CONTAINER_PATH="/panasas/scratch/grp-adamw/singularity/$USER/singularity-geospatial-r_latest.sif"
export CONTAINER_PATH="/panasas/scratch/grp-adamw/singularity/adamw/AdamWilsonLab-emma_docker-latest.sif"
export CONTAINER_PATH="/ssd_data/singularity/$USER/AdamWilsonLab-emma_docker-latest.sif"
# to use for ssh:
export SERVER_URL="horae.ccr.buffalo.edu"
# folder to hold temporary singularity files - unique for each user:
export SINGULARITY_LOCALCACHEDIR="/panasas/scratch/grp-adamw/singularity/"$USER
# Run as particular group to use group storage
newgrp grp-adamw
##################################################
# shouldn't need to edit anything below this point
# define a few more folders used by singularity
export TMPDIR=$SINGULARITY_LOCALCACHEDIR
export SINGULARITY_CACHEDIR=$SINGULARITY_LOCALCACHEDIR
export SINGULARITY_TMPDIR=$SINGULARITY_LOCALCACHEDIR
# Create the folders if they don't already exist
mkdir -p $SINGULARITY_LOCALCACHEDIR/tmp
mkdir -p $SINGULARITY_LOCALCACHEDIR/run
mkdir -p $SINGULARITY_LOCALCACHEDIR/rstudio
# Following https://www.rocker-project.org/use/singularity/
# Find an open port
export PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
# generate a random password
export PASSWORD=$(openssl rand -base64 15)
# report on current settings
echo "
For debugging:
-----------------------------------------
PROJECT_FOLDER is set to: $PROJECT_FOLDER
CONTAINER_PATH is set to: $CONTAINER_PATH
SERVER_URL is set to: $SERVER_URL
SINGULARITY_LOCALCACHEDIR is set to: $SINGULARITY_LOCALCACHEDIR
PORT is set to: $PORT
-----------------------------------------
"
# Start the instance using variables above
singularity instance start \
--bind $PROJECT_FOLDER:$PROJECT_FOLDER \
--bind $SINGULARITY_LOCALCACHEDIR/tmp:/tmp \
--bind $SINGULARITY_LOCALCACHEDIR/run:/run \
--bind $SINGULARITY_LOCALCACHEDIR/rstudio:/var/lib/rstudio-server \
$CONTAINER_PATH rserver
# Start the rserver within the container
singularity exec instance://rserver rserver --server-user=$USER --www-port ${PORT} --auth-none=0 --auth-pam-helper-path=pam-helper &
# write a file with the details (port and password)
echo "
1. SSH tunnel from your workstation using the following command:
ssh -N -L 8787:${SERVER_URL}:${PORT} ${USER}@${SERVER_URL}
and point your web browser to http://localhost:8787
2. log in to RStudio Server using the following credentials:
user: ${USER}
password: ${PASSWORD}
3. to repeat these instructions:
cat ~/singularity_status.txt
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:
singularity instance stop rserver
" > ~/singularity_status.txt
cat ~/singularity_status.txt