Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
Created May 16, 2011 18:12
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrrooijen/974983 to your computer and use it in GitHub Desktop.
Save mrrooijen/974983 to your computer and use it in GitHub Desktop.
Unicorn + Bluepill + Capistrano with RVM
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :application, "my_app"
set :repository, "git@trunksapp.com:myuser/myapp.git"
set :branch, "production"
set :rvm_ruby_string, "1.9.2"
set :deploy_to, "/var/applications/"
set :user, "username"
set :scm, :git
set :use_sudo, false
default_run_options[:pty] = true
role :web, "123.45.678.90"
role :app, "123.45.678.90"
role :db, "123.45.678.90", :primary => true
BP = 'bluepill --no-privileged'
namespace :deploy do
##
# Invoked during initial deployment
task :start do
run "cd #{current_path} && bundle --without test --without development"
run "cd #{current_path} && RACK_ENV=production UNICORN_SERVERS=#{ENV['UNICORN_SERVERS'] || 3} #{BP} load ./app.pill"
end
##
# Invoked after each deployment afterwards
task :restart do
run "cd #{current_path} && bundle --without test --without development"
ignore_failure { run "cd #{current_path} && #{BP} stop unicorn-cluster && sleep 1 && #{BP} quit && sleep 1" }
run "cd #{current_path} && RACK_ENV=production UNICORN_SERVERS=#{ENV['UNICORN_SERVERS'] || 3} #{BP} load ./app.pill"
end
end
##
# Shorthand for ignoring exceptions
def ignore_failure(&block)
begin
yield
rescue
end
end
#! /usr/bin/env ruby
Bluepill.application("my-app") do |app|
app.process("unicorn") do |process|
process.pid_file = File.join(RAILS_ROOT, 'tmp', 'pids', 'unicorn.pid')
process.working_dir = RAILS_ROOT
process.start_command = "/usr/bin/env UNICORN_SERVERS=#{ENV['UNICORN_SERVERS']} #{UNICORN_PATH} -D -c config/unicorn.rb -E production"
process.stop_command = "kill -QUIT {{PID}}"
process.restart_command = "kill -USR2 {{PID}}"
process.uid = process.gid = 'deploy'
process.start_grace_time = 8.seconds
process.stop_grace_time = 5.seconds
process.restart_grace_time = 13.seconds
process.monitor_children do |child_process|
child_process.stop_command = "kill -QUIT {{PID}}"
child_process.checks :mem_usage, :every => 10.seconds, :below => 150.megabytes, :times => [3,4], :fires => :stop
child_process.checks :cpu_usage, :every => 10.seconds, :below => 20, :times => [3,4], :fires => :stop
end
end
end
# Spawn workers - default 3 unless ENV['UNICORN_SERVERS'] is set (passed in via Bluepill)
worker_processes ENV['UNICORN_SERVERS'].nil? ? 3 : ENV['UNICORN_SERVERS'].to_i
# Restart any workers that haven't responded in 30 seconds
timeout 30
# Listen on a Unix data socket
listen File.join(ENV['HOME'], 'tmp', 'sockets', 'rails', 'unicorn.sock'), :backlog => 2048
# Create the pid file
pid File.join(ENV['HOME'], 'tmp', 'pids', 'rails', 'unicorn.pid')
@blackjid
Copy link

What about with rbenv?

@bf4
Copy link

bf4 commented Jul 10, 2013

@blackjid Configure your deploy to use rbenv then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment