Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH.
on rubygems.org
Capistrano is written in Ruby, but it can easily be used to deploy any language.on capistranorb.com
cd my_awesome_app/ gem install capistrano
gem install capistrano-multistage
# (or just include these on your Gemfile) capify .
require 'capistrano/ext/multistage'
set :stages, %w(production staging)
set :default_stage, "staging"
set :application, "set your application name here"
set :scm, :git
set :repository, "ssh://ourserver/#{application}.git"
set :deploy_to, "/var/www/#{application}"
set :deploy_via, :remote_cache
set :rails_env, 'production'
set :user, "your username here"
set :branch, "desired branch to deploy from"
role :web, "your web-server here"
role :app, "your app-server here"
role :db, "your primary db-server here", :primary => true
role :db, "your slave db-server here"
cap <enviroment> deploy:setup
cap <environment>
deploy:cold
cap <environment> deploy
desc "Task description"
task :<task name>, roles: [<desired role(s) which should run the task >] do
run "apt-get -y update" # Bash commands can be used like this
end
after "deploy:<task>", "<namespace>:<task name>"
desc "Install latest stable release of nginx"
task :install, roles: :web do
run "#{sudo} add-apt-repository -y ppa:nginx/stable"
run "#{sudo} apt-get -y update"
run "#{sudo} apt-get -y install nginx"
end
after "deploy:install", "nginx:install"
cap <environment> deploy:install
set :domain, "myawesomeapp.com"
cap <environment> deploy:setup
desc "Setup nginx configuration for this application"
task :setup, roles: :web do
template "nginx_unicorn.erb", "/tmp/nginx_conf"
run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-enabled/#{application}"
run "#{sudo} rm -f /etc/nginx/sites-enabled/default"
restart
end
after "deploy:setup", "nginx:setup"
def template(from, to)
erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
put ERB.new(erb).result(binding), to
end
upstream unicorn { server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0; } server { listen 80; server_name <%= domain %>; root <%= current_path %>/public;
location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; }
... }
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if children > 250 then restart
if 5 restarts within 5 cycles then timeout
desc "Tail all application log files"
task :tail, :roles => :app do
run "tail -f #{shared_path}/log/*.log" do |channel, stream, data|
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end