7 echo >&2 "usage: $0 [options] <identifier>"
9 echo >&2 " <identifier> Arvados cluster name"
11 echo >&2 "$0 options:"
12 echo >&2 " -d, --debug Enable debug output"
13 echo >&2 " -h, --help Display this help and exit"
15 echo >&2 "Note: this script requires an arvados token created with these permissions:"
16 echo >&2 ' arv api_client_authorization create_system_auth \'
17 echo >&2 ' --scopes "[\"GET /arvados/v1/virtual_machines\",'
18 echo >&2 ' \"GET /arvados/v1/keep_services\",'
19 echo >&2 ' \"GET /arvados/v1/keep_services/\",'
20 echo >&2 ' \"GET /arvados/v1/groups\",'
21 echo >&2 ' \"GET /arvados/v1/groups/\",'
22 echo >&2 ' \"GET /arvados/v1/links\",'
23 echo >&2 ' \"GET /arvados/v1/collections\",'
24 echo >&2 ' \"POST /arvados/v1/collections\",'
25 echo >&2 ' \"POST /arvados/v1/links\"]"'
29 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
34 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
35 # Note the quotes around `$TEMP': they are essential!
58 if [[ "$IDENTIFIER" == '' ]]; then
68 date=`date +'%Y-%m-%d %H:%M:%S'`
72 function run_puppet() {
76 title "Running puppet on $node"
78 if [[ "$DEBUG" != "0" ]]; then
79 ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "/usr/bin/puppet agent -t" | tee $TMP_FILE
81 ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "/usr/bin/puppet agent -t" > $TMP_FILE 2>&1
85 RESULT=$(cat $TMP_FILE)
87 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
88 # Ssh exits 255 if the connection timed out. Just ignore that.
89 # Puppet exits 2 if there are changes. For real!
90 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
92 echo "ERROR running puppet on $node: exit code $ECODE"
93 if [[ "$DEBUG" == "0" ]]; then
94 title "Command output follows:"
98 if [[ "$ECODE" == "255" ]]; then
99 title "Connection timed out"
102 if [[ "$ECODE" == "2" ]]; then
106 eval "$return_var=$ECODE"
109 function run_command() {
114 title "Running '$command' on $node"
116 if [[ "$DEBUG" != "0" ]]; then
117 ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "$command" | tee $TMP_FILE
119 ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "$command" > $TMP_FILE 2>&1
123 RESULT=$(cat $TMP_FILE)
125 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
126 # Ssh exists 255 if the connection timed out. Just ignore that, it's possible that this node is
127 # a shell node that is down.
128 title "ERROR running command 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"
139 eval "$return_var=$ECODE"
142 title "Updating API server"
144 run_puppet $IDENTIFIER.arvadosapi.com ECODE
145 SUM_ECODE=$(($SUM_ECODE + $ECODE))
146 run_command $IDENTIFIER.arvadosapi.com ECODE "/usr/local/bin/arvados-api-server-upgrade.sh"
147 SUM_ECODE=$(($SUM_ECODE + $ECODE))
148 run_command $IDENTIFIER.arvadosapi.com ECODE "dpkg -L arvados-mailchimp-plugin 2>/dev/null && apt-get install arvados-mailchimp-plugin --reinstall || echo"
149 SUM_ECODE=$(($SUM_ECODE + $ECODE))
151 if [[ "$SUM_ECODE" != "0" ]]; then
152 title "ERROR: Updating API server FAILED"
153 EXITCODE=$(($EXITCODE + $SUM_ECODE))
157 title "Loading ARVADOS_API_HOST and ARVADOS_API_TOKEN"
158 if [[ -f "$HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf" ]]; then
159 . $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf
161 title "WARNING: $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf not found."
163 if [[ "$ARVADOS_API_HOST" == "" ]] || [[ "$ARVADOS_API_TOKEN" == "" ]]; then
164 title "ERROR: ARVADOS_API_HOST and/or ARVADOS_API_TOKEN environment variables are not set."
168 title "Locating Arvados Standard Docker images project"
170 JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
171 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
173 if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
174 title "Warning: Arvados Standard Docker Images project not found. Creating it."
176 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\"}"`
177 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\" }"
178 if [[ "$?" != "0" ]]; then
179 title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
184 title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
185 GIT_COMMIT=`ssh -o "StrictHostKeyChecking no" $IDENTIFIER cat /usr/local/arvados/src/git-commit.version`
187 if [[ "$?" != "0" ]] || [[ "$GIT_COMMIT" == "" ]]; then
188 title "ERROR: unable to get arvados/jobs Docker image git revision"
191 title "Found git commit for arvados/jobs Docker image: $GIT_COMMIT"
194 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
196 if [[ "$?" == "0" ]]; then
197 title "Found latest arvados/jobs Docker image, nothing to upload"
199 title "Installing latest arvados/jobs Docker image"
200 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"
201 if [[ "$?" -ne 0 ]]; then
202 title "'git pull' failed exiting..."
207 title "Gathering list of shell and Keep nodes"
208 SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv virtual_machine list |jq .items[].hostname -r`
209 KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv keep_service list |jq .items[].service_host -r`
211 title "Updating workbench"
213 if [[ `host workbench.$ARVADOS_API_HOST |cut -f4 -d' '` != `host $ARVADOS_API_HOST |cut -f4 -d' '` ]]; then
214 # Workbench runs on a separate host. We need to run puppet there too.
215 run_puppet workbench.$IDENTIFIER ECODE
216 SUM_ECODE=$(($SUM_ECODE + $ECODE))
219 run_command workbench.$IDENTIFIER ECODE "/usr/local/bin/arvados-workbench-upgrade.sh"
220 SUM_ECODE=$(($SUM_ECODE + $ECODE))
222 if [[ "$SUM_ECODE" != "0" ]]; then
223 title "ERROR: Updating workbench FAILED"
224 EXITCODE=$(($EXITCODE + $SUM_ECODE))
228 for n in manage switchyard $SHELL_NODES $KEEP_NODES; do
230 if [[ $n =~ $ARVADOS_API_HOST$ ]]; then
231 # e.g. keep.qr1hi.arvadosapi.com
235 node=$n.$ARVADOS_API_HOST
239 node=${node%.arvadosapi.com}
241 title "Updating $node"
242 run_puppet $node ECODE
243 if [[ "$ECODE" != "0" ]]; then
244 title "ERROR: Updating $node node FAILED: exit code $ECODE"
245 EXITCODE=$(($EXITCODE + $ECODE))