Skip to content

Instantly share code, notes, and snippets.

@peterc
Created February 6, 2010 01:48
Show Gist options
  • Save peterc/296460 to your computer and use it in GitHub Desktop.
Save peterc/296460 to your computer and use it in GitHub Desktop.
# === Documentation === #
# This is just a standard shell script, which is loaded from the
# post-receive hook when a new branch is created.
# Just don't forget that gems you have on your local machine probably
# aren't installed at the server, at least before you run gem bundle.
# Your working directory is root of your application which was just cloned
# here. (Probably) unlike to your local machine, basename is name of the branch,
# not name of the application. It shouldn't matter in most cases, but sometimes
# it does, for example in Python where you are using import myapp.something.
# 1) Write an awful perl-ish script with sed -i / perl -i / ruby -i and just replace
# the name in your code. It might work, but come on, you don't want to do that.
# 2) Your application will be as a subdirectory of the root of the repository,
# so you may call it whatever you want.
# 3) Obviously the best solution is to change the post-receive script, for example:
# Task["deployer:compile_hook"].config[:target] = "myappname"
# Make sure this script isn't executable, otherwise the script will simply run,
# so you won't have access to shell functions from the post-receive hook.
# However this is useful if you want to run this script under another interpret.
# If you want to install hooks which will be executed rather than just
# loaded, use ./tasks.rb deployer:install --executable or add
# Task["deployer:install"].config[:executable] = false to your tasks.rb
# Also, post-receive hook run under /bin/sh by default, but you might want to
# use something more advance like bash or zsh. Since these shells are compatible
# with the original sh, it's easy, just run ./tasks.rb deployer:compile_hook --shebang="#!/bin/zsh"
# or add Task["deployer:compile_hook"].config[:shebang] = "#!/bin/zsh" to your tasks.rb and reinstall the hooks.
# Use Ruby 1.8.7
rvm use 1.8.7
# Ruby on Rails
export RAILS_ENV="production"
info "Running bundler ..."
bundle install
bundle lock
info "Creating databases ..."
# bundle exec rake db:create # This doesn't work so far
./gems/bin/rake db:create
info "Running update hook ..."
. hooks/update
#!/usr/bin/env nake
# This is an executable script, you can list tasks by running ./tasks.rb -T
# It requires github.com/botanicus/nake ... and no, I couldn't use Rake since
# Rake doesn't provide any kind of configuration which is necessary for us.
# The post-receive hook on the remote server is already installed, so don't
# worry about this stuff, unless you want to change something in the hook.
begin
load "git-deployer.nake"
Task["deployer:setup"].config[:servers] = {
server: {
user: "josefrichter",
host: "78.40.35.50",
repo: "/home/josefrichter/apps/smartlinks.git",
path: "/home/josefrichter/apps/smartlinks"
}
}
rescue LoadError
warn "You have to install git-deployer gem if you want to deploy to remote servers!"
end
# === Documentation === #
# This is just a standard shell script, which is loaded from the
# post-receive hook each time a branch is updated.
# Just don't forget that gems you have on your local machine probably
# aren't installed at the server, at least before you run gem bundle.
# Your working directory is root of your application which was just cloned
# here. (Probably) unlike to your local machine, basename is name of the branch,
# not name of the application. It shouldn't matter in most cases, but sometimes
# it does, for example in Python where you are using import myapp.something.
# 1) Write an awful perl-ish script with sed -i / perl -i / ruby -i and just replace
# the name in your code. It might work, but come on, you don't want to do that.
# 2) Your application will be as a subdirectory of the root of the repository,
# so you may call it whatever you want.
# 3) Obviously the best solution is to change the post-receive script, for example:
# Task["deployer:compile_hook"].config[:target] = "myappname"
# Make sure this script isn't executable, otherwise the script will simply run,
# so you won't have access to shell functions from the post-receive hook.
# However this is useful if you want to run this script under another interpret.
# If you want to install hooks which will be executed rather than just
# loaded, use ./tasks.rb deployer:install --executable or add
# Task["deployer:install"].config[:executable] = false to your tasks.rb
# Use Ruby 1.8.7
rvm use 1.8.7
export RAILS_ENV="production"
info "Running bundler ..."
bundle install
bundle lock
# bundle exec rake db:migrate
./gems/bin/rake db:migrate
if test -f tmp/pids/thin.pid; then
info "Restarting Thin ..."
bundle exec thin restart
else
info "Thin doesn't run, starting it ..."
bundle exec thin start -e production --daemonize
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment