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
104 let endtime="$(now) + 600"
105 while [ "$endtime" -gt "$(now)" ]; do
106 puppet agent --test --detailed-exitcodes
108 if [ 0 = "$agent_exitcode" ] || [ 2 = "$agent_exitcode" ]; then
114 exit ${agent_exitcode:-99}
118 date=`date +'%Y-%m-%d %H:%M:%S'`
122 function run_puppet() {
125 title "Running puppet on $node"
126 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
128 if [[ "$DEBUG" != "0" ]]; then
129 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" | tee $TMP_FILE
131 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" > $TMP_FILE 2>&1
134 ECODE=${PIPESTATUS[0]}
135 RESULT=$(cat $TMP_FILE)
137 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
138 # Ssh exits 255 if the connection timed out. Just ignore that.
139 # Puppet exits 2 if there are changes. For real!
140 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
141 # was already running
142 echo "ERROR running puppet on $node: exit code $ECODE"
143 if [[ "$DEBUG" == "0" ]]; then
144 title "Command output follows:"
148 if [[ "$ECODE" == "255" ]]; then
149 title "Connection timed out"
152 if [[ "$ECODE" == "2" ]]; then
156 if [[ "$ECODE" == "0" ]]; then
158 echo $node successfully updates
160 echo $node exit code: $ECODE see $TMP_FILE for details
164 function run_command() {
169 title "Running '$command' on $node"
171 if [[ "$DEBUG" != "0" ]]; then
172 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" | tee $TMP_FILE
174 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" > $TMP_FILE 2>&1
178 RESULT=$(cat $TMP_FILE)
180 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
181 # Ssh exists 255 if the connection timed out. Just ignore that, it's possible that this node is
182 # a shell node that is down.
183 title "ERROR running command on $node: exit code $ECODE"
184 if [[ "$DEBUG" == "0" ]]; then
185 title "Command output follows:"
189 if [[ "$ECODE" == "255" ]]; then
190 title "Connection timed out"
194 eval "$return_var=$ECODE"
197 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
198 title "Updating API server"
200 run_puppet $IDENTIFIER.arvadosapi.com ECODE
201 SUM_ECODE=$(($SUM_ECODE + $ECODE))
203 if [[ "$SUM_ECODE" != "0" ]]; then
204 title "ERROR: Updating API server FAILED"
205 EXITCODE=$(($EXITCODE + $SUM_ECODE))
210 if [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
215 title "Loading ARVADOS_API_HOST and ARVADOS_API_TOKEN"
216 if [[ -f "$HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf" ]]; then
217 . $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf
219 title "WARNING: $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf not found."
221 if [[ "$ARVADOS_API_HOST" == "" ]] || [[ "$ARVADOS_API_TOKEN" == "" ]]; then
222 title "ERROR: ARVADOS_API_HOST and/or ARVADOS_API_TOKEN environment variables are not set."
226 title "Gathering list of shell and Keep nodes"
227 SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv virtual_machine list |jq .items[].hostname -r`
228 KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv keep_service list |jq .items[].service_host -r`
231 for n in workbench manage switchyard $SHELL_NODES $KEEP_NODES; do
233 if [[ $n =~ $ARVADOS_API_HOST$ ]]; then
234 # e.g. keep.qr1hi.arvadosapi.com
238 node=$n.$ARVADOS_API_HOST
240 if [[ "$NODE" == "" ]] || [[ "$NODE" == "$node" ]]; then
242 nodes="$nodes ${node%.arvadosapi.com}"
246 if [[ "$nodes" != "" ]]; then
247 ## at this point nodes should be an array containing
248 ## manage.qr1hi, keep.qr1hi, etc
249 ## that should be defined in the .ssh/config file
250 title "Updating in parallel: $nodes"
255 echo $nodes|xargs -d " " -n 1 -P $PUPPET_CONCURRENCY -I {} bash -c "run_puppet {}"
258 if [[ "$NODE" == "" ]]; then
259 title "Locating Arvados Standard Docker images project"
261 JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
262 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
264 if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
265 title "Warning: Arvados Standard Docker Images project not found. Creating it."
267 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\"}"`
268 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\" }"
269 if [[ "$?" != "0" ]]; then
270 title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
275 title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
277 # from 1.4 onwards, we use the python executable that is part of the python-arvados-cwl-runner package
278 GIT_COMMIT=`ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "bash -s" <<EOF
279 if [[ -e "/usr/share/python2.7/dist/python-arvados-cwl-runner/bin/python" ]]; then
280 /usr/share/python2.7/dist/python-arvados-cwl-runner/bin/python -c 'import arvados_cwl ; print arvados_cwl.__version__'
282 /usr/bin/python -c 'import arvados_cwl ; print arvados_cwl.__version__'
287 if [[ "$?" != "0" ]] || [[ "$GIT_COMMIT" == "" ]]; then
288 title "ERROR: unable to get arvados/jobs Docker image git revision"
291 title "Found git commit for arvados/jobs Docker image: $GIT_COMMIT"
294 run_command shell.$IDENTIFIER ECODE "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker" |grep -q $GIT_COMMIT
296 if [[ "$?" == "0" ]]; then
297 title "Found latest arvados/jobs Docker image, nothing to upload"
298 # Just in case it isn't yet, tag the image as latest
299 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker arvados/jobs latest"
301 title "Installing latest arvados/jobs Docker image"
302 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --pull --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs $GIT_COMMIT"
303 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER docker tag --force >/dev/null 2>&1
304 # docker 1.13 no longer supports --force. Sigh.
305 if [[ "$?" == "125" ]]; then
310 ## adding latest tag too refs 9254
311 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER docker tag $FORCE_TAG arvados/jobs:$GIT_COMMIT arvados/jobs:latest
312 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"
313 if [[ "$?" -ne 0 ]]; then
314 title "'git pull' failed exiting..."