public
Last active

deploy use unicorn and nginx

  • Download Gist
deploy.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
set :application, "hermes"
set :repository, "git@your_repository:hermes.git"
set :user, 'root'
set :use_sudo, false
 
set :deploy_via, :remote_cache
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
 
role :web, "xxx.com" # Your HTTP server, Apache/etc
role :app, "xxx.com" # This may be the same as your `Web` server
role :db, "xxx.com", :primary => true # This is where Rails migrations will run
#role :db, "your slave db-server here"
set :deploy_to, "/path/to/app/#{application}"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
 
# If you are using Passenger mod_rails uncomment this:
# namespace :deploy do
# task :start do ; end
# task :stop do ; end
# task :restart, :roles => :app, :except => { :no_release => true } do
# run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
# end
# end
 
before "deploy", "deploy:bundle_gems"
before "deploy:restart", "deploy:bundle_gems"
#after "deploy:bundle_gems", "deploy:restart"
#after "deploy:bundle_gems", "deploy:restart"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
set :bundle, "/var/lib/gems/1.9.1/bin//bundle"
set :unicorn_rails, "/var/lib/gems/1.9.1/bin//unicorn_rails"
 
namespace :deploy do
task :bundle_gems do
run "cd #{deploy_to}/current && #{bundle} install --path vendor/gems"
end
 
task :start, :roles => :app, :except => { :no_release => true} do
run "#{unicorn_rails} -c #{deploy_to}/current/config/unicorn.rb -D -E production"
end
 
task :stop, :roles => :app, :except => { :no_release => true} do
run "kill `cat #{unicorn_pid}`"
end
task :reload, :roles => :app, :except => { :no_release => true } do
run "kill -s USR2 `cat #{unicorn_pid}`"
end
 
task :restart, :roles => :app, :except => { :no_release => true } do
stop
start
end
end
 
after "migration:reload", "deploy:restart"
namespace :migration do
task :reload, :roles => :app, :except => { :no_release => true } do
run "cd #{deploy_to}/current && rake db:drop:all && rake db:migrate RAILS_ENV='production' && rake db:seed RAILS_ENV='production'"
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.