Cannot run Unicorn with Ruby 2.0

。_饼干妹妹 提交于 2020-01-02 05:40:43

问题


On my ubuntu machine, I can run unicorn on ruby 1.9.3, however, it does not seem to work with ruby 2.0. Any idea why?

root@dev:/home/karan# rvm use 1.9
Using /usr/local/rvm/gems/ruby-1.9.3-p429
root@dev:/home/karan# unicorn -v
unicorn v4.6.3
root@dev:/home/karan# rvm use 2.0
Using /usr/local/rvm/gems/ruby-2.0.0-p195
root@dev:/home/karan# unicorn -v
/usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- unicorn/launcher (LoadError)
        from /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/bin/unicorn:3:in `<main>'

回答1:


Try reinstalling the gem with 2.0.0.

The problem must have been caused by the fact the gem was installed in 1.9.3.




回答2:


I have the exact same problem when I try to start Unicorn server

Starting Unicorn web server unicorn
/usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- unicorn/launcher (LoadError)
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /usr/bin/unicorn:3:in `<main>'

Nevertheless, Unicorn works fine when I run it from the rails app folder, simply using "unicorn" command.

I have tried what you suggest, installing the gem unicorn

gem install 'unicorn'

But it does not change the result

I check what gem is installed:

which gem 'unicorn'
/usr/local/rvm/rubies/ruby-2.0.0-p353/bin/gem
/usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn

I am running unicorn from a etc/init.d script that you can see here:

http://pastebin.com/qvwdmRJ2

and here for the default configuration:

http://pastebin.com/84FBQjMp

There seems to be some problem with the PATH of the default configuration file:

PATH=/usr/local/rvm/rubies/ruby-2.0.0-p353/bin:/home/unicorn/.rvm/bin:/usr/local/sbin:/usr/bin:/bin:/sbin:$

Because since I updated it with the new installed version I get the error message shown at the top. If I remove it, Unicorn "apparently starts" but the log shows a crazy activity and nginx shows an empty screen.

I am trying to find a solution and will share it here as soon as I find it.

Thanks for your help

* UPDATE *

OK I have found the problems:

1) for the /etc/init.d script:

You need to create a wrapper for Unicorn to work in a init.d type of script:

rvm wrapper 2.0.0 ruby-2.0.0 unicorn

then replace the line

DAEMON=/usr/bin/unicorn

with this one:

DAEMON=/usr/local/rvm/bin/ruby-2.0.0_unicorn

And now the command

service unicorn start

more on rvm wrapper here: https://rvm.io/integration/init-d

2) I also had another issue that was difficult to identify in the log:

I had not created a config/environments/staging.rb file



来源:https://stackoverflow.com/questions/18193506/cannot-run-unicorn-with-ruby-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!