5 if ! test -d /sys/fs/cgroup ; then
6 echo "Arvbox requires cgroups to be mounted at /sys/fs/cgroup in order to use"
7 echo "Docker-in-Docker. Older operating systems that put cgroups in other"
8 echo "places (such as /cgroup) are not supported."
12 if ! which docker >/dev/null 2>/dev/null ; then
13 echo "Arvbox requires Docker. To install, run the following command as root:"
14 echo "curl -sSL https://get.docker.com/ | sh"
18 if test -z "$ARVBOX_DOCKER" ; then
19 if which greadlink >/dev/null 2>/dev/null ; then
20 ARVBOX_DOCKER=$(greadlink -f $(dirname $0)/../lib/arvbox/docker)
22 ARVBOX_DOCKER=$(readlink -f $(dirname $0)/../lib/arvbox/docker)
26 if test -z "$ARVBOX_CONTAINER" ; then
27 ARVBOX_CONTAINER=arvbox
30 if test -z "$ARVBOX_BASE" ; then
31 ARVBOX_BASE="$HOME/.arvbox"
34 if test -z "$ARVBOX_DATA" ; then
35 ARVBOX_DATA="$ARVBOX_BASE/$ARVBOX_CONTAINER"
38 if test -z "$ARVADOS_ROOT" ; then
39 ARVADOS_ROOT="$ARVBOX_DATA/arvados"
42 if test -z "$SSO_ROOT" ; then
43 SSO_ROOT="$ARVBOX_DATA/sso-devise-omniauth-provider"
46 PG_DATA="$ARVBOX_DATA/postgres"
47 VAR_DATA="$ARVBOX_DATA/var"
48 PASSENGER="$ARVBOX_DATA/passenger"
49 GEMS="$ARVBOX_DATA/gems"
50 PIPCACHE="$ARVBOX_DATA/pip"
51 GOSTUFF="$ARVBOX_DATA/gopath"
54 docker inspect $ARVBOX_CONTAINER | grep \"IPAddress\" | head -n1 | tr -d ' ":,\n' | cut -c10-
59 OVERRIDE=$(docker exec -i $ARVBOX_CONTAINER cat /var/run/localip_override 2>/dev/null)
62 if test "$CODE" = 0 ; then
70 if test -f ~/.config/arvados/$ARVBOX_CONTAINER.conf ; then
71 sed "s/ARVADOS_API_HOST=.*/ARVADOS_API_HOST=$(gethost):8000/" <$HOME/.config/arvados/$ARVBOX_CONTAINER.conf >$HOME/.config/arvados/$ARVBOX_CONTAINER.conf.tmp
72 mv ~/.config/arvados/$ARVBOX_CONTAINER.conf.tmp ~/.config/arvados/$ARVBOX_CONTAINER.conf
74 mkdir -p $HOME/.config/arvados
75 cat >$HOME/.config/arvados/$ARVBOX_CONTAINER.conf <<EOF
76 ARVADOS_API_HOST=$(gethost):8000
78 ARVADOS_API_HOST_INSECURE=true
84 FF=/tmp/arvbox-fifo-$$
86 docker logs -f $ARVBOX_CONTAINER > $FF &
90 if echo $line | grep "Workbench is running at" >/dev/null ; then
96 if test -n "$localip" ; then
97 echo "export ARVADOS_API_HOST=$localip:8000"
99 echo "export ARVADOS_API_HOST=$(gethost):8000"
107 if docker ps -a --filter "status=running" | grep -E "$ARVBOX_CONTAINER$" -q ; then
108 echo "Container $ARVBOX_CONTAINER is already running"
112 if docker ps -a | grep -E "$ARVBOX_CONTAINER$" -q ; then
113 echo "Container $ARVBOX_CONTAINER already exists but is not running; use restart or rebuild"
122 if echo "$CONFIG" | grep '^public' ; then
123 if test -n "$ARVBOX_PUBLISH_IP" ; then
124 localip=$ARVBOX_PUBLISH_IP
126 defaultdev=$(/sbin/ip route|awk '/default/ { print $5 }')
127 localip=$(ip addr show $defaultdev | grep 'inet ' | sed 's/ *inet \(.*\)\/.*/\1/')
130 echo $localip > $iptemp
132 PUBLIC="--volume=$iptemp:/var/run/localip_override
138 --publish=25100:25100
139 --publish=25107:25107
140 --publish=25108:25108
147 if echo "$CONFIG" | grep 'demo$' ; then
148 if test -d "$ARVBOX_DATA" ; then
149 echo "It looks like you already have a development container named $ARVBOX_CONTAINER."
150 echo "Set ARVBOX_CONTAINER to set a different name for your demo container"
154 if ! (docker ps -a | grep -E "$ARVBOX_CONTAINER-data$" -q) ; then
155 docker create -v /var/lib/postgresql -v /var/lib/arvados --name $ARVBOX_CONTAINER-data arvados/arvbox-demo /bin/true
160 --name=$ARVBOX_CONTAINER \
162 --volumes-from $ARVBOX_CONTAINER-data \
164 arvados/arvbox-demo$TAG
168 mkdir -p "$PG_DATA" "$VAR_DATA" "$PASSENGER" "$GEMS" "$PIPCACHE" "$GOSTUFF"
171 if ! test -d "$ARVADOS_ROOT" ; then
172 git clone https://github.com/curoverse/arvados.git "$ARVADOS_ROOT"
174 if ! test -d "$SSO_ROOT" ; then
175 git clone https://github.com/curoverse/sso-devise-omniauth-provider.git "$SSO_ROOT"
178 if test "$CONFIG" = test ; then
180 mkdir -p $VAR_DATA/test
184 --name=$ARVBOX_CONTAINER \
186 "--volume=$ARVADOS_ROOT:/usr/src/arvados:rw" \
187 "--volume=$SSO_ROOT:/usr/src/sso:rw" \
188 "--volume=$PG_DATA:/var/lib/postgresql:rw" \
189 "--volume=$VAR_DATA:/var/lib/arvados:rw" \
190 "--volume=$PASSENGER:/var/lib/passenger:rw" \
191 "--volume=$GEMS:/var/lib/gems:rw" \
192 "--volume=$PIPCACHE:/var/lib/pip:rw" \
193 "--volume=$GOSTUFF:/var/lib/gopath:rw" \
194 arvados/arvbox-dev$TAG \
195 /usr/local/bin/runsvinit -svdir=/etc/test-service
199 /usr/local/lib/arvbox/runsu.sh \
200 /usr/local/lib/arvbox/waitforpostgres.sh
204 /usr/local/lib/arvbox/runsu.sh \
205 /var/lib/arvbox/service/sso/run-service --only-setup
209 /usr/local/lib/arvbox/runsu.sh \
210 /var/lib/arvbox/service/api/run-service --only-setup
214 /usr/local/lib/arvbox/runsu.sh \
215 /usr/src/arvados/build/run-tests.sh \
216 --temp /var/lib/arvados/test \
217 WORKSPACE=/usr/src/arvados \
218 GEM_HOME=/var/lib/gems \
220 elif echo "$CONFIG" | grep 'dev$' ; then
223 --name=$ARVBOX_CONTAINER \
225 "--volume=$ARVADOS_ROOT:/usr/src/arvados:rw" \
226 "--volume=$SSO_ROOT:/usr/src/sso:rw" \
227 "--volume=$PG_DATA:/var/lib/postgresql:rw" \
228 "--volume=$VAR_DATA:/var/lib/arvados:rw" \
229 "--volume=$PASSENGER:/var/lib/passenger:rw" \
230 "--volume=$GEMS:/var/lib/gems:rw" \
231 "--volume=$PIPCACHE:/var/lib/pip:rw" \
232 "--volume=$GOSTUFF:/var/lib/gopath:rw" \
234 arvados/arvbox-dev$TAG
237 echo "The Arvados source code is checked out at: $ARVADOS_ROOT"
239 echo "Unknown configuration '$CONFIG'"
245 if docker ps -a --filter "status=running" | grep -E "$ARVBOX_CONTAINER$" -q ; then
246 docker stop $ARVBOX_CONTAINER
249 VOLUMES=--volumes=true
250 if docker ps -a --filter "status=created" | grep -E "$ARVBOX_CONTAINER$" -q ; then
251 docker rm $VOLUMES $ARVBOX_CONTAINER
253 if docker ps -a --filter "status=exited" | grep -E "$ARVBOX_CONTAINER$" -q ; then
254 docker rm $VOLUMES $ARVBOX_CONTAINER
259 if ! test -f "$ARVBOX_DOCKER/Dockerfile.base" ; then
260 echo "Could not find Dockerfile (expected it at $ARVBOX_DOCKER/Dockerfile.base)"
263 docker build $NO_CACHE -t arvados/arvbox-base -f "$ARVBOX_DOCKER/Dockerfile.base" "$ARVBOX_DOCKER"
264 if test "$1" = localdemo -o "$1" = publicdemo ; then
265 docker build $NO_CACHE -t arvados/arvbox-demo -f "$ARVBOX_DOCKER/Dockerfile.demo" "$ARVBOX_DOCKER"
267 docker build $NO_CACHE -t arvados/arvbox-dev -f "$ARVBOX_DOCKER/Dockerfile.dev" "$ARVBOX_DOCKER"
273 localdemo|publicdemo|dev|publicdev|test)
277 echo "Argument to $subcmd must be one of localdemo, publicdemo, dev, publicdev, test"
284 if test -n "$subcmd" ; then
295 NO_CACHE=--no-cache build $@
304 exec docker exec -ti $ARVBOX_CONTAINER /usr/bin/env TERM=$TERM GEM_HOME=/var/lib/gems /bin/bash
308 exec docker exec -i $ARVBOX_CONTAINER /usr/bin/env GEM_HOME=/var/lib/gems /bin/bash -
337 exec xdg-open http://$(gethost)
341 echo "Selected: $ARVBOX_CONTAINER"
342 if docker ps -a --filter "status=running" | grep -E "$ARVBOX_CONTAINER$" -q ; then
343 echo "Status: running"
344 echo "Container IP: $(getip)"
345 echo "Published host: $(gethost)"
347 echo "Status: not running"
349 if test -d "$ARVBOX_DATA" ; then
350 echo "Data: $ARVBOX_DATA"
351 elif docker ps -a | grep -E "$ARVBOX_CONTAINER-data$" -q ; then
352 echo "Data: $ARVBOX_CONTAINER-data"
360 if test -d "$ARVBOX_DATA" ; then
361 if test "$subcmd" = destroy ; then
362 if test "$1" != -f ; then
363 echo "WARNING! This will delete your entire arvbox ($ARVBOX_DATA)."
364 echo "Use destroy -f if you really mean it."
368 rm -rf "$ARVBOX_DATA"
370 if test "$1" != -f ; then
371 echo "WARNING! This will delete your arvbox data ($ARVBOX_DATA)."
372 echo "Code and downloaded packages will be preserved."
373 echo "Use reset -f if you really mean it."
377 rm -rf "$ARVBOX_DATA/postgres"
378 rm -rf "$ARVBOX_DATA/var"
381 if test "$1" != -f ; then
382 echo "WARNING! This will delete your data container $ARVBOX_CONTAINER-data. Use -f if you really mean it."
386 docker rm "$ARVBOX_CONTAINER-data"
391 if test -n "$1" ; then
392 exec docker exec -ti $ARVBOX_CONTAINER /usr/bin/env TERM=$TERM less --follow-name -R +GF "/etc/service/$1/log/main/current"
394 exec docker exec -ti $ARVBOX_CONTAINER /usr/bin/env TERM=$TERM tail $(docker exec -ti $ARVBOX_CONTAINER find -L /etc -path '/etc/service/*/log/main/current' -printf " %p")
399 if test -n "$1" ; then
400 exec docker exec -ti $ARVBOX_CONTAINER cat "$@"
402 echo "Usage: $0 $subcmd <files>"
407 exec docker exec -ti $ARVBOX_CONTAINER /usr/bin/env TERM=$TERM ls "$@"
411 if test -n "$1" -a -n "$2" ; then
412 exec docker exec -ti $ARVBOX_CONTAINER sv "$@"
414 echo "Usage: $0 $subcmd <start|stop|restart> <service>"
415 echo "Available services:"
416 exec docker exec -ti $ARVBOX_CONTAINER ls /etc/service
421 if test -n "$2" ; then
422 cp -r "$ARVBOX_BASE/$1" "$ARVBOX_BASE/$2"
423 echo "Created new arvbox $2"
424 echo "export ARVBOX_CONTAINER=$2"
426 echo "clone <from> <to> clone an arvbox"
427 echo "available arvboxes: $(ls $ARVBOX_BASE)"
432 echo "Arvados-in-a-box http://arvados.org"
434 echo "build <config> build arvbox Docker image"
435 echo "rebuild <config> build arvbox Docker image, no layer cache"
436 echo "start|run <config> [tag] start $ARVBOX_CONTAINER container"
437 echo "open open arvbox workbench in a web browser"
438 echo "shell enter arvbox shell"
439 echo "ip print arvbox docker container ip address"
440 echo "host print arvbox published host"
441 echo "status print some information about current arvbox"
442 echo "stop stop arvbox container"
443 echo "restart <config> stop, then run again"
444 echo "reboot <config> stop, build arvbox Docker image, run"
445 echo "reset delete arvbox arvados data (be careful!)"
446 echo "destroy delete all arvbox code and data (be careful!)"
447 echo "log <service> tail log of specified service"
448 echo "ls <options> list directories inside arvbox"
449 echo "cat <files> get contents of files inside arvbox"
450 echo "pipe run a bash script piped in from stdin"
451 echo "sv <start|stop|restart> <service> change state of service inside arvbox"
452 echo "clone <from> <to> clone an arvbox"