3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: AGPL-3.0
11 read -d] -r SCOPES <<EOF
13 '["GET /arvados/v1/virtual_machines",\n
14 "GET /arvados/v1/keep_services",\n
15 "GET /arvados/v1/keep_services/",\n
16 "GET /arvados/v1/groups",\n
17 "GET /arvados/v1/groups/",\n
18 "GET /arvados/v1/links",\n
19 "GET /arvados/v1/collections",\n
20 "POST /arvados/v1/collections",\n
21 "POST /arvados/v1/links",\n
22 "GET /arvados/v1/users/current",\n
23 "POST /arvados/v1/users/current",\n
24 "GET /arvados/v1/jobs",\n
25 "POST /arvados/v1/jobs",\n
26 "GET /arvados/v1/pipeline_instances",\n
27 "POST /arvados/v1/pipeline_instances",\n
28 "PUT /arvados/v1/pipeline_instances/",\n
29 "GET /arvados/v1/collections/",\n
30 "POST /arvados/v1/collections/",\n
31 "GET /arvados/v1/logs"]'
36 echo >&2 "usage: $0 [options] <identifier>"
38 echo >&2 " <identifier> Arvados cluster name"
40 echo >&2 "$0 options:"
41 echo >&2 " -n, --node <node> Single machine to deploy, use fqdn, optional"
42 echo >&2 " -p, --port <ssh port> SSH port to use (default 22)"
43 echo >&2 " -c, --concurrency <max> Maximum concurrency for puppet runs (default 5)"
44 echo >&2 " -d, --debug Enable debug output"
45 echo >&2 " -h, --help Display this help and exit"
47 echo >&2 "Note: this script requires an arvados token created with these permissions:"
48 echo >&2 ' arv api_client_authorization create_system_auth \'
49 echo -e $SCOPES"]'" >&2
54 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
55 TEMP=`getopt -o hdp:c:n: \
56 --long help,debug,port:,concurrency:,node: \
59 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
60 # Note the quotes around `$TEMP': they are essential!
70 SSH_PORT="$2"; shift 2
73 PUPPET_CONCURRENCY="$2"; shift 2
92 if [[ "$IDENTIFIER" == '' ]]; then
103 let endtime="$(now) + 600"
104 while [ "$endtime" -gt "$(now)" ]; do
105 puppet agent --test --detailed-exitcodes
107 if [ 0 = "$agent_exitcode" ] || [ 2 = "$agent_exitcode" ]; then
113 exit ${agent_exitcode:-99}
117 date=`date +'%Y-%m-%d %H:%M:%S'`
121 function run_puppet() {
124 title "Running puppet on $node"
125 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
127 if [[ "$DEBUG" != "0" ]]; then
128 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" | tee $TMP_FILE
130 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" > $TMP_FILE 2>&1
133 ECODE=${PIPESTATUS[0]}
134 RESULT=$(cat $TMP_FILE)
136 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
137 # Ssh exits 255 if the connection timed out. Just ignore that.
138 # Puppet exits 2 if there are changes. For real!
139 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
140 # was already running
141 echo "ERROR running puppet on $node: exit code $ECODE"
142 if [[ "$DEBUG" == "0" ]]; then
143 title "Command output follows:"
147 if [[ "$ECODE" == "255" ]]; then
148 title "Connection timed out"
151 if [[ "$ECODE" == "2" ]]; then
155 if [[ "$ECODE" == "0" ]]; then
157 echo $node successfully updates
159 echo $node exit code: $ECODE see $TMP_FILE for details
163 function run_command() {
168 title "Running '$command' on $node"
170 if [[ "$DEBUG" != "0" ]]; then
171 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" | tee $TMP_FILE
173 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" > $TMP_FILE 2>&1
177 RESULT=$(cat $TMP_FILE)
179 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
180 # Ssh exists 255 if the connection timed out. Just ignore that, it's possible that this node is
181 # a shell node that is down.
182 title "ERROR running command on $node: exit code $ECODE"
183 if [[ "$DEBUG" == "0" ]]; then
184 title "Command output follows:"
188 if [[ "$ECODE" == "255" ]]; then
189 title "Connection timed out"
193 eval "$return_var=$ECODE"
196 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
197 title "Updating API server"
199 run_puppet $IDENTIFIER.arvadosapi.com ECODE
200 SUM_ECODE=$(($SUM_ECODE + $ECODE))
202 if [[ "$SUM_ECODE" != "0" ]]; then
203 title "ERROR: Updating API server FAILED"
204 EXITCODE=$(($EXITCODE + $SUM_ECODE))
209 if [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
214 title "Loading ARVADOS_API_HOST and ARVADOS_API_TOKEN"
215 if [[ -f "$HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf" ]]; then
216 . $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf
218 title "WARNING: $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf not found."
220 if [[ "$ARVADOS_API_HOST" == "" ]] || [[ "$ARVADOS_API_TOKEN" == "" ]]; then
221 title "ERROR: ARVADOS_API_HOST and/or ARVADOS_API_TOKEN environment variables are not set."
225 title "Gathering list of shell and Keep nodes"
226 SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN rvm-exec default arv virtual_machine list |jq .items[].hostname -r`
227 KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN rvm-exec default arv keep_service list |jq .items[].service_host -r`
230 for n in workbench manage switchyard $SHELL_NODES $KEEP_NODES; do
232 if [[ $n =~ $ARVADOS_API_HOST$ ]]; then
233 # e.g. keep.qr1hi.arvadosapi.com
237 node=$n.$ARVADOS_API_HOST
239 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$node" ]]; then
241 nodes="$nodes ${node%.arvadosapi.com}"
245 if [[ "$nodes" != "" ]]; then
246 ## at this point nodes should be an array containing
247 ## manage.qr1hi, keep.qr1hi, etc
248 ## that should be defined in the .ssh/config file
249 title "Updating in parallel: $nodes"
254 echo $nodes|xargs -d " " -n 1 -P $PUPPET_CONCURRENCY -I {} bash -c "run_puppet {}"
257 if [[ "$NODE" == "" ]]; then
258 title "Locating Arvados Standard Docker images project"
260 JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
261 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
263 if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
264 title "Warning: Arvados Standard Docker Images project not found. Creating it."
266 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group create --group "{\"owner_uuid\":\"$IDENTIFIER-tpzed-000000000000000\", \"name\":\"Arvados Standard Docker Images\", \"group_class\":\"project\"}"`
267 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv link create --link "{\"tail_uuid\":\"$IDENTIFIER-j7d0g-fffffffffffffff\", \"head_uuid\":\"$DOCKER_IMAGES_PROJECT\", \"link_class\":\"permission\", \"name\":\"can_read\" }"
268 if [[ "$?" != "0" ]]; then
269 title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
274 title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
275 GIT_COMMIT=`ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "/usr/share/python2.7/dist/python-arvados-cwl-runner/bin/python -c 'import arvados_cwl ; print arvados_cwl.__version__'" 2>&1 |grep -v INFO:rdflib:RDFLib`
277 if [[ "$?" != "0" ]] || [[ "$GIT_COMMIT" == "" ]]; then
278 title "ERROR: unable to get arvados/jobs Docker image git revision"
281 title "Found git commit for arvados/jobs Docker image: $GIT_COMMIT"
284 run_command shell.$IDENTIFIER ECODE "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN /usr/local/rvm/bin/rvm-exec default arv keep docker" |grep -q $GIT_COMMIT
286 if [[ "$?" == "0" ]]; then
287 title "Found latest arvados/jobs Docker image, nothing to upload"
288 # Just in case it isn't yet, tag the image as latest
289 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker arvados/jobs latest"
291 title "Installing latest arvados/jobs Docker image"
292 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN /usr/local/rvm/bin/rvm-exec default arv keep docker --pull --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs $GIT_COMMIT"
293 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER docker tag --force >/dev/null 2>&1
294 # docker 1.13 no longer supports --force. Sigh.
295 if [[ "$?" == "125" ]]; then
300 ## adding latest tag too refs 9254
301 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER docker tag $FORCE_TAG arvados/jobs:$GIT_COMMIT arvados/jobs:latest
302 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs latest"
303 if [[ "$?" -ne 0 ]]; then
304 title "'git pull' failed exiting..."