7 echo >&2 "usage: $0 (start|stop|test) [options]"
9 echo >&2 "$0 start options:"
10 echo >&2 " -d [port], --doc[=port] Start documentation server (default port 9898)"
11 echo >&2 " -w [port], --workbench[=port] Start workbench server (default port 9899)"
12 echo >&2 " -s [port], --sso[=port] Start SSO server (default port 9901)"
13 echo >&2 " -a [port], --api[=port] Start API server (default port 9900)"
14 echo >&2 " -k, --keep Start Keep servers"
15 echo >&2 " --ssh Enable SSH access to server containers"
16 echo >&2 " -h, --help Display this help and exit"
18 echo >&2 " If no switches are given, the default is to start all"
19 echo >&2 " servers on the default ports."
22 echo >&2 " Stop all servers."
24 echo >&2 "$0 test [testname] [testname] ..."
25 echo >&2 " By default, all tests are run."
30 echo `docker inspect $container |grep IPAddress |cut -f4 -d\"`
33 function start_container {
35 if [[ "$1" != '' ]]; then
39 if [[ "$2" != '' ]]; then
41 args="$args -name $name"
43 if [[ "$3" != '' ]]; then
45 args="$args -v $volume"
47 if [[ "$4" != '' ]]; then
49 args="$args -link $link"
55 args="$args -e ENABLE_SSH=$ENABLE_SSH"
58 `docker ps |grep -P "$name[^/]" -q`
59 if [[ "$?" == "0" ]]; then
60 echo "You have a running container with name $name -- skipping."
64 # Remove any existing container by this name.
65 docker rm "$name" 2>/dev/null
67 echo "Starting container:"
68 echo " docker run $args $image"
69 container=`docker run $args $image`
70 if [[ "$?" != "0" ]]; then
71 echo "Unable to start container"
76 ip=$(ip_address $container )
78 echo "You can ssh into the container with:"
85 declare -a keep_volumes
87 # Initialize the global `keep_volumes' array. If any keep volumes
88 # already appear to exist (mounted volumes with a top-level "keep"
89 # directory), use them; create temporary volumes if necessary.
91 function make_keep_volumes () {
92 # Mount a keep volume if we don't already have one
93 for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do
94 if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then
95 keep_volumes+=($mountpoint)
99 # Create any keep volumes that do not yet exist.
100 while [ ${#keep_volumes[*]} -lt 2 ]
102 new_keep=$(mktemp -d)
103 echo >&2 "mounting 512M tmpfs keep volume in $new_keep"
104 sudo mount -t tmpfs -o size=512M tmpfs $new_keep
106 keep_volumes+=($new_keep)
111 local start_doc=false
112 local start_sso=false
113 local start_api=false
114 local start_workbench=false
115 local start_keep=false
117 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
118 local TEMP=`getopt -o d::s::a::w::kh \
119 --long doc::,sso::,api::,workbench::,keep,help,ssh \
122 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
124 # Note the quotes around `$TEMP': they are essential!
132 "") start_doc=9898; shift 2 ;;
133 *) start_doc=$2; shift 2 ;;
138 "") start_sso=9901; shift 2 ;;
139 *) start_sso=$2; shift 2 ;;
144 "") start_api=9900; shift 2 ;;
145 *) start_api=$2; shift 2 ;;
150 "") start_workbench=9899; shift 2 ;;
151 *) start_workbench=$2; shift 2 ;;
159 # ENABLE_SSH is a global variable
174 # If no options were selected, then start all servers.
175 if [[ $start_doc == false &&
176 $start_sso == false &&
177 $start_api == false &&
178 $start_workbench == false &&
179 $start_keep == false ]]
188 if [[ $start_doc != false ]]
190 start_container "9898:80" "doc_server" '' '' "arvados/doc"
193 if [[ $start_sso != false ]]
195 start_container "9901:443" "sso_server" '' '' "arvados/sso"
198 if [[ $start_api != false ]]
200 start_container "9900:443" "api_server" '' "sso_server:sso" "arvados/api"
203 if [[ $start_workbench != false ]]
205 start_container "9899:80" "workbench_server" '' "api_server:api" "arvados/workbench"
208 if [[ $start_keep != false ]]
210 # create `keep_volumes' array with a list of keep mount points
211 # remove any stale metadata from those volumes before starting them
213 for v in ${keep_volumes[*]}
215 [ -f $v/keep/.metadata.yml ] && sudo rm $v/keep/.metadata.yml
217 start_container "25107:25107" "keep_server_0" \
218 "${keep_volumes[0]}:/dev/keep-0" \
221 start_container "25108:25107" "keep_server_1" \
222 "${keep_volumes[1]}:/dev/keep-0" \
227 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
229 cat >$HOME/.config/arvados/settings.conf <<EOF
230 ARVADOS_API_HOST=$(ip_address "api_server")
231 ARVADOS_API_HOST_INSECURE=yes
232 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
235 echo "To run a test suite:"
236 echo "python -m unittest discover ../sdk/python"
241 docker stop doc_server \
246 keep_server_1 2>/dev/null
253 alltests="python-sdk api"
258 for testname in $alltests
260 echo "testing $testname..."
263 do_start --api --keep --sso
264 export ARVADOS_API_HOST=$(ip_address "api_server")
265 export ARVADOS_API_HOST_INSECURE=yes
266 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
267 python -m unittest discover ../sdk/python
270 docker run -t -i arvados/api \
271 /usr/src/arvados/services/api/script/rake_test.sh
274 echo >&2 "unknown test $testname"