Skip to content

Instantly share code, notes, and snippets.

@johncblandii
Created February 11, 2013 21:26
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 johncblandii/4757771 to your computer and use it in GitHub Desktop.
Save johncblandii/4757771 to your computer and use it in GitHub Desktop.
Unicorn deployment file for Capistrano
set_default(:unicorn_user) { user }
set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
set_default(:unicorn_workers, 2)
namespace :unicorn do
desc "Setup Unicorn initializer and app configuration"
task :setup, roles: :app do
run "mkdir -p #{shared_path}/config"
template "unicorn.rb.erb", unicorn_config
template "unicorn_init.erb", "/tmp/unicorn_init"
run "chmod +x /tmp/unicorn_init"
run %q{export RAILS_ENV="#{rails_env}"}
run "#{sudo} mv -f /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
run "#{sudo} update-rc.d -f unicorn_#{application} remove"
run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
end
after "deploy:setup", "unicorn:setup"
%w[start stop restart].each do |command|
desc "#{command} unicorn"
task command, roles: :app do
run "service unicorn_#{application} #{command}"
end
after "deploy:#{command}", "unicorn:#{command}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment