3 DOCKER=`which docker.io`
5 if [[ "$DOCKER" == "" ]]; then
13 echo >&2 "usage: $0 (start|stop|restart|test) [options]"
15 echo >&2 "$0 start/stop/restart options:"
16 echo >&2 " -d[port], --doc[=port] Documentation server (default port 9898)"
17 echo >&2 " -w[port], --workbench[=port] Workbench server (default port 9899)"
18 echo >&2 " -s[port], --sso[=port] SSO server (default port 9901)"
19 echo >&2 " -a[port], --api[=port] API server (default port 9900)"
20 echo >&2 " -c, --compute Compute nodes (starts 2)"
21 echo >&2 " -v, --vm Shell server"
22 echo >&2 " -n, --nameserver Nameserver"
23 echo >&2 " -k, --keep Keep servers"
24 echo >&2 " -h, --help Display this help and exit"
26 echo >&2 " If no options are given, the action is applied to all servers."
28 echo >&2 "$0 test [testname] [testname] ..."
29 echo >&2 " By default, all tests are run."
34 echo `$DOCKER inspect $container |grep IPAddress |cut -f4 -d\"`
37 function start_container {
39 if [[ "$1" != '' ]]; then
43 if [[ "$2" != '' ]]; then
45 if [[ "$name" == "api_server" ]]; then
46 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname api -P --name $name"
47 elif [[ "$name" == "compute" ]]; then
48 name=$name$COMPUTE_COUNTER
49 # We need --privileged because we run docker-inside-docker on the compute nodes
50 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname compute$COMPUTE_COUNTER -P --privileged --name $name"
51 let COMPUTE_COUNTER=$(($COMPUTE_COUNTER + 1))
53 args="$args --dns=172.17.42.1 --dns-search=dev.arvados --hostname ${name#_server} --name $name"
56 if [[ "$3" != '' ]]; then
58 args="$args -v $volume"
60 if [[ "$4" != '' ]]; then
62 args="$args --link $link"
66 `$DOCKER ps |grep -P "$name[^/]" -q`
67 if [[ "$?" == "0" ]]; then
68 echo "You have a running container with name $name -- skipping."
72 # Remove any existing container by this name.
73 $DOCKER rm "$name" 2>/dev/null
75 echo "Starting container:"
76 #echo " $DOCKER run --dns=127.0.0.1 $args $image"
77 echo " $DOCKER run $args $image"
78 container=`$DOCKER run $args $image`
79 if [ "$?" != "0" -o "$container" = "" ]; then
80 echo "Unable to start container"
83 echo "Started container: $container"
86 if [[ "$name" == "doc_server" ]]; then
88 echo "*****************************************************************"
89 echo "You can access the Arvados documentation at http://localhost:${port%:*}"
90 echo "*****************************************************************"
94 if [[ "$name" == "workbench_server" ]]; then
96 echo "*****************************************************************"
97 echo "You can access the Arvados workbench at http://localhost:${port%:*}"
98 echo "*****************************************************************"
105 declare -a keep_volumes
107 # Initialize the global `keep_volumes' array. If any keep volumes
108 # already appear to exist (mounted volumes with a top-level "keep"
109 # directory), use them; create temporary volumes if necessary.
111 function make_keep_volumes () {
112 # Mount a keep volume if we don't already have one
113 for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do
114 if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then
115 keep_volumes+=($mountpoint)
119 # Create any keep volumes that do not yet exist.
120 while [ ${#keep_volumes[*]} -lt 2 ]
122 new_keep=$(mktemp -d)
123 echo >&2 "mounting 2G tmpfs keep volume in $new_keep"
124 sudo mount -t tmpfs -o size=2G tmpfs $new_keep
126 keep_volumes+=($new_keep)
131 local start_doc=false
132 local start_sso=false
133 local start_api=false
134 local start_compute=false
135 local start_workbench=false
137 local start_nameserver=false
138 local start_keep=false
140 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
141 local TEMP=`getopt -o d::s::a::cw::nkvh \
142 --long doc::,sso::,api::,compute,workbench::,nameserver,keep,vm,help \
145 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
147 # Note the quotes around `$TEMP': they are essential!
155 "") start_doc=9898; shift 2 ;;
156 *) start_doc=$2; shift 2 ;;
161 "") start_sso=9901; shift 2 ;;
162 *) start_sso=$2; shift 2 ;;
167 "") start_api=9900; shift 2 ;;
168 *) start_api=$2; shift 2 ;;
177 "") start_workbench=9899; shift 2 ;;
178 *) start_workbench=$2; shift 2 ;;
186 start_nameserver=true
204 # If no options were selected, then start all servers.
205 if [[ $start_doc == false &&
206 $start_sso == false &&
207 $start_api == false &&
208 $start_compute == false &&
209 $start_workbench == false &&
210 $start_vm == false &&
211 $start_nameserver == false &&
212 $start_keep == false ]]
215 #the sso server is currently not used by default so don't start it unless explicitly requested
221 start_nameserver=true
225 if [[ $start_sso != false ]]
227 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
230 if [[ $start_api != false ]]
232 if [[ $start_sso != false ]]; then
233 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
235 start_container "$start_api:443" "api_server" '' '' "arvados/api"
239 if [[ $start_nameserver != false ]]
241 # We rely on skydock and skydns for dns discovery between the slurm controller and compute nodes,
242 # so make sure they are running
243 $DOCKER ps | grep skydns >/dev/null
244 if [[ "$?" != "0" ]]; then
245 echo "Starting crosbymichael/skydns container..."
246 $DOCKER rm "skydns" 2>/dev/null
247 $DOCKER run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
249 $DOCKER ps | grep skydock >/dev/null
250 if [[ "$?" != "0" ]]; then
251 echo "Starting crosbymichael/skydock container..."
252 $DOCKER rm "skydock" 2>/dev/null
253 $DOCKER run -d -v /var/run/docker.sock:/docker.sock --name skydock crosbymichael/skydock -ttl 30 -environment dev -s /docker.sock -domain arvados -name skydns
257 if [[ $start_compute != false ]]
259 for i in `seq 0 $(($start_compute - 1))`; do
260 start_container "" "compute" '' "api_server:api" "arvados/compute"
264 if [[ $start_keep != false ]]
266 # create `keep_volumes' array with a list of keep mount points
267 # remove any stale metadata from those volumes before starting them
269 for v in ${keep_volumes[*]}
271 [ -f $v/keep/.metadata.yml ] && sudo rm $v/keep/.metadata.yml
273 start_container "25107:25107" "keep_server_0" \
274 "${keep_volumes[0]}:/keep-data" \
277 start_container "25108:25107" "keep_server_1" \
278 "${keep_volumes[1]}:/keep-data" \
283 if [[ $start_doc != false ]]
285 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
288 if [[ $start_vm != false ]]
290 start_container "" "shell" '' "api_server:api" "arvados/shell"
293 if [[ $start_workbench != false ]]
295 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
298 if [[ $start_api != false ]]
300 if [[ -f "api/generated/superuser_token" ]]
302 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
304 cat >$HOME/.config/arvados/settings.conf <<EOF
305 ARVADOS_API_HOST=$(ip_address "api_server")
306 ARVADOS_API_HOST_INSECURE=yes
307 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
318 local stop_compute=""
319 local stop_workbench=""
320 local stop_nameserver=""
324 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
325 local TEMP=`getopt -o dsacwnkvh \
326 --long doc,sso,api,compute,workbench,nameserver,keep,vm,help \
329 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
331 # Note the quotes around `$TEMP': they are essential!
338 stop_doc=doc_server ; shift ;;
340 stop_sso=sso_server ; shift ;;
342 stop_api=api_server ; shift ;;
344 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
346 stop_workbench=workbench_server ; shift ;;
348 stop_nameserver="skydock skydns" ; shift ;;
350 stop_vm="shell" ; shift ;;
352 stop_keep="keep_server_0 keep_server_1" ; shift ;;
364 # If no options were selected, then stop all servers.
365 if [[ $stop_doc == "" &&
368 $stop_compute == "" &&
369 $stop_workbench == "" &&
371 $stop_nameserver == "" &&
377 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '`
378 stop_workbench=workbench_server
380 stop_nameserver="skydock skydns"
381 stop_keep="keep_server_0 keep_server_1"
384 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_vm \
392 alltests="python-sdk api"
397 for testname in $alltests
399 echo "testing $testname..."
402 do_start --api --keep --sso
403 export ARVADOS_API_HOST=$(ip_address "api_server")
404 export ARVADOS_API_HOST_INSECURE=yes
405 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
406 python -m unittest discover ../sdk/python
409 $DOCKER run -t -i arvados/api \
410 /usr/src/arvados/services/api/script/rake_test.sh
413 echo >&2 "unknown test $testname"