Merge branch '8784-dir-listings'
[arvados.git] / tools / arvbox / lib / arvbox / docker / service / ready / run-service
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 . /usr/local/lib/arvbox/common.sh
7
8 set -eu -o pipefail
9
10 if ! [[ -d /tmp/arvbox-ready ]] ; then
11    echo
12    echo "Arvados-in-a-box starting"
13    echo
14    echo "Note: if this is a fresh arvbox installation, it may take 10-15 minutes (or longer) to download and"
15    echo "install dependencies.  Use \"arvbox log\" to monitor the progress of specific services."
16    echo
17    mkdir -p /tmp/arvbox-ready
18 fi
19
20 sleep 3
21
22 waiting=""
23
24 for s in "${!services[@]}"
25 do
26   if ! [[ -f /tmp/arvbox-ready/$s ]] ; then
27     if nc -z localhost ${services[$s]} ; then
28       echo "$s is ready at $localip:${services[$s]}"
29       touch /tmp/arvbox-ready/$s
30     else
31       waiting="$waiting $s"
32     fi
33   fi
34 done
35
36 if ! docker version >/dev/null 2>/dev/null ; then
37   waiting="$waiting docker"
38 fi
39
40 for sdk_app in arv arv-get cwl-runner arv-mount ; do
41     if ! which $sdk_app >/dev/null ; then
42         waiting="$waiting sdk"
43         break
44     fi
45 done
46
47 if ! (ps x | grep -v grep | grep "crunch-dispatch") > /dev/null ; then
48     waiting="$waiting crunch-dispatch"
49 fi
50
51 export ARVADOS_API_HOST=$localip:${services[api]}
52 export ARVADOS_API_HOST_INSECURE=1
53
54 vm_ok=0
55 if test -s /var/lib/arvados/vm-uuid -a -s /var/lib/arvados/superuser_token; then
56     vm_uuid=$(cat /var/lib/arvados/vm-uuid)
57     export ARVADOS_API_TOKEN=$(cat /var/lib/arvados/superuser_token)
58     if (which arv && arv virtual_machine get --uuid $vm_uuid) >/dev/null 2>/dev/null ; then
59         vm_ok=1
60     fi
61 fi
62
63 if test $vm_ok = 0 ; then
64     waiting="$waiting vm"
65 fi
66
67 if ! [[ -z "$waiting" ]] ; then
68     if ps x | grep -v grep | grep "bundle install" > /dev/null; then
69         gemcount=$(ls /var/lib/gems/ruby/2.1.0/gems 2>/dev/null | wc -l)
70
71         gemlockcount=0
72         for l in /usr/src/arvados/services/api/Gemfile.lock \
73                      /usr/src/arvados/apps/workbench/Gemfile.lock \
74                      /usr/src/sso/Gemfile.lock ; do
75             gc=$(cat $l \
76                         | grep -vE "(GEM|PLATFORMS|DEPENDENCIES|BUNDLED|GIT|$^|remote:|specs:|revision:)" \
77                         | sed 's/^ *//' | sed 's/(.*)//' | sed 's/ *$//' | sort | uniq | wc -l)
78             gemlockcount=$(($gemlockcount + $gc))
79         done
80         waiting="$waiting (installing ruby gems $gemcount of about $gemlockcount)"
81     fi
82
83     if ps x | grep -v grep | grep "c++.*/var/lib/passenger" > /dev/null ; then
84         waiting="$waiting (compiling passenger)"
85     fi
86
87     if ps x | grep -v grep | grep "pip install" > /dev/null; then
88         waiting="$waiting (installing python packages)"
89     fi
90     echo "    Waiting for$waiting ..."
91     exit 1
92 fi
93
94 echo
95 echo "Your Arvados-in-a-box is ready!"
96 echo "Workbench is running at http://$localip"
97
98 rm -r /tmp/arvbox-ready
99
100 sv stop ready >/dev/null