Created
May 17, 2011 10:47
-
-
Save alexyoung/976283 to your computer and use it in GitHub Desktop.
Deployment script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Configuration | |
SERVER='myserver' | |
DEPLOY_TO='/path/to/app' | |
EXCLUDE='*.swp .git/ db/sphinx/ tmp/ log/' | |
DRY_RUN=false | |
DEPLOY_GEM_PATH='/opt/ec/ruby/1.8.7/lib/ruby/gems/1.8' | |
# To improve ssh performance, consider reusing connections: | |
# | |
# Host * | |
# ControlMaster auto | |
# ControlPath /tmp/%r@%h:%p | |
# Map the excluded files to rsync's options | |
function excludes { | |
EXCLUDES='' | |
for i in $(echo $EXCLUDE | tr " " "\n") | |
do | |
EXCLUDES="$EXCLUDES --exclude $i" | |
done | |
} | |
# Run rsync | |
function upload_files { | |
excludes | |
CMD="rsync -avz $EXCLUDES" | |
if $DRY_RUN ; then | |
CMD="$CMD --dry-run" | |
fi | |
CMD="$CMD ./ $SERVER:$DEPLOY_TO" | |
echo $CMD | |
$CMD | |
} | |
# run the Rails migrations | |
function migrate { | |
ssh $SERVER "cd $DEPLOY_TO && RAILS_ENV=production rake db:migrate" | |
} | |
# Restart the web processes, easy with passenger | |
function restart_web_processes { | |
ssh $SERVER "cd $DEPLOY_TO && touch tmp/restart.txt" | |
} | |
# Run bundler, there's an extra option here for my server's environment | |
function bundler { | |
# chgrp -R deploy /opt/ec/ruby/1.8.7/lib/ruby/gems/1.8 | |
# chmod g+w -R /opt/ec/ruby/1.8.7/lib/ruby/gems/1.8 | |
ssh $SERVER "cd $DEPLOY_TO && GEM_PATH=$DEPLOY_GEM_PATH RAILS_ENV=production CXX=/usr/sfw/bin/g++ bundle install" | |
} | |
# Copy the app's settings files for this environment | |
function copy_settings { | |
# Remove the old ones | |
ssh $SERVER "rm $DEPLOY_TO/config/settings.yml" | |
ssh $SERVER "rm $DEPLOY_TO/config/database.yml" | |
ssh $SERVER "rm $DEPLOY_TO/config/sphinx.yml" | |
# Copy | |
ssh $SERVER "cp $DEPLOY_TO/config/environments/settings/test.yml $DEPLOY_TO/config/settings.yml" | |
ssh $SERVER "cp $DEPLOY_TO/config/environments/settings/test_database.yml $DEPLOY_TO/config/database.yml" | |
ssh $SERVER "cp $DEPLOY_TO/config/environments/settings/test_sphinx.yml $DEPLOY_TO/config/sphinx.yml" | |
} | |
function locales { | |
ssh $SERVER "cd $DEPLOY_TO && RAILS_ENV=production rake tolk:dump_all" | |
} | |
# Reusable: | |
function restart_sphinx { | |
ssh $SERVER "cd $DEPLOY_TO && RAILS_ENV=production rake ts:restart" | |
} | |
# Run deployment | |
upload_files | |
if ! $DRY_RUN ; then | |
copy_settings | |
bundler | |
migrate | |
restart_sphinx | |
locales | |
restart_web_processes | |
fi |
nice script.
I had forked it and added ControlPersist 1h
to the .ssh/config, to launch a background session automatically for the first contact, and then stay up for 1 hour of inactivity before closing.
HIH
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'll give it a try, thanks