4 DOCKER=`which docker.io`
6 if [[ "$DOCKER" == "" ]]; then
14 echo >&2 "usage: $0 (start|stop|restart|test) [options]"
16 echo >&2 "$0 start/stop/restart options:"
17 echo >&2 " -d[port], --doc[=port] Documentation server (default port 9898)"
18 echo >&2 " -w[port], --workbench[=port] Workbench server (default port 9899)"
19 echo >&2 " -s[port], --sso[=port] SSO server (default port 9901)"
20 echo >&2 " -a[port], --api[=port] API server (default port 9900)"
21 echo >&2 " -c[count], --compute[=count] Compute nodes (default starts 2)"
22 echo >&2 " -k, --keep Keep servers"
23 echo >&2 " --ssh Enable SSH access to server containers"
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 --hostname api --name $name"
47 elif [[ "$name" == "compute" ]]; then
48 name=$name$COMPUTE_COUNTER
49 args="$args --hostname compute$COMPUTE_COUNTER --name $name"
50 let COMPUTE_COUNTER=$(($COMPUTE_COUNTER + 1))
52 args="$args --name $name"
55 if [[ "$3" != '' ]]; then
57 args="$args -v $volume"
59 if [[ "$4" != '' ]]; then
61 args="$args --link $link"
67 args="$args -e ENABLE_SSH=$ENABLE_SSH"
70 `$DOCKER ps |grep -P "$name[^/]" -q`
71 if [[ "$?" == "0" ]]; then
72 echo "You have a running container with name $name -- skipping."
76 # Remove any existing container by this name.
77 $DOCKER rm "$name" 2>/dev/null
79 echo "Starting container:"
80 echo " $DOCKER run $args $image"
81 container=`$DOCKER run $args $image`
82 if [[ "$?" != "0" ]]; then
83 echo "Unable to start container"
88 ip=$(ip_address $container )
90 echo "You can ssh into the container with:"
96 if [[ "$name" == "doc_server" ]]; then
98 echo "*****************************************************************"
99 echo "You can access the Arvados documentation at http://localhost:${port%:*}"
100 echo "*****************************************************************"
104 if [[ "$name" == "workbench_server" ]]; then
106 echo "*****************************************************************"
107 echo "You can access the Arvados workbench at http://localhost:${port%:*}"
108 echo "*****************************************************************"
115 declare -a keep_volumes
117 # Initialize the global `keep_volumes' array. If any keep volumes
118 # already appear to exist (mounted volumes with a top-level "keep"
119 # directory), use them; create temporary volumes if necessary.
121 function make_keep_volumes () {
122 # Mount a keep volume if we don't already have one
123 for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do
124 if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then
125 keep_volumes+=($mountpoint)
129 # Create any keep volumes that do not yet exist.
130 while [ ${#keep_volumes[*]} -lt 2 ]
132 new_keep=$(mktemp -d)
133 echo >&2 "mounting 512M tmpfs keep volume in $new_keep"
134 sudo mount -t tmpfs -o size=512M tmpfs $new_keep
136 keep_volumes+=($new_keep)
141 local start_doc=false
142 local start_sso=false
143 local start_api=false
144 local start_compute=false
145 local start_workbench=false
146 local start_keep=false
148 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
149 local TEMP=`getopt -o d::s::a::c::w::kh \
150 --long doc::,sso::,api::,compute::,workbench::,keep,help,ssh \
153 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
155 # Note the quotes around `$TEMP': they are essential!
163 "") start_doc=9898; shift 2 ;;
164 *) start_doc=$2; shift 2 ;;
169 "") start_sso=9901; shift 2 ;;
170 *) start_sso=$2; shift 2 ;;
175 "") start_api=9900; shift 2 ;;
176 *) start_api=$2; shift 2 ;;
181 "") start_compute=2; shift 2 ;;
182 *) start_compute=$2; shift 2 ;;
187 "") start_workbench=9899; shift 2 ;;
188 *) start_workbench=$2; shift 2 ;;
196 # ENABLE_SSH is a global variable
211 # If no options were selected, then start all servers.
212 if [[ $start_doc == false &&
213 $start_sso == false &&
214 $start_api == false &&
215 $start_compute == false &&
216 $start_workbench == false &&
217 $start_keep == false ]]
227 if [[ $start_sso != false ]]
229 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
232 if [[ $start_api != false ]]
234 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
237 if [[ $start_compute != false ]]
239 for i in `seq 0 $(($start_compute - 1))`; do
240 start_container "" "compute" '' "api_server:api" "arvados/compute"
244 if [[ $start_keep != false ]]
246 # create `keep_volumes' array with a list of keep mount points
247 # remove any stale metadata from those volumes before starting them
249 for v in ${keep_volumes[*]}
251 [ -f $v/keep/.metadata.yml ] && sudo rm $v/keep/.metadata.yml
253 start_container "25107:25107" "keep_server_0" \
254 "${keep_volumes[0]}:/dev/keep-0" \
257 start_container "25108:25107" "keep_server_1" \
258 "${keep_volumes[1]}:/dev/keep-0" \
263 if [[ $start_doc != false ]]
265 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
268 if [[ $start_workbench != false ]]
270 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
273 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
275 cat >$HOME/.config/arvados/settings.conf <<EOF
276 ARVADOS_API_HOST=$(ip_address "api_server")
277 ARVADOS_API_HOST_INSECURE=yes
278 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
288 local stop_compute=""
289 local stop_workbench=""
292 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
293 local TEMP=`getopt -o dsacwkh \
294 --long doc,sso,api,compute,workbench,keep,help \
297 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
299 # Note the quotes around `$TEMP': they are essential!
306 stop_doc=doc_server ; shift ;;
308 stop_sso=sso_server ; shift ;;
310 stop_api=api_server ; shift ;;
312 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
314 stop_workbench=workbench_server ; shift ;;
316 stop_keep="keep_server_0 keep_server_1" ; shift ;;
328 # If no options were selected, then stop all servers.
329 if [[ $stop_doc == "" &&
332 $stop_compute == "" &&
333 $stop_workbench == "" &&
339 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '`
340 stop_workbench=workbench_server
341 stop_keep="keep_server_0 keep_server_1"
344 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_keep \
352 alltests="python-sdk api"
357 for testname in $alltests
359 echo "testing $testname..."
362 do_start --api --keep --sso
363 export ARVADOS_API_HOST=$(ip_address "api_server")
364 export ARVADOS_API_HOST_INSECURE=yes
365 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
366 python -m unittest discover ../sdk/python
369 $DOCKER run -t -i arvados/api \
370 /usr/src/arvados/services/api/script/rake_test.sh
373 echo >&2 "unknown test $testname"