简体   繁体   English

Rails Unicorn初始化脚本未执行。 说找不到Ruby

[英]Rails Unicorn init script not executing. Says Ruby can't be found

Having trouble getting unicorn to run as a service. 无法让独角兽作为服务运行。 when I call "sudo service unicorn restart", I get the error below. 当我调用“ sudo服务独角兽重启”时,出现以下错误。

If I call '/var/www/mysite/bin/unicorn -D -c /var/www/mysite/config/unicorn.rb -E production' from the app's root directory, it runs just fine. 如果我从应用程序的根目录中调用“ / var / www / mysite / bin / unicorn -D -c /var/www/mysite/config/unicorn.rb -E production”,它将运行良好。 And I can even call "sudo service unicorn restart" after that just fine. 在那之后,我什至可以叫“ sudo服务独角兽重启”。

Any help is much appreciated! 任何帮助深表感谢!

ubuntu@ip:$ sudo service unicorn restart
Couldn't reload, starting '/var/www/mysite/bin/unicorn -D -c /var/www/mysite/config/unicorn.rb -E production' instead
/usr/bin/env: ruby: No such file or directory

Here's the terminal output to show which ruby the system is using. 这是终端输出,显示系统正在使用哪个红宝石。

ubuntu@ip:$ which ruby
/home/ubuntu/.rbenv/shims/ruby

I'm running on Ubuntu 12.04. 我在Ubuntu 12.04上运行。 Rails 4, Ruby 2.1 and nginx Rails 4,Ruby 2.1和Nginx

I had the same issue, but I was using rbenv installed on per user basis. 我遇到了同样的问题,但是我正在使用按用户安装的rbenv。 I used this init script 我用了这个初始化脚本

I figured out that since my rbenv installed on per user basis I need to slightly change this: 我发现由于我的rbenv是按用户安装的,因此我需要对此稍作更改:

CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"

with this: 有了这个:

CMD="cd $APP_ROOT; ~/.rbenv/bin/rbenv exec bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"

Hope it will help you! 希望对您有帮助!

Your problem is that your rbenv installation is only loaded for the ubuntu user, but you're running unicorn as root. 您的问题是您的rbenv安装仅为ubuntu用户加载,但您以root身份运行unicorn。

You might want to install rbenv for your root user, or install it globally. 您可能要为root用户安装rbenv,或在全局安装它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM