I am trying to use capistrano and unicorn for the first time in my rails application. I can deploy successfully, except that unicorn does not start with the following error from stderr:
I, [2013-03-25T16:55:35.877323 #2378] INFO -- : reloading config_file=/var/www/good/current/config/unicorn.rb E, [2013-03-25T16:55:35.881496 #2378] ERROR -- : error reloading config_file=/var/www/good/current/config/unicorn.rb: Already running on PID:2378 (or pid=/var/www/good/current/tmp/pids/unicorn.pid is stale) (ArgumentError) E, [2013-03-25T16:55:35.881548 #2378] ERROR -- : /var/www/good/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:193:in `pid=' E, [2013-03-25T16:55:35.881579 #2378] ERROR -- : /var/www/good/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/configurator.rb:111:in `block in commit!' E, [2013-03-25T16:55:35.881606 #2378] ERROR -- : /var/www/good/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/configurator.rb:108:in `each' E, [2013-03-25T16:55:35.881645 #2378] ERROR -- : /var/www/good/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/configurator.rb:108:in `commit!' E, [2013-03-25T16:55:35.881674 #2378] ERROR -- : /var/www/good/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:699:in `load_config!' E, [2013-03-25T16:55:35.881703 #2378] ERROR -- : /var/www/good/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:308:in `join' E, [2013-03-25T16:55:35.881731 #2378] ERROR -- : /var/www/good/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/bin/unicorn:126:in `<top (required)>' E, [2013-03-25T16:55:35.881758 #2378] ERROR -- : /var/www/good/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `load' E, [2013-03-25T16:55:35.881786 #2378] ERROR -- : /var/www/good/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `<main>' I, [2013-03-25T16:55:36.233632 #2378] INFO -- : reaped #<Process::Status: pid 2392 exit 0> worker=1 I, [2013-03-25T16:55:36.234045 #2378] INFO -- : reaped #<Process::Status: pid 2397 exit 0> worker=3 I, [2013-03-25T16:55:36.234560 #2378] INFO -- : reaped #<Process::Status: pid 2394 exit 0> worker=2 I, [2013-03-25T16:55:36.336246 #8587] INFO -- : executing ["/var/www/good/shared/bundle/ruby/1.9.1/bin/unicorn", "-c", "/var/www/good/current/config/unicorn.rb", "-E", "production", "-D", {12=>#<Kgio::UNIXServer:fd 12>, 13=>#<Kgio::TCPServer:fd 13>}] (in /var/www/good/releases/20130325165445) I, [2013-03-25T16:55:36.336510 #8587] INFO -- : forked child re-executing... I, [2013-03-25T16:55:38.475972 #2378] INFO -- : reaped #<Process::Status: pid 2389 exit 0> worker=0 I, [2013-03-25T16:55:38.476109 #2378] INFO -- : master complete
keyword
error reload config_file = / var / www / good / current / config / unicorn.rb: Already running on PID: 2378
I have included Gemfile, deploy.rb and unicorn.rb
I would be grateful for any help or thoughts. I also use RVM and ubuntu
configurations /deploy.rb
require "rvm/capistrano" set :rvm_type, :system set :rvm_install_with_sudo, true require "bundler/capistrano" set :bundle_without, [:darwin, :development, :test] set :application, "Talking GOOD" set :repository, " git@github.com :FTW-Development/good.git" set :scm_user, " hunter@ftwdev.com " ssh_options[:forward_agent] = true
configurations /unicorn.rb
app_path = "/var/www/good/current" # Set unicorn options worker_processes 1 preload_app true timeout 180 listen "127.0.0.1:9000" # Spawn unicorn master worker for user apps (group: apps) user 'rails.www' # Fill path to your app working_directory "/var/www/good/current" # 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
Gemfile
source 'https://rubygems.org' gem 'rails', '3.2.8'