6 read -d] -r SCOPES <<EOF
8 '["GET /arvados/v1/virtual_machines",\n
9 "GET /arvados/v1/keep_services",\n
10 "GET /arvados/v1/keep_services/",\n
11 "GET /arvados/v1/groups",\n
12 "GET /arvados/v1/groups/",\n
13 "GET /arvados/v1/links",\n
14 "GET /arvados/v1/collections",\n
15 "POST /arvados/v1/collections",\n
16 "POST /arvados/v1/links",\n
17 "GET /arvados/v1/users/current",\n
18 "POST /arvados/v1/users/current",\n
19 "GET /arvados/v1/jobs",\n
20 "POST /arvados/v1/jobs",\n
21 "GET /arvados/v1/pipeline_instances",\n
22 "POST /arvados/v1/pipeline_instances",\n
23 "PUT /arvados/v1/pipeline_instances/",\n
24 "GET /arvados/v1/collections/",\n
25 "POST /arvados/v1/collections/",\n
26 "GET /arvados/v1/logs"]'
31 echo >&2 "usage: $0 [options] <identifier>"
33 echo >&2 " <identifier> Arvados cluster name"
35 echo >&2 "$0 options:"
36 echo >&2 " -p, --port <ssh port> SSH port to use (default 22)"
37 echo >&2 " -d, --debug Enable debug output"
38 echo >&2 " -h, --help Display this help and exit"
40 echo >&2 "Note: this script requires an arvados token created with these permissions:"
41 echo >&2 ' arv api_client_authorization create_system_auth \'
42 echo -e $SCOPES"]'" >&2
47 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
48 TEMP=`getopt -o hdp: \
49 --long help,debug,port: \
52 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
53 # Note the quotes around `$TEMP': they are essential!
60 SSH_PORT="$2"; shift 2
79 if [[ "$IDENTIFIER" == '' ]]; then
90 let endtime="$(now) + 600"
91 while [ "$endtime" -gt "$(now)" ]; do
92 puppet agent --test --detailed-exitcodes
94 if [ 0 = "$agent_exitcode" ] || [ 2 = "$agent_exitcode" ]; then
100 exit ${agent_exitcode:-99}
104 date=`date +'%Y-%m-%d %H:%M:%S'`
108 function run_puppet() {
111 title "Running puppet on $node"
112 sleep $[ $RANDOM / 6000 ].$[ $RANDOM / 1000 ]
114 if [[ "$DEBUG" != "0" ]]; then
115 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" | tee $TMP_FILE
117 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" > $TMP_FILE 2>&1
120 ECODE=${PIPESTATUS[0]}
121 RESULT=$(cat $TMP_FILE)
123 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
124 # Ssh exits 255 if the connection timed out. Just ignore that.
125 # Puppet exits 2 if there are changes. For real!
126 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
127 # was already running
128 echo "ERROR running puppet on $node: exit code $ECODE"
129 if [[ "$DEBUG" == "0" ]]; then
130 title "Command output follows:"
134 if [[ "$ECODE" == "255" ]]; then
135 title "Connection timed out"
138 if [[ "$ECODE" == "2" ]]; then
142 if [[ "$ECODE" == "0" ]]; then
144 echo $node successfully updates
146 echo $node exit code: $ECODE see $TMP_FILE for details
150 function run_command() {
155 title "Running '$command' on $node"
157 if [[ "$DEBUG" != "0" ]]; then
158 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" | tee $TMP_FILE
160 ssh -t -p$SSH_PORT -o "StrictHostKeyChecking no" -o "ConnectTimeout 125" root@$node -C "$command" > $TMP_FILE 2>&1
164 RESULT=$(cat $TMP_FILE)
166 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
167 # Ssh exists 255 if the connection timed out. Just ignore that, it's possible that this node is
168 # a shell node that is down.
169 title "ERROR running command 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 eval "$return_var=$ECODE"
183 title "Updating API server"
185 run_puppet $IDENTIFIER.arvadosapi.com ECODE
186 SUM_ECODE=$(($SUM_ECODE + $ECODE))
187 if [ ! "$IDENTIFIER" = "c97qk" ]
189 run_command $IDENTIFIER.arvadosapi.com ECODE "dpkg -L arvados-mailchimp-plugin 2>/dev/null && apt-get install arvados-mailchimp-plugin --reinstall || echo"
190 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 "Locating Arvados Standard Docker images project"
212 JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
213 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
215 if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
216 title "Warning: Arvados Standard Docker Images project not found. Creating it."
218 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\"}"`
219 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\" }"
220 if [[ "$?" != "0" ]]; then
221 title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
226 title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
227 GIT_COMMIT=`ssh -o "StrictHostKeyChecking no" $IDENTIFIER cat /usr/local/arvados/src/git-commit.version`
229 if [[ "$?" != "0" ]] || [[ "$GIT_COMMIT" == "" ]]; then
230 title "ERROR: unable to get arvados/jobs Docker image git revision"
233 title "Found git commit for arvados/jobs Docker image: $GIT_COMMIT"
236 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
238 if [[ "$?" == "0" ]]; then
239 title "Found latest arvados/jobs Docker image, nothing to upload"
240 # Just in case it isn't yet, tag the image as latest
241 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker arvados/jobs latest"
243 title "Installing latest arvados/jobs Docker image"
244 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"
245 ## adding latest tag too refs 9254
246 ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER docker tag -f arvados/jobs:$GIT_COMMIT arvados/jobs:latest
247 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"
248 if [[ "$?" -ne 0 ]]; then
249 title "'git pull' failed exiting..."
254 title "Gathering list of shell and Keep nodes"
255 SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv virtual_machine list |jq .items[].hostname -r`
256 KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv keep_service list |jq .items[].service_host -r`
259 for n in workbench manage switchyard $SHELL_NODES $KEEP_NODES; do
261 if [[ $n =~ $ARVADOS_API_HOST$ ]]; then
262 # e.g. keep.qr1hi.arvadosapi.com
266 node=$n.$ARVADOS_API_HOST
269 nodes="$nodes ${node%.arvadosapi.com}"
272 ## at this point nodes should be an array containing
273 ## manage.qr1hi, keep.qr1hi, etc
274 ## that should be defined in the .ssh/config file
275 title "Updating in parallel: $nodes"
280 echo $nodes|xargs -d " " -n 1 -P 10 -I {} bash -c "run_puppet {}"