2
votes

Guys I'm trying to restart my unicorn service and seems it get stuck on this

[2019-03-06T20:45:05.938802 #7614] INFO -- : Refreshing Gem list

/usr/local/rvm/gems/ruby-2.5.1@citius_artis/gems/unicorn-5.5.0/lib/unicorn.rb:49:in

`block in builder': wrong number of arguments (given 0, expected 2) (ArgumentError)

Did not change anything on gemfile

If I run rails s -e staging the rails starts normally

Any ideas?

My unicorn.rb config

APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))

# puts "APP ROOT ->>> #{APP_ROOT}"

if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
  begin
    rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
    # puts "RUBY HOME ->>> #{rvm_path}"
    rvm_lib_path = File.join(rvm_path, 'lib')
    # $LOAD_PATH.unshift rvm_lib_path
    # require 'rvm'
    # RVM.use_from_path! APP_ROOT
  rescue LoadError
    raise "RVM ruby lib is currently unavailable."
  end
end

ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'

if ENV['RAILS_ENV'] == 'production'
  worker_processes 2
else
  worker_processes 2
end

working_directory APP_ROOT

preload_app true

timeout 60

listen APP_ROOT + "/tmp/sockets/unicorn.sock", :backlog => 64

pid APP_ROOT + "/tmp/pids/unicorn.pid"

stderr_path APP_ROOT + "/log/unicorn.stderr.log"
stdout_path APP_ROOT + "/log/unicorn.stdout.log"

before_fork do |server, worker|
  # puts "SERVER ->>> #{server}"

  defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect!

  old_pid = APP_ROOT + '/tmp/pids/unicorn.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
      # puts "Old master alerady dead"
    end
  end
end

after_fork do |server, worker|
  if defined?(ActiveRecord::Base)
    config = ActiveRecord::Base.configurations[Rails.env] || Rails.application.config.database_configuration[Rails.env]
    config['pool'] = ENV["DB_POOL"] || ENV['RAILS_MAX_THREADS'] || 5

    ActiveRecord::Base.establish_connection(config)
  end
end
2
try downgrading to 5.4 - John Smith
Could you upload your unicorn config code? - H Dox
updated it @HDox - Pedro Sturmer
updated @FailingCoder - Pedro Sturmer
Is it a bug in the updated unicorns or was something deprecated? - jjcf89

2 Answers

4
votes

Looks like there was a bug introduced in 5.5.0 https://bogomips.org/unicorn-public/20190307022859.mxz7m3mbspujo4c2@dcvr/

I tested his patched version and it works:

Set unicorn version in Gemfile

gem "unicorn", "~> 5.5.0.1.g6836"

And ran bundle update unicorn

3
votes

I was having the same problem and following John Smith's advice this worked for me:

bundle exec gem list | grep unicorn # returns unicorn (5.5.0)

change Gemfile to gem 'unicorn', '5.4.1'

bundle install

bundle exec gem list | grep unicorn # returns unicorn (5.4.1)

Then I was able to restart unicorn without error