diff --git a/Gemfile b/Gemfile index e40d1efdc..1f2f8958b 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,7 @@ gem "truncate_html" group :development do gem "capistrano" + gem "capistrano-unicorn" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 6889ca502..f265f717c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,8 @@ GEM net-sftp (>= 2.0.0) net-ssh (>= 2.0.14) net-ssh-gateway (>= 1.1.0) + capistrano-unicorn (0.1.5) + capistrano capybara (1.1.2) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -184,6 +186,7 @@ DEPENDENCIES ansi authlogic capistrano + capistrano-unicorn capybara database_cleaner erubis diff --git a/config/deploy.rb b/config/deploy.rb index fd0fa9640..cf00d960f 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,5 +1,7 @@ load "config/db" load "local/config/deploy.rb" if File.exists?("local/config/deploy.rb") +require 'bundler/capistrano' +require "capistrano-unicorn" set :scm, "git" set :repository, "git://github.com/scottwillson/racing_on_rails.git" @@ -9,7 +11,7 @@ set :deploy_via, :remote_cache set :keep_releases, 5 -set :deploy_to, "/usr/local/www/rails/#{application}" +set :deploy_to, "/var/www/rails/#{application}" set :user, "app" set :use_sudo, false @@ -41,22 +43,6 @@ run("if [ -e \"#{previous_release}/public/#{cached_path}\" ]; then cp -pr #{previous_release}/public/#{cached_path} #{release_path}/public/#{cached_path}; fi") rescue nil end end - - task :start, :roles => :app do - run "/usr/local/etc/rc.d/unicorn start #{application}" - end - - task :stop, :roles => :app do - run "/usr/local/etc/rc.d/unicorn stop #{application}" - end - - task :restart, :roles => :app do - run "/usr/local/etc/rc.d/unicorn reload #{application}" - end - - task :status, :roles => :app do - run "/usr/local/etc/rc.d/unicorn status #{application}" - end namespace :web do desc "Present a maintenance page to visitors" diff --git a/config/new_server.rb b/config/new_server.rb new file mode 100644 index 000000000..f58b4524c --- /dev/null +++ b/config/new_server.rb @@ -0,0 +1,11 @@ +load "deploy" +load "config/deploy" +require "capistrano-unicorn" + +roles.clear +role :app, "bushtit.obra.org" +role :db, "bushtit.obra.org", :primary => true +set :user, "app" + +set :rails_env, "production" +set :deploy_to, "/var/www/rails/#{application}" diff --git a/config/unicorn.rb b/config/unicorn.rb deleted file mode 100644 index 232bdc7c4..000000000 --- a/config/unicorn.rb +++ /dev/null @@ -1,13 +0,0 @@ -# unicorn -c /usr/local/etc/unicorn/wsba.rb -E production -D - -rails_env = ENV['::Rails.env'] || 'production' - -worker_processes 2 -timeout 90 - -# This may not be working correctly in production -rails_root = File.expand_path(File.dirname(__FILE__) + "/../") -working_directory rails_root -listen "#{rails_root}/tmp/sockets/unicorn.sock", :backlog => 64 -stderr_path "#{rails_root}/log/unicorn.stderr.log" -stdout_path "#{rails_root}/log/unicorn.stdout.log" diff --git a/config/unicorn/production.rb b/config/unicorn/production.rb new file mode 100644 index 000000000..ac726ef1f --- /dev/null +++ b/config/unicorn/production.rb @@ -0,0 +1,32 @@ +rails_env = ENV['::Rails.env'] || 'production' + +worker_processes 4 +preload_app true +timeout 180 + +user 'app', 'app' + +app_path = File.expand_path(File.dirname(__FILE__) + "/../../../current") +working_directory app_path +listen "#{app_path}/tmp/sockets/unicorn.sock", :backlog => 64 +stderr_path "log/unicorn.stderr.log" +stdout_path "log/unicorn.stdout.log" + +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 diff --git a/config/unicorn_development.rb b/config/unicorn_development.rb deleted file mode 100644 index a0e13ca7b..000000000 --- a/config/unicorn_development.rb +++ /dev/null @@ -1 +0,0 @@ -timeout 300