Skip to content

Instantly share code, notes, and snippets.

@eddiesel
Created April 25, 2012 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddiesel/2492856 to your computer and use it in GitHub Desktop.
Save eddiesel/2492856 to your computer and use it in GitHub Desktop.
Capistrano recipe for multi-stage deployment running Passenger standalone
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
# REPLACE this below with your ruby version/gemset version: YOUR_RUBY_VERSION@YOUR_GEM_SET
set :rvm_ruby_string, 'ruby-1.9.2-p136@example_gemset'
set :use_sudo, false
set :stages, %w(production staging)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
# REPLACE this below with your git repo
set :repository, "git@github.com:example/example.git"
set :scm, :git
set :branch, "master"
set :deploy_via, :remote_cache
# REPLACE the below with your deploy server credentials/server domain name (or ip)
set :user, 'exampleuser'
server "example.com", :app, :web, :db, :primary => true
after "deploy:update_code",
"deploy:update_shared_symlinks"
set :bundle_flags, '--deployment'
require "bundler/capistrano"
after "bundle:install",
"deploy:migrate"
after "deploy",
"deploy:cleanup"
namespace :deploy do
task :start do ; end
task :stop do ; end
# This task with bounce the standalone passenger server (running the embedded nginx server).
# The rails_env and passenger_port are specified in the deploy environment files, ex: "config/deploy/staging.rb"
desc "Restart Passenger server"
task :restart, :roles => :app, :except => { :no_release => true } do
run <<-CMD
if [[ -f #{release_path}/tmp/pids/passenger.#{passenger_port}.pid ]];
then
cd #{deploy_to}/current && passenger stop -p #{passenger_port} --pid-file #{release_path}/tmp/pids/passenger.#{passenger_port}.pid;
fi
CMD
# restart passenger standalone on the specified port/environment and as a daemon
run "cd #{deploy_to}/current && #{try_sudo} passenger start -e #{rails_env} -p #{passenger_port} -d"
end
desc "Update shared symbolic links"
task :update_shared_symlinks do
shared_files = ["config/database.yml"]
shared_files.each do |path|
run "rm -rf #{File.join(release_path, path)}"
run "ln -s #{File.join(deploy_to, "shared", path)} #{File.join(release_path, path)}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment