3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: AGPL-3.0
12 read -d] -r SCOPES <<EOF
14 '["GET /arvados/v1/virtual_machines",\n
15 "GET /arvados/v1/keep_services",\n
16 "GET /arvados/v1/keep_services/",\n
17 "GET /arvados/v1/groups",\n
18 "GET /arvados/v1/groups/",\n
19 "GET /arvados/v1/links",\n
20 "GET /arvados/v1/collections",\n
21 "POST /arvados/v1/collections",\n
22 "POST /arvados/v1/links",\n
23 "GET /arvados/v1/users/current",\n
24 "POST /arvados/v1/users/current",\n
25 "GET /arvados/v1/jobs",\n
26 "POST /arvados/v1/jobs",\n
27 "GET /arvados/v1/pipeline_instances",\n
28 "POST /arvados/v1/pipeline_instances",\n
29 "PUT /arvados/v1/pipeline_instances/",\n
30 "GET /arvados/v1/collections/",\n
31 "POST /arvados/v1/collections/",\n
32 "GET /arvados/v1/logs"]'
37 echo >&2 "usage: $0 [options] <identifier>"
39 echo >&2 " <identifier> Arvados cluster name"
41 echo >&2 "$0 options:"
42 echo >&2 " -n, --node <node> Single machine to deploy, use fqdn, optional"
43 echo >&2 " -p, --port <ssh port> SSH port to use (default 22)"
44 echo >&2 " -c, --concurrency <max> Maximum concurrency for puppet runs (default 5)"
45 echo >&2 " -u, --unmanaged Deploy to unmanaged node/cluster"
46 echo >&2 " -d, --debug Enable debug output"
47 echo >&2 " -h, --help Display this help and exit"
49 echo >&2 "Note: this script requires an arvados token created with these permissions:"
50 echo >&2 ' arv api_client_authorization create_system_auth \'
51 echo -e $SCOPES"]'" >&2
56 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
57 TEMP=`getopt -o hudp:c:n: \
58 --long help,unmanaged,debug,port:,concurrency:,node: \
61 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
62 # Note the quotes around `$TEMP': they are essential!
72 SSH_PORT="$2"; shift 2
75 PUPPET_CONCURRENCY="$2"; shift 2
98 if [[ "$IDENTIFIER" == '' ]]; then
110 let endtime="$(now) + 600"
111 while [ "$endtime" -gt "$(now)" ]; do
112 puppet agent --test --detailed-exitcodes
114 if [ 0 = "$agent_exitcode" ] || [ 2 = "$agent_exitcode" ]; then
120 exit ${agent_exitcode:-99}
125 let endtime="$(now) + 600"
126 while [ "$endtime" -gt "$(now)" ]; do
130 if [ 0 = "$apt_exitcode" ]; then
136 exit ${apt_exitcode:-99}
140 date=`date +'%Y-%m-%d %H:%M:%S'`
144 function update_node() {
145 if [[ $UNMANAGED -ne 0 ]]; then
155 title "Running apt on $node"
156 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
158 if [[ "$DEBUG" != "0" ]]; then
159 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$APT_AGENT'" | tee $TMP_FILE
161 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$APT_AGENT'" > $TMP_FILE 2>&1
164 ECODE=${PIPESTATUS[0]}
165 RESULT=$(cat $TMP_FILE)
167 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
168 # Ssh exits 255 if the connection timed out. Just ignore that.
169 echo "ERROR running apt on $node: exit code $ECODE"
170 if [[ "$DEBUG" == "0" ]]; then
171 title "Command output follows:"
175 if [[ "$ECODE" == "255" ]]; then
176 title "Connection timed out"
180 if [[ "$ECODE" == "0" ]]; then
182 echo $node successfully updated
184 echo $node exit code: $ECODE see $TMP_FILE for details
188 function run_puppet() {
191 title "Running puppet on $node"
192 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
194 if [[ "$DEBUG" != "0" ]]; then
195 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" | tee $TMP_FILE
197 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" > $TMP_FILE 2>&1
200 ECODE=${PIPESTATUS[0]}
201 RESULT=$(cat $TMP_FILE)
203 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
204 # Ssh exits 255 if the connection timed out. Just ignore that.
205 # Puppet exits 2 if there are changes. For real!
206 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
207 # was already running
208 echo "ERROR running puppet on $node: exit code $ECODE"
209 if [[ "$DEBUG" == "0" ]]; then
210 title "Command output follows:"
214 if [[ "$ECODE" == "255" ]]; then
215 title "Connection timed out"
218 if [[ "$ECODE" == "2" ]]; then
222 if [[ "$ECODE" == "0" ]]; then
224 echo $node successfully updated
226 echo $node exit code: $ECODE see $TMP_FILE for details
230 function run_command() {
235 title "Running '$command' on $node"
237 if [[ "$DEBUG" != "0" ]]; then
238 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" | tee $TMP_FILE
240 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" > $TMP_FILE 2>&1
244 RESULT=$(cat $TMP_FILE)
246 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
247 # Ssh exists 255 if the connection timed out. Just ignore that, it's possible that this node is
248 # a shell node that is down.
249 title "ERROR running command on $node: exit code $ECODE"
250 if [[ "$DEBUG" == "0" ]]; then
251 title "Command output follows:"
255 if [[ "$ECODE" == "255" ]]; then
256 title "Connection timed out"
260 eval "$return_var=$ECODE"
263 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
264 title "Updating API server"
266 update_node $IDENTIFIER.arvadosapi.com ECODE
267 SUM_ECODE=$(($SUM_ECODE + $ECODE))
269 if [[ "$SUM_ECODE" != "0" ]]; then
270 title "ERROR: Updating API server FAILED"
271 EXITCODE=$(($EXITCODE + $SUM_ECODE))
276 if [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
281 title "Loading ARVADOS_API_HOST and ARVADOS_API_TOKEN"
282 if [[ -f "$HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf" ]]; then
283 . $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf
285 title "WARNING: $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf not found."
287 if [[ "$ARVADOS_API_HOST" == "" ]] || [[ "$ARVADOS_API_TOKEN" == "" ]]; then
288 title "ERROR: ARVADOS_API_HOST and/or ARVADOS_API_TOKEN environment variables are not set."
292 title "Gathering list of nodes"
293 if [[ "$IDENTIFIER" == "ce8i5" ]]; then
294 start_nodes="keep keep0"
295 SHELL_NODE_FOR_ARV_KEEPDOCKER=""
297 SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv virtual_machine list |jq .items[].hostname -r`
298 KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv keep_service list |jq .items[].service_host -r`
299 SHELL_NODE_FOR_ARV_KEEPDOCKER="shell.$IDENTIFIER"
300 start_nodes="workbench manage switchyard $SHELL_NODES $KEEP_NODES"
304 for n in $start_nodes; do
306 if [[ $n =~ $ARVADOS_API_HOST$ ]]; then
307 # e.g. keep.qr1hi.arvadosapi.com
311 node=$n.$ARVADOS_API_HOST
313 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$node" ]]; then
315 nodes="$nodes ${node%.arvadosapi.com}"
319 if [[ "$nodes" != "" ]]; then
320 ## at this point nodes should be an array containing
321 ## manage.qr1hi, keep.qr1hi, etc
322 ## that should be defined in the .ssh/config file
323 title "Updating in parallel: $nodes"
324 export -f update_node
332 echo $nodes|xargs -d " " -n 1 -P $PUPPET_CONCURRENCY -I {} bash -c "update_node {}"
335 if [[ "$NODE" == "" ]]; then
336 title "Locating Arvados Standard Docker images project"
338 JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
339 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
341 if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
342 title "Warning: Arvados Standard Docker Images project not found. Creating it."
344 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\"}"`
345 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\" }"
346 if [[ "$?" != "0" ]]; then
347 title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
352 title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
354 VERSION=`ssh -o "StrictHostKeyChecking no" $IDENTIFIER apt-cache policy python-arvados-cwl-runner|grep Candidate`
355 VERSION=`echo $VERSION|cut -f2 -d' '|cut -f1 -d-`
357 if [[ "$?" != "0" ]] || [[ "$VERSION" == "" ]]; then
358 title "ERROR: unable to get arvados/jobs Docker image version"
361 title "Found version for arvados/jobs Docker image: $VERSION"
364 if [[ "$SHELL_NODE_FOR_ARV_KEEPDOCKER" == "" ]]; then
365 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker |grep -q $VERSION
366 if [[ "$?" == "0" ]]; then
367 title "Found latest arvados/jobs Docker image, nothing to upload"
368 # Just in case it isn't yet, tag the image as latest
369 title "Tag arvados/jobs Docker image $VERSION as latest"
370 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs latest
371 if [[ $? -ne 0 ]]; then
372 title "'arv-keepdocker' failed..."
376 title "Installing latest arvados/jobs Docker image"
377 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --pull --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs $VERSION
378 if [[ $? -ne 0 ]]; then
379 title "'arv-keepdocker' failed..."
382 ## adding latest tag too refs 9254
383 docker tag arvados/jobs:$VERSION arvados/jobs:latest
384 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs latest
385 if [[ $? -ne 0 ]]; then
386 title "'arv-keepdocker' failed..."
391 run_command $SHELL_NODE_FOR_ARV_KEEPDOCKER ECODE "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker" |grep -q $VERSION
393 if [[ "$?" == "0" ]]; then
394 title "Found latest arvados/jobs Docker image, nothing to upload"
395 # Just in case it isn't yet, tag the image as latest
396 title "Tag arvados/jobs Docker image $VERSION as latest"
397 ssh -o "StrictHostKeyChecking no" $SHELL_NODE_FOR_ARV_KEEPDOCKER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs latest"
398 if [[ $? -ne 0 ]]; then
399 title "'arv-keepdocker' failed..."
403 title "Installing latest arvados/jobs Docker image"
404 ssh -o "StrictHostKeyChecking no" $SHELL_NODE_FOR_ARV_KEEPDOCKER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --pull --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs $VERSION"
405 if [[ $? -ne 0 ]]; then
406 title "'arv-keepdocker' failed..."
409 ## adding latest tag too refs 9254
410 ssh -o "StrictHostKeyChecking no" $SHELL_NODE_FOR_ARV_KEEPDOCKER docker tag arvados/jobs:$VERSION arvados/jobs:latest
411 ssh -o "StrictHostKeyChecking no" $SHELL_NODE_FOR_ARV_KEEPDOCKER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs latest"
412 if [[ $? -ne 0 ]]; then
413 title "'arv-keepdocker' failed..."