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.curoverse.rb"
106 ensure_symlink "services/api/config/deploy.$IDENTIFIER.rb"
109 title "Deploying API server"
113 bundle install --deployment
115 # make sure we do not print the output of config:check
116 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
118 bundle exec cap deploy -f Capfile.$IDENTIFIER
122 # restore unaltered deploy.common.rb
123 cd $WORKSPACE/$DEPLOY_REPO
124 git checkout services/api/config/deploy.common.rb
126 if [[ "$ECODE" != "0" ]]; then
127 title "!!!!!! DEPLOYING API SERVER FAILED !!!!!!"
128 EXITCODE=$(($EXITCODE + $ECODE))
132 title "Deploying API server complete"
134 # Install updated debian packages
135 title "Deploying updated arvados debian packages"
137 ssh -p2222 root@$IDENTIFIER.arvadosapi.com -C "apt-get update && apt-get -qqy install arvados-src python-arvados-fuse python-arvados-python-client"
139 if [[ "$ECODE" != "0" ]]; then
140 title "!!!!!! DEPLOYING DEBIAN PACKAGES FAILED !!!!!!"
141 EXITCODE=$(($EXITCODE + $ECODE))
145 title "Deploying updated arvados debian packages complete"
147 # Install updated arvados gems
148 title "Deploying updated arvados gems"
150 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"
152 if [[ "$ECODE" != "0" ]]; then
153 title "!!!!!! DEPLOYING ARVADOS GEMS FAILED !!!!!!"
154 EXITCODE=$(($EXITCODE + $ECODE))
158 title "Deploying updated arvados gems complete"
161 title "Deploying workbench"
164 bundle install --deployment
166 # make sure we do not print the output of config:check
167 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
169 bundle exec cap deploy -f Capfile.workbench.$IDENTIFIER
173 # restore unaltered deploy.common.rb
174 cd $WORKSPACE/$DEPLOY_REPO
175 git checkout apps/workbench/config/deploy.common.rb
177 if [[ "$ECODE" != "0" ]]; then
178 title "!!!!!! DEPLOYING WORKBENCH FAILED !!!!!!"
179 EXITCODE=$(($EXITCODE + $ECODE))
183 title "Deploying workbench complete"
185 # Update compute node(s)
186 title "Update compute node(s)"
188 # Get list of nodes that are up
189 COMPRESSED_NODE_LIST=`ssh -p2222 root@$IDENTIFIER -C "sinfo --long -p crypto -r -o "%N" -h"`
191 if [[ "$COMPRESSED_NODE_LIST" != '' ]]; then
192 COMPUTE_NODES=`ssh -p2222 root@$IDENTIFIER -C "scontrol show hostname $COMPRESSED_NODE_LIST"`
195 for node in $COMPUTE_NODES; do
196 echo "Updating $node.$IDENTIFIER"
197 run_puppet $node ECODE
198 SUM_ECODE=$(($SUM_ECODE + $ECODE))
201 if [[ "$SUM_ECODE" != "0" ]]; then
202 title "!!!!!! Update compute node(s) FAILED !!!!!!"
203 EXITCODE=$(($EXITCODE + $SUM_ECODE))
207 title "Update compute node(s) complete"
211 run_puppet shell ECODE
213 if [[ "$ECODE" == "2" ]]; then
214 # Puppet exits '2' if there are changes. For real!
218 if [[ "$ECODE" != "0" ]]; then
219 title "!!!!!! Update shell FAILED !!!!!!"
220 EXITCODE=$(($EXITCODE + $ECODE))
223 title "Update shell complete"
227 run_puppet keep0 ECODE
229 if [[ "$ECODE" == "2" ]]; then
230 # Puppet exits '2' if there are changes. For real!
234 if [[ "$ECODE" != "0" ]]; then
235 title "!!!!!! Update keep0 FAILED !!!!!!"
236 EXITCODE=$(($EXITCODE + $ECODE))
239 title "Update keep0 complete"