add unicorn support

This commit is contained in:
r888888888 2013-04-15 21:58:00 -07:00
parent ff2c125e0f
commit 27f60060d5
4 changed files with 69 additions and 6 deletions

View File

@ -35,7 +35,12 @@ gem 'bcrypt-ruby', :require => "bcrypt"
gem 'aws-s3', :require => "aws/s3"
gem 'awesome_print'
group :production do
gem 'capistrano-unicorn', :require => false
end
group :development do
gem 'ruby-prof'
gem 'pry'
end

View File

@ -63,6 +63,14 @@ GEM
bourne (1.4.0)
mocha (~> 0.13.2)
builder (3.0.4)
capistrano (2.14.2)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
capistrano-unicorn (0.1.7)
capistrano
chronic (0.9.1)
coderay (1.0.9)
daemons (1.1.9)
@ -79,6 +87,7 @@ GEM
multi_json (~> 1.0)
factory_girl (4.2.0)
activesupport (>= 3.0.0)
highline (1.6.18)
hike (1.2.1)
i18n (0.6.4)
journey (1.0.4)
@ -97,9 +106,13 @@ GEM
multi_json (1.7.2)
net-http-digest_auth (1.3)
net-http-persistent (2.8)
net-scp (1.1.0)
net-ssh (>= 2.6.5)
net-sftp (2.1.1)
net-ssh (>= 2.6.5)
net-ssh (2.6.6)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
newrelic_rpm (3.6.0.78)
nokogiri (1.5.9)
ntlm-http (0.1.1)
@ -191,6 +204,7 @@ DEPENDENCIES
awesome_print
aws-s3
bcrypt-ruby
capistrano-unicorn
daemons
delayed_job
delayed_job_active_record

View File

@ -19,6 +19,8 @@ set :scm, :git
set :user, "albert"
set :deploy_to, "/var/www/danbooru2"
require 'capistrano-unicorn'
default_run_options[:pty] = true
namespace :local_config do
@ -101,11 +103,6 @@ namespace :deploy do
task :precompile_assets do
run "cd #{current_path}; bundle exec rake assets:precompile"
end
desc "Restart the application"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
namespace :delayed_job do
@ -145,7 +142,8 @@ after "deploy:stop", "delayed_job:stop"
after "deploy:restart", "delayed_job:restart"
before "deploy:update", "deploy:web:disable"
after "deploy:update", "deploy:migrate"
after "deploy:update", "deploy:restart"
after "deploy:restart", "unicorn:reload"
after "deploy:restart", "unicorn:restart"
after "deploy:restart", "deploy:precompile_assets"
after "deploy:restart", "deploy:web:enable"
after "delayed_job:stop", "delayed_job:kill"

46
config/unicorn.rb Normal file
View File

@ -0,0 +1,46 @@
# Set your full path to application.
app_path = "/var/www/danbooru2/current"
# Set unicorn options
if Socket.gethostname =~ /sonohara|hijiribe/
worker_processes 12
else
worker_processes 1
end
preload_app false
timeout 180
listen "127.0.0.1:9000"
# Spawn unicorn master worker for user apps (group: apps)
user 'albert', 'albert'
# Fill path to your app
working_directory app_path
# Should be 'production' by default, otherwise use other env
rails_env = ENV['RAILS_ENV'] || 'production'
# Log everything to one file
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"
# Set master PID location
pid "#{app_path}/tmp/pids/unicorn.pid"
before_fork do |server, worker|
ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
end
after_fork do |server, worker|
ActiveRecord::Base.establish_connection
end