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/groups\",'
20 echo >&2 ' \"GET /arvados/v1/links\",'
21 echo >&2 ' \"GET /arvados/v1/groups/\",'
22 echo >&2 ' \"GET /arvados/v1/collections\",'
23 echo >&2 ' \"POST /arvados/v1/collections\",'
24 echo >&2 ' \"POST /arvados/v1/links\"]"'
28 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
33 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
34 # Note the quotes around `$TEMP': they are essential!
57 if [[ "$IDENTIFIER" == '' ]]; then
67 date=`date +'%Y-%m-%d %H:%M:%S'`
71 function run_puppet() {
75 title "Running puppet on $node"
77 if [[ "$DEBUG" != "0" ]]; then
78 ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "/usr/bin/puppet agent -t" | tee $TMP_FILE
80 ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "/usr/bin/puppet agent -t" > $TMP_FILE 2>&1
84 RESULT=$(cat $TMP_FILE)
86 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
87 # Ssh exits 255 if the connection timed out. Just ignore that.
88 # Puppet exits 2 if there are changes. For real!
89 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
91 echo "ERROR running puppet on $node: exit code $ECODE"
92 if [[ "$DEBUG" == "0" ]]; then
93 title "Command output follows:"
97 if [[ "$ECODE" == "255" ]]; then
98 title "Connection timed out"
101 if [[ "$ECODE" == "2" ]]; then
105 eval "$return_var=$ECODE"
108 function run_command() {
113 title "Running '$command' on $node"
115 if [[ "$DEBUG" != "0" ]]; then
116 ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "$command" | tee $TMP_FILE
118 ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "$command" > $TMP_FILE 2>&1
122 RESULT=$(cat $TMP_FILE)
124 if [[ "$ECODE" != "255" && "$ECODE" != "0" ]]; then
125 # Ssh exists 255 if the connection timed out. Just ignore that, it's possible that this node is
126 # a shell node that is down.
127 title "ERROR running command on $node: exit code $ECODE"
128 if [[ "$DEBUG" == "0" ]]; then
129 title "Command output follows:"
133 if [[ "$ECODE" == "255" ]]; then
134 title "Connection timed out"
138 eval "$return_var=$ECODE"
141 title "Updating API server"
143 run_puppet $IDENTIFIER.arvadosapi.com ECODE
144 SUM_ECODE=$(($SUM_ECODE + $ECODE))
145 run_command $IDENTIFIER.arvadosapi.com ECODE "/usr/local/bin/arvados-api-server-upgrade.sh"
146 SUM_ECODE=$(($SUM_ECODE + $ECODE))
147 run_command $IDENTIFIER.arvadosapi.com ECODE "dpkg -L arvados-mailchimp-plugin 2>/dev/null && apt-get install arvados-mailchimp-plugin --reinstall || echo"
148 SUM_ECODE=$(($SUM_ECODE + $ECODE))
150 if [[ "$SUM_ECODE" != "0" ]]; then
151 title "ERROR: Updating API server FAILED"
152 EXITCODE=$(($EXITCODE + $SUM_ECODE))
156 title "Loading ARVADOS_API_HOST and ARVADOS_API_TOKEN"
157 if [[ -f "$HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf" ]]; then
158 . $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf
160 title "WARNING: $HOME/.config/arvados/$IDENTIFIER.arvadosapi.com.conf not found."
162 if [[ "$ARVADOS_API_HOST" == "" ]] || [[ "$ARVADOS_API_TOKEN" == "" ]]; then
163 title "ERROR: ARVADOS_API_HOST and/or ARVADOS_API_TOKEN environment variables are not set."
167 title "Locating Arvados Standard Docker images project"
169 JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
170 DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
172 if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
173 title "Warning: Arvados Standard Docker Images project not found. Creating it."
175 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\"}"`
176 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\" }"
177 if [[ "$?" != "0" ]]; then
178 title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
183 title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
184 GIT_COMMIT=`ssh -o "StrictHostKeyChecking no" $IDENTIFIER cat /usr/local/arvados/src/git-commit.version`
186 if [[ "$?" != "0" ]] || [[ "$GIT_COMMIT" == "" ]]; then
187 title "ERROR: unable to get arvados/jobs Docker image git revision"
190 title "Found git commit for arvados/jobs Docker image: $GIT_COMMIT"
193 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
195 if [[ "$?" == "0" ]]; then
196 title "Found latest arvados/jobs Docker image, nothing to upload"
198 title "Installing latest arvados/jobs Docker image"
199 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"
200 if [[ "$?" -ne 0 ]]; then
201 title "'git pull' failed exiting..."
206 title "Gathering list of shell and Keep nodes"
207 SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv virtual_machine list |jq .items[].hostname -r`
208 KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv keep_service list |jq .items[].service_host -r`
210 title "Updating workbench"
212 if [[ `host workbench.$ARVADOS_API_HOST` != `host $ARVADOS_API_HOST` ]]; then
213 # Workbench runs on a separate host. We need to run puppet there too.
214 run_puppet workbench.$IDENTIFIER ECODE
215 SUM_ECODE=$(($SUM_ECODE + $ECODE))
218 run_command workbench.$IDENTIFIER ECODE "/usr/local/bin/arvados-workbench-upgrade.sh"
219 SUM_ECODE=$(($SUM_ECODE + $ECODE))
221 if [[ "$SUM_ECODE" != "0" ]]; then
222 title "ERROR: Updating workbench FAILED"
223 EXITCODE=$(($EXITCODE + $SUM_ECODE))
227 for n in manage switchyard $SHELL_NODES $KEEP_NODES; do
229 if [[ $n =~ $ARVADOS_API_HOST$ ]]; then
230 # e.g. keep.qr1hi.arvadosapi.com
234 node=$n.$ARVADOS_API_HOST
238 node=${node%.arvadosapi.com}
240 title "Updating $node"
241 run_puppet $node ECODE
242 if [[ "$ECODE" != "0" ]]; then
243 title "ERROR: Updating $node node FAILED: exit code $ECODE"
244 EXITCODE=$(($EXITCODE + $ECODE))