7 read -d] -r SCOPES <<EOF
9 '["GET /arvados/v1/virtual_machines",\n
10 "GET /arvados/v1/keep_services",\n
11 "GET /arvados/v1/keep_services/",\n
12 "GET /arvados/v1/groups",\n
13 "GET /arvados/v1/groups/",\n
14 "GET /arvados/v1/links",\n
15 "GET /arvados/v1/collections",\n
16 "POST /arvados/v1/collections",\n
17 "POST /arvados/v1/links",\n
18 "GET /arvados/v1/users/current",\n
19 "POST /arvados/v1/users/current",\n
20 "GET /arvados/v1/jobs",\n
21 "POST /arvados/v1/jobs",\n
22 "GET /arvados/v1/pipeline_instances",\n
23 "POST /arvados/v1/pipeline_instances",\n
24 "PUT /arvados/v1/pipeline_instances/",\n
25 "GET /arvados/v1/collections/",\n
26 "POST /arvados/v1/collections/",\n
27 "GET /arvados/v1/logs"]'
32 echo >&2 "usage: $0 [options] <identifier>"
34 echo >&2 " <identifier> Arvados cluster name"
36 echo >&2 "$0 options:"
37 echo >&2 " -p, --port <ssh port> SSH port to use (default 22)"
38 echo >&2 " -c, --concurrency <max> Maximum concurrency for puppet runs (default 5)"
39 echo >&2 " -d, --debug Enable debug output"
40 echo >&2 " -h, --help Display this help and exit"
42 echo >&2 "Note: this script requires an arvados token created with these permissions:"
43 echo >&2 ' arv api_client_authorization create_system_auth \'
44 echo -e $SCOPES"]'" >&2
49 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
50 TEMP=`getopt -o hdp:c: \
51 --long help,debug,port:,concurrency: \
54 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
55 # Note the quotes around `$TEMP': they are essential!
62 SSH_PORT="$2"; shift 2
65 PUPPET_CONCURRENCY="$2"; shift 2
84 if [[ "$IDENTIFIER" == '' ]]; then
95 let endtime="$(now) + 600"
96 while [ "$endtime" -gt "$(now)" ]; do
97 puppet agent --test --detailed-exitcodes
99 if [ 0 = "$agent_exitcode" ] || [ 2 = "$agent_exitcode" ]; then
105 exit ${agent_exitcode:-99}
109 date=`date +'%Y-%m-%d %H:%M:%S'`
113 function run_puppet() {
116 title "Running puppet on $node"
117 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
119 if [[ "$DEBUG" != "0" ]]; then
120 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" | tee $TMP_FILE
122 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" > $TMP_FILE 2>&1
125 ECODE=${PIPESTATUS[0]}
126 RESULT=$(cat $TMP_FILE)
128 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
129 # Ssh exits 255 if the connection timed out. Just ignore that.
130 # Puppet exits 2 if there are changes. For real!
131 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
132 # was already running
133 echo "ERROR running puppet on $node: exit code $ECODE"
134 if [[ "$DEBUG" == "0" ]]; then
135 title "Command output follows:"
139 if [[ "$ECODE" == "255" ]]; then
140 title "Connection timed out"
143 if [[ "$ECODE" == "2" ]]; then
147 if [[ "$ECODE" == "0" ]]; then
149 echo $node successfully updates
151 echo $node exit code: $ECODE see $TMP_FILE for details
155 function run_command() {
160 title "Running '$command' on $node"
162 if [[ "$DEBUG" != "0" ]]; then
163 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" | tee $TMP_FILE
165 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" > $TMP_FILE 2>&1
169 RESULT=$(cat $TMP_FILE)
171 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
172 # Ssh exists 255 if the connection timed out. Just ignore that, it's possible that this node is
173 # a shell node that is down.
174 title "ERROR running command on $node: exit code $ECODE"
175 if [[ "$DEBUG" == "0" ]]; then
176 title "Command output follows:"
180 if [[ "$ECODE" == "255" ]]; then
181 title "Connection timed out"
185 eval "$return_var=$ECODE"
188 title "Updating API server"
190 run_puppet $IDENTIFIER.arvadosapi.com ECODE
191 SUM_ECODE=$(($SUM_ECODE + $ECODE))
193 if [[ "$SUM_ECODE" != "0" ]]; then
194 title "ERROR: Updating API server FAILED"
195 EXITCODE=$(($EXITCODE + $SUM_ECODE))
199 title "Loading ARVADOS_API_HOST and ARVADOS_API_TOKEN"
200 if [[ -f "$HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf" ]]; then
201 . $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf
203 title "WARNING: $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf not found."
205 if [[ "$ARVADOS_API_HOST" == "" ]] || [[ "$ARVADOS_API_TOKEN" == "" ]]; then
206 title "ERROR: ARVADOS_API_HOST and/or ARVADOS_API_TOKEN environment variables are not set."
210 title "Gathering list of shell and Keep nodes"
211 SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv virtual_machine list |jq .items[].hostname -r`
212 KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv keep_service list |jq .items[].service_host -r`
215 for n in workbench manage switchyard $SHELL_NODES $KEEP_NODES; do
217 if [[ $n =~ $ARVADOS_API_HOST$ ]]; then
218 # e.g. keep.qr1hi.arvadosapi.com
222 node=$n.$ARVADOS_API_HOST
225 nodes="$nodes ${node%.arvadosapi.com}"
228 ## at this point nodes should be an array containing
229 ## manage.qr1hi, keep.qr1hi, etc
230 ## that should be defined in the .ssh/config file
231 title "Updating in parallel: $nodes"
236 echo $nodes|xargs -d " " -n 1 -P $PUPPET_CONCURRENCY -I {} bash -c "run_puppet {}"
238 title "Locating Arvados Standard Docker images project"
240 JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
241 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
243 if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
244 title "Warning: Arvados Standard Docker Images project not found. Creating it."
246 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\"}"`
247 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\" }"
248 if [[ "$?" != "0" ]]; then
249 title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
254 title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
255 GIT_COMMIT=`ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "python -c 'import arvados_cwl ; print arvados_cwl.__version__'"`
257 if [[ "$?" != "0" ]] || [[ "$GIT_COMMIT" == "" ]]; then
258 title "ERROR: unable to get arvados/jobs Docker image git revision"
261 title "Found git commit for arvados/jobs Docker image: $GIT_COMMIT"
264 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
266 if [[ "$?" == "0" ]]; then
267 title "Found latest arvados/jobs Docker image, nothing to upload"
268 # Just in case it isn't yet, tag the image as latest
269 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker arvados/jobs latest"
271 title "Installing latest arvados/jobs Docker image"
272 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"
273 ## adding latest tag too refs 9254
274 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER docker tag --force arvados/jobs:$GIT_COMMIT arvados/jobs:latest
275 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"
276 if [[ "$?" -ne 0 ]]; then
277 title "'git pull' failed exiting..."