4 read -rd "\000" helpmessage <<EOF
5 $(basename $0): Deploy Arvados to a cluster
8 WORKSPACE=/path/to/arvados $(basename $0) <identifier> <deploy_repo_name>
12 identifier Arvados cluster name
13 deploy_repo_name Name for the repository with the (capistrano) deploy scripts
15 WORKSPACE=path Path to the Arvados source tree to deploy from
23 if [[ "$IDENTIFIER" == '' || "$DEPLOY_REPO" == '' ]]; then
24 echo >&2 "$helpmessage"
30 if ! [[ -n "$WORKSPACE" ]]; then
31 echo >&2 "$helpmessage"
33 echo >&2 "Error: WORKSPACE environment variable not set"
43 printf "\n%*s\n\n" $(((${#title}+$COLUMNS)/2)) "********** $1 **********"
46 # We only install capistrano in dev mode
47 export RAILS_ENV=development
49 source /etc/profile.d/rvm.sh
52 # Weirdly, jenkins/rvm ties itself in a knot.
55 # Just say what version of ruby we're running
58 function run_puppet() {
63 ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node.$IDENTIFIER -C "/usr/bin/puppet agent -t" | tee $TMP_FILE
66 RESULT=$(cat $TMP_FILE)
68 if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0" ]]; then
69 # Puppet exists 255 if the connection timed out. Just ignore that, it's possible that this node is
70 # a compute node that was being shut down.
71 # Puppet exits 2 if there are changes. For real!
72 # Puppet prints 'Notice: Run of Puppet configuration client already in progress' if another puppet process
74 echo "ERROR updating $node.$IDENTIFIER: exit code $ECODE"
78 eval "$return_var=$ECODE"
81 function ensure_symlink() {
82 if [[ ! -L $WORKSPACE/$1 ]]; then
83 ln -s $WORKSPACE/$DEPLOY_REPO/$1 $WORKSPACE/$1
87 # Check out/update the $DEPLOY_REPO repository
88 if [[ ! -d $DEPLOY_REPO ]]; then
90 git clone git@git.curoverse.com:$DEPLOY_REPO.git
96 # Make sure the necessary symlinks are in place
98 ensure_symlink "apps/workbench/Capfile.workbench.$IDENTIFIER"
99 ensure_symlink "apps/workbench/config/deploy.common.rb"
100 ensure_symlink "apps/workbench/config/deploy.curoverse.rb"
101 ensure_symlink "apps/workbench/config/deploy.workbench.$IDENTIFIER.rb"
103 ensure_symlink "services/api/Capfile.$IDENTIFIER"
104 ensure_symlink "services/api/config/deploy.common.rb"
105 ensure_symlink "services/api/config/deploy.$IDENTIFIER.rb"
108 title "Deploying API server"
112 bundle install --deployment
114 # make sure we do not print the output of config:check
115 sed -i'' -e "s/RAILS_ENV=production #{rake} config:check/RAILS_ENV=production QUIET=true #{rake} config:check/" $WORKSPACE/$DEPLOY_REPO/services/api/config/deploy.common.rb
117 bundle exec cap deploy -f Capfile.$IDENTIFIER
121 # restore unaltered deploy.common.rb
122 cd $WORKSPACE/$DEPLOY_REPO
123 git checkout services/api/config/deploy.common.rb
125 if [[ "$ECODE" != "0" ]]; then
126 title "!!!!!! DEPLOYING API SERVER FAILED !!!!!!"
127 EXITCODE=$(($EXITCODE + $ECODE))
131 title "Deploying API server complete"
133 # Install updated debian packages
134 title "Deploying updated arvados debian packages"
136 ssh -p2222 root@$IDENTIFIER.arvadosapi.com -C "apt-get update && apt-get -qqy install arvados-src python-arvados-fuse python-arvados-python-client"
138 if [[ "$ECODE" != "0" ]]; then
139 title "!!!!!! DEPLOYING DEBIAN PACKAGES FAILED !!!!!!"
140 EXITCODE=$(($EXITCODE + $ECODE))
144 title "Deploying updated arvados debian packages complete"
146 # Install updated arvados gems
147 title "Deploying updated arvados gems"
149 ssh -p2222 root@$IDENTIFIER.arvadosapi.com -C "/usr/local/rvm/bin/rvm default do gem install arvados arvados-cli && /usr/local/rvm/bin/rvm default do gem clean arvados arvados-cli"
151 if [[ "$ECODE" != "0" ]]; then
152 title "!!!!!! DEPLOYING ARVADOS GEMS FAILED !!!!!!"
153 EXITCODE=$(($EXITCODE + $ECODE))
157 title "Deploying updated arvados gems complete"
160 title "Deploying workbench"
163 bundle install --deployment
165 # make sure we do not print the output of config:check
166 sed -i'' -e "s/RAILS_ENV=production #{rake} config:check/RAILS_ENV=production QUIET=true #{rake} config:check/" $WORKSPACE/$DEPLOY_REPO/apps/workbench/config/deploy.common.rb
168 bundle exec cap deploy -f Capfile.workbench.$IDENTIFIER
172 # restore unaltered deploy.common.rb
173 cd $WORKSPACE/$DEPLOY_REPO
174 git checkout apps/workbench/config/deploy.common.rb
176 if [[ "$ECODE" != "0" ]]; then
177 title "!!!!!! DEPLOYING WORKBENCH FAILED !!!!!!"
178 EXITCODE=$(($EXITCODE + $ECODE))
182 title "Deploying workbench complete"
184 # Update compute node(s)
185 title "Update compute node(s)"
187 # Get list of nodes that are up
188 COMPRESSED_NODE_LIST=`ssh -p2222 root@$IDENTIFIER -C "sinfo --long -p crypto -r -o "%N" -h"`
190 if [[ "$COMPRESSED_NODE_LIST" != '' ]]; then
191 COMPUTE_NODES=`ssh -p2222 root@$IDENTIFIER -C "scontrol show hostname $COMPRESSED_NODE_LIST"`
194 for node in $COMPUTE_NODES; do
195 echo "Updating $node.$IDENTIFIER"
196 run_puppet $node ECODE
197 SUM_ECODE=$(($SUM_ECODE + $ECODE))
200 if [[ "$SUM_ECODE" != "0" ]]; then
201 title "!!!!!! Update compute node(s) FAILED !!!!!!"
202 EXITCODE=$(($EXITCODE + $SUM_ECODE))
206 title "Update compute node(s) complete"
210 run_puppet shell ECODE
212 if [[ "$ECODE" == "2" ]]; then
213 # Puppet exits '2' if there are changes. For real!
217 if [[ "$ECODE" != "0" ]]; then
218 title "!!!!!! Update shell FAILED !!!!!!"
219 EXITCODE=$(($EXITCODE + $ECODE))
222 title "Update shell complete"
226 run_puppet keep0 ECODE
228 if [[ "$ECODE" == "2" ]]; then
229 # Puppet exits '2' if there are changes. For real!
233 if [[ "$ECODE" != "0" ]]; then
234 title "!!!!!! Update keep0 FAILED !!!!!!"
235 EXITCODE=$(($EXITCODE + $ECODE))
238 title "Update keep0 complete"