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
99 if [[ "$IDENTIFIER" == '' ]]; then
109 if [[ -e "/usr/local/rvm/scripts/rvm" ]]; then
110 source /usr/local/rvm/scripts/rvm
114 let endtime="$(now) + 600"
115 while [ "$endtime" -gt "$(now)" ]; do
116 puppet agent --test --detailed-exitcodes
118 if [ 0 = "$agent_exitcode" ] || [ 2 = "$agent_exitcode" ]; then
124 exit ${agent_exitcode:-99}
129 let endtime="$(now) + 600"
130 while [ "$endtime" -gt "$(now)" ]; do
134 if [ 0 = "$apt_exitcode" ]; then
140 exit ${apt_exitcode:-99}
144 date=`date +'%Y-%m-%d %H:%M:%S'`
148 function update_node() {
149 if [[ $UNMANAGED -ne 0 ]]; then
159 title "Running apt on $node"
160 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
162 if [[ "$DEBUG" != "0" ]]; then
163 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$APT_AGENT'" 2>&1 | sed 's/^/['"${node}"'] /' | tee $TMP_FILE
165 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$APT_AGENT'" 2>&1 | sed 's/^/['"${node}"'] /' > $TMP_FILE 2>&1
168 ECODE=${PIPESTATUS[0]}
169 RESULT=$(cat $TMP_FILE)
171 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
172 # Ssh exits 255 if the connection timed out. Just ignore that.
173 echo "ERROR running apt on $node: exit code $ECODE"
174 if [[ "$DEBUG" == "0" ]]; then
175 title "Command output follows:"
179 if [[ "$ECODE" == "255" ]]; then
180 title "Connection timed out"
184 if [[ "$ECODE" == "0" ]]; then
186 echo $node successfully updated
188 echo $node exit code: $ECODE see $TMP_FILE for details
192 function run_puppet() {
195 title "Running puppet on $node"
196 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
198 if [[ "$DEBUG" != "0" ]]; then
199 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" 2>&1 | sed 's/^/['"${node}"'] /' | tee $TMP_FILE
201 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" 2>&1 | sed 's/^/['"${node}"'] /' > $TMP_FILE 2>&1
204 ECODE=${PIPESTATUS[0]}
205 RESULT=$(cat $TMP_FILE)
207 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
208 # Ssh exits 255 if the connection timed out. Just ignore that.
209 # Puppet exits 2 if there are changes. For real!
210 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
211 # was already running
212 echo "ERROR running puppet on $node: exit code $ECODE"
213 if [[ "$DEBUG" == "0" ]]; then
214 title "Command output follows:"
218 if [[ "$ECODE" == "255" ]]; then
219 title "Connection timed out"
222 if [[ "$ECODE" == "2" ]]; then
226 if [[ "$ECODE" == "0" ]]; then
228 echo $node successfully updated
230 echo $node exit code: $ECODE see $TMP_FILE for details
234 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
235 title "Updating API server"
237 update_node $IDENTIFIER.arvadosapi.com ECODE
238 SUM_ECODE=$(($SUM_ECODE + $ECODE))
240 if [[ "$SUM_ECODE" != "0" ]]; then
241 title "ERROR: Updating API server FAILED"
242 EXITCODE=$(($EXITCODE + $SUM_ECODE))
247 if [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
252 title "Loading ARVADOS_API_HOST and ARVADOS_API_TOKEN"
253 if [[ -f "$HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf" ]]; then
254 . $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf
256 title "WARNING: $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf not found."
258 if [[ "$ARVADOS_API_HOST" == "" ]] || [[ "$ARVADOS_API_TOKEN" == "" ]]; then
259 title "ERROR: ARVADOS_API_HOST and/or ARVADOS_API_TOKEN environment variables are not set."
263 title "Gathering list of nodes"
264 start_nodes="workbench"
265 if [[ "$IDENTIFIER" != "ce8i5" ]]; then
266 start_nodes="$start_nodes manage switchyard"
268 SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv virtual_machine list |jq .items[].hostname -r`
269 KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv keep_service list |jq .items[].service_host -r`
270 SHELL_NODE_FOR_ARV_KEEPDOCKER="shell.$IDENTIFIER"
271 start_nodes="$start_nodes $SHELL_NODES $KEEP_NODES $ARVADOS_API_HOST"
274 for n in $start_nodes; do
276 if [[ $n =~ $ARVADOS_API_HOST$ ]]; then
277 # e.g. keep.qr1hi.arvadosapi.com
281 node=$n.$ARVADOS_API_HOST
283 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$node" ]]; then
285 nodes="$nodes ${node%.arvadosapi.com}"
289 if [[ "$nodes" != "" ]]; then
290 ## at this point nodes should be an array containing
291 ## manage.qr1hi, keep.qr1hi, etc
292 ## that should be defined in the .ssh/config file
293 title "Updating in parallel: $nodes"
294 export -f update_node
302 echo $nodes|xargs -d " " -n 1 -P $PUPPET_CONCURRENCY -I {} bash -c "update_node {}"
305 if [[ "$NODE" == "" ]]; then
306 title "Locating Arvados Standard Docker images project"
308 JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
309 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
311 if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
312 title "Warning: Arvados Standard Docker Images project not found. Creating it."
314 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\"}"`
315 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\" }"
316 if [[ "$?" != "0" ]]; then
317 title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
322 title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
324 VERSION=`ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" $IDENTIFIER apt-cache policy python3-arvados-cwl-runner|grep Candidate`
325 VERSION=`echo $VERSION|cut -f2 -d' '|cut -f1 -d-`
327 if [[ "$?" != "0" ]] || [[ "$VERSION" == "" ]]; then
328 title "ERROR: unable to get arvados/jobs Docker image version"
331 title "Found version for arvados/jobs Docker image: $VERSION"
334 if [[ "$SHELL_NODE_FOR_ARV_KEEPDOCKER" == "" ]]; then
335 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker |grep -qP "arvados/jobs +$VERSION "
336 if [[ $? -eq 0 ]]; then
337 title "Found latest arvados/jobs Docker image, nothing to upload"
338 # Just in case it isn't yet, tag the image as latest
339 title "Tag arvados/jobs Docker image $VERSION as latest"
340 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs latest
341 if [[ $? -ne 0 ]]; then
342 title "'arv-keepdocker' failed..."
346 title "Installing latest arvados/jobs Docker image"
347 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --pull --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs $VERSION
348 if [[ $? -ne 0 ]]; then
349 title "'arv-keepdocker' failed..."
352 ## adding latest tag too refs 9254
353 docker tag arvados/jobs:$VERSION arvados/jobs:latest
354 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs latest
355 if [[ $? -ne 0 ]]; then
356 title "'arv-keepdocker' failed..."
361 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" $SHELL_NODE_FOR_ARV_KEEPDOCKER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker" |grep -qP "arvados/jobs +$VERSION "
363 if [[ $? -eq 0 ]]; then
364 title "Found latest arvados/jobs Docker image, nothing to upload"
365 # Just in case it isn't yet, tag the image as latest
366 title "Tag arvados/jobs Docker image $VERSION as latest"
367 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" $SHELL_NODE_FOR_ARV_KEEPDOCKER docker tag arvados/jobs:$VERSION arvados/jobs:latest
368 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" $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"
369 if [[ $? -ne 0 ]]; then
370 title "'arv-keepdocker' failed..."
374 title "Installing latest arvados/jobs Docker image"
375 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" $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"
376 if [[ $? -ne 0 ]]; then
377 title "'arv-keepdocker' failed..."
380 ## adding latest tag too refs 9254
381 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" $SHELL_NODE_FOR_ARV_KEEPDOCKER docker tag arvados/jobs:$VERSION arvados/jobs:latest
382 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" $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"
383 if [[ $? -ne 0 ]]; then
384 title "'arv-keepdocker' failed..."