3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: AGPL-3.0
14 read -d] -r SCOPES <<EOF
16 '["GET /arvados/v1/virtual_machines",\n
17 "GET /arvados/v1/keep_services",\n
18 "GET /arvados/v1/keep_services/",\n
19 "GET /arvados/v1/groups",\n
20 "GET /arvados/v1/groups/",\n
21 "GET /arvados/v1/links",\n
22 "GET /arvados/v1/collections",\n
23 "POST /arvados/v1/collections",\n
24 "POST /arvados/v1/links",\n
25 "GET /arvados/v1/users/current",\n
26 "POST /arvados/v1/users/current",\n
27 "GET /arvados/v1/jobs",\n
28 "POST /arvados/v1/jobs",\n
29 "GET /arvados/v1/pipeline_instances",\n
30 "POST /arvados/v1/pipeline_instances",\n
31 "PUT /arvados/v1/pipeline_instances/",\n
32 "GET /arvados/v1/collections/",\n
33 "POST /arvados/v1/collections/",\n
34 "GET /arvados/v1/logs"]'
39 echo >&2 "usage: $0 [options] <identifier>"
41 echo >&2 " <identifier> Arvados cluster name"
43 echo >&2 "$0 options:"
44 echo >&2 " -n, --node <node> Single machine to deploy, use fqdn, optional"
45 echo >&2 " -p, --port <ssh port> SSH port to use (default 22)"
46 echo >&2 " -c, --concurrency <max> Maximum concurrency for puppet runs (default 5)"
47 echo >&2 " -u, --unmanaged Deploy to unmanaged node/cluster"
48 echo >&2 " -d, --debug Enable debug output"
49 echo >&2 " -h, --help Display this help and exit"
51 echo >&2 "Note: this script requires an arvados token created with these permissions:"
52 echo >&2 ' arv api_client_authorization create_system_auth \'
53 echo -e $SCOPES"]'" >&2
58 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
59 TEMP=`getopt -o hudp:c:n: \
60 --long help,unmanaged,debug,port:,concurrency:,node: \
63 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
64 # Note the quotes around `$TEMP': they are essential!
74 SSH_PORT="$2"; shift 2
77 PUPPET_CONCURRENCY="$2"; shift 2
101 if [[ "$IDENTIFIER" == '' ]]; then
111 if [[ -e "/usr/local/rvm/scripts/rvm" ]]; then
112 source /usr/local/rvm/scripts/rvm
116 let endtime="$(now) + 600"
117 while [ "$endtime" -gt "$(now)" ]; do
118 puppet agent --test --detailed-exitcodes
120 if [ 0 = "$agent_exitcode" ] || [ 2 = "$agent_exitcode" ]; then
126 exit ${agent_exitcode:-99}
131 let endtime="$(now) + 600"
132 while [ "$endtime" -gt "$(now)" ]; do
134 DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
136 if [ 0 = "$apt_exitcode" ]; then
142 exit ${apt_exitcode:-99}
146 date=`date +'%Y-%m-%d %H:%M:%S'`
150 function update_node() {
151 if [[ $UNMANAGED -ne 0 ]]; then
161 title "Running apt on $node"
162 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
164 if [[ "$DEBUG" != "0" ]]; then
165 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
167 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
170 ECODE=${PIPESTATUS[0]}
171 RESULT=$(cat $TMP_FILE)
173 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
174 # Ssh exits 255 if the connection timed out. Just ignore that.
175 echo "ERROR running apt on $node: exit code $ECODE"
176 if [[ "$DEBUG" == "0" ]]; then
177 title "Command output follows:"
181 if [[ "$ECODE" == "255" ]]; then
182 title "Connection timed out"
186 if [[ "$ECODE" == "0" ]]; then
188 title "$node successfully updated"
190 title "$node exit code: $ECODE see $TMP_FILE for details"
194 function run_puppet() {
197 title "Running puppet on $node"
198 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
200 if [[ "$DEBUG" != "0" ]]; then
201 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
203 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
206 ECODE=${PIPESTATUS[0]}
207 RESULT=$(cat $TMP_FILE)
209 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
210 # Ssh exits 255 if the connection timed out. Just ignore that.
211 # Puppet exits 2 if there are changes. For real!
212 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
213 # was already running
214 echo "ERROR running puppet on $node: exit code $ECODE"
215 if [[ "$DEBUG" == "0" ]]; then
216 title "Command output follows:"
220 if [[ "$ECODE" == "255" ]]; then
221 title "Connection timed out"
224 if [[ "$ECODE" == "2" ]]; then
228 if [[ "$ECODE" == "0" ]]; then
230 echo $node successfully updated
232 echo $node exit code: $ECODE see $TMP_FILE for details
236 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
237 title "Updating API server"
239 update_node $IDENTIFIER.arvadosapi.com ECODE
240 SUM_ECODE=$(($SUM_ECODE + $ECODE))
242 if [[ "$SUM_ECODE" != "0" ]]; then
243 title "ERROR: Updating API server FAILED"
244 EXITCODE=$(($EXITCODE + $SUM_ECODE))
249 if [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
254 title "Loading ARVADOS_API_HOST and ARVADOS_API_TOKEN"
255 if [[ -f "$HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf" ]]; then
256 . $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf
258 title "WARNING: $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf not found."
260 if [[ "$ARVADOS_API_HOST" == "" ]] || [[ "$ARVADOS_API_TOKEN" == "" ]]; then
261 title "ERROR: ARVADOS_API_HOST and/or ARVADOS_API_TOKEN environment variables are not set."
265 title "Gathering list of nodes"
266 start_nodes="workbench"
267 if [[ "$IDENTIFIER" != "ce8i5" ]] && [[ "$IDENTIFIER" != "tordo" ]]; then
268 start_nodes="$start_nodes manage switchyard"
270 SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv virtual_machine list |jq .items[].hostname -r`
271 KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv keep_service list |jq .items[].service_host -r`
272 SHELL_NODE_FOR_ARV_KEEPDOCKER="shell.$IDENTIFIER"
273 start_nodes="$start_nodes $SHELL_NODES $KEEP_NODES"
276 for n in $start_nodes; do
278 if [[ $n =~ $ARVADOS_API_HOST$ ]]; then
279 # e.g. keep.qr1hi.arvadosapi.com
283 node=$n.$ARVADOS_API_HOST
285 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$node" ]]; then
287 nodes="$nodes ${node%.arvadosapi.com}"
291 if [[ "$nodes" != "" ]]; then
292 ## at this point nodes should be an array containing
293 ## manage.qr1hi, keep.qr1hi, etc
294 ## that should be defined in the .ssh/config file
295 title "Updating in parallel:$nodes"
296 export -f update_node
304 echo $nodes|xargs -d " " -n 1 -P $PUPPET_CONCURRENCY -I {} bash -c "update_node {}"
307 if [[ "$NODE" == "" ]]; then
308 title "Locating Arvados Standard Docker images project"
310 JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
311 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
313 if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
314 title "Warning: Arvados Standard Docker Images project not found. Creating it."
316 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\"}"`
317 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\" }"
318 if [[ "$?" != "0" ]]; then
319 title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
324 title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
326 if [[ "$SHELL_NODE_FOR_ARV_KEEPDOCKER" == "" ]]; then
327 VERSION=`ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" -o "LogLevel QUIET" $IDENTIFIER apt-cache policy python3-arvados-cwl-runner|grep Candidate`
328 VERSION=`echo $VERSION|cut -f2 -d' '|cut -f1 -d-`
330 if [[ "$?" != "0" ]] || [[ "$VERSION" == "" ]]; then
331 title "ERROR: unable to get python3-arvados-cwl-runner version"
334 title "Found version for python3-arvados-cwl-runner: $VERSION"
338 CLEAN_VERSION=`echo $VERSION | sed s/~dev/.dev/g | sed s/~rc/rc/g`
339 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker |grep -qP "arvados/jobs +$CLEAN_VERSION "
340 if [[ $? -eq 0 ]]; then
342 title "Found arvados/jobs Docker image version $CLEAN_VERSION, nothing to upload"
345 title "Installing arvados/jobs Docker image version $CLEAN_VERSION"
346 ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --pull --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs $CLEAN_VERSION
347 if [[ $? -ne 0 ]]; then
348 title "'arv-keepdocker' failed..."
353 VERSION=`ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" -o "LogLevel QUIET" $SHELL_NODE_FOR_ARV_KEEPDOCKER apt-cache policy python3-arvados-cwl-runner|grep Candidate`
354 VERSION=`echo $VERSION|cut -f2 -d' '|cut -f1 -d-`
356 if [[ "$?" != "0" ]] || [[ "$VERSION" == "" ]]; then
357 title "ERROR: unable to get python3-arvados-cwl-runner version"
360 title "Found version for python3-arvados-cwl-runner: $VERSION"
364 CLEAN_VERSION=`echo $VERSION | sed s/~dev/.dev/g | sed s/~rc/rc/g`
365 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" -o "LogLevel QUIET" $SHELL_NODE_FOR_ARV_KEEPDOCKER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker" |grep -qP "arvados/jobs +$CLEAN_VERSION "
366 if [[ $? -eq 0 ]]; then
368 title "Found arvados/jobs Docker image version $CLEAN_VERSION, nothing to upload"
371 title "Installing arvados/jobs Docker image version $CLEAN_VERSION"
372 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" -o "LogLevel QUIET" $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 $CLEAN_VERSION"
373 if [[ $? -ne 0 ]]; then
374 title "'arv-keepdocker' failed..."