forked from sib-swiss/AWS-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_rstudio_server
More file actions
executable file
·113 lines (102 loc) · 3.07 KB
/
run_rstudio_server
File metadata and controls
executable file
·113 lines (102 loc) · 3.07 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
USAGE="Usage: run_rstudio_server -i <image> -u <user list> -p <admin password>\n
\n
This command generates docker containers based on a rstudio server container for each user\n
\n
-i image name. If not present yet it will be downloaded from docker hub. Should be based on a rocker/rstudio image. Default: rocker/rstudio\n
-u user list. Tab delimited list of users with three columns: port, user name, password\n
-p admin password. Password used for the admin container.\n
-m maximum memory for the user container. Default: 16g.\n
-c maximum number of cpu for the user container. Default: 4.
-n container name prefix. Default: jupyter \n
-a add admin container[yes/no]. Default: yes \n"
while getopts ":i:u:p:m:c:n:a:" opt
do
case $opt in
i)
IMAGE=$OPTARG
;;
u)
USERLIST=$OPTARG
;;
p)
MASTERPW=$OPTARG
;;
m)
MEMORY=$OPTARG
;;
c)
CPU=$OPTARG
;;
n)
CONTAINER_NAME=$OPTARG
;;
a)
ADD_ADMIN=$OPTARG
;;
\?)
echo -e "Invalid option: -$OPTARG \n" >&2
echo -e $USAGE >&2
exit 1
;;
:)
echo -e "Option -$OPTARG requires an argument. \n"
echo -e $USAGE >&2
exit 1
;;
esac
done
# return usage if no options are passed
if [ $OPTIND -eq 1 ]
then
echo -e "No options were passed. \n" >&2
echo -e $USAGE >&2
exit 1
fi
# required options
if [ "$USERLIST" == "" ]; then echo "option -u is missing, but required">&2 && exit 1; fi
if [ "$MASTERPW" == "" ]; then echo "option -p is missing, but required">&2 && exit 1; fi
# default values
if [ "$IMAGE" == "" ]; then IMAGE=rocker/rstudio; fi
if [ "$MEMORY" == "" ]; then MEMORY=16g; fi
if [ "$CPU" == "" ]; then CPU=4; fi
if [ "$CONTAINER_NAME" == "" ]; then CONTAINER_NAME=rstudio; fi
if [ "$ADD_ADMIN" == "" ]; then ADD_ADMIN=yes; fi
# create general volume that will be populated with read-only data
docker volume create data
# create general volume for group work
docker volume create group
if [ "$ADD_ADMIN" == "yes" ]
then
docker run \
-d \
-e ROOT=TRUE \
-p 9000:8787 \
--name rstudio_admin \
-e PASSWORD=$MASTERPW \
--mount source=data,target=/home/rstudio/data \
--mount source=group,target=/group_work \
$IMAGE
fi
# remove carriage returns and spaces and pipe to while loop
cat $USERLIST | tr -d '\015\040' | while read port user password
do
# create user volume. If the container crashes the volume keeps existing.
docker volume create $user
# generate container for each user
# mount user volume, data volume (general, read only) and group work volume (general, read and write)
# the permissions of general volumes (data and group work) need to be changed with the master container (this can probably be coded as well)
docker run \
-d \
--cpus=$CPU \
--memory=$MEMORY \
--restart=on-failure:10 \
--name "$CONTAINER_NAME"_"$user" \
-p $port:8787 \
--name rstudio_"$user" \
-e PASSWORD=$password \
--mount source=$user,target=/home/rstudio \
--mount source=data,target=/data,readonly \
--mount source=group,target=/group_work \
$IMAGE
done