【发布时间】:2015-11-05 05:55:25
【问题描述】:
我正在尝试在 Ubuntu 启动时启动 rails 应用程序。
为此,我在/etc/rc.local 中添加了这些行。
cd /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
bundle exec passenger start --port 8000 --user ubuntu --daemonize
但是,rc.local 退出并出现错误
+ cd /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
+ bundle exec passenger start --port 8000 --user ubuntu --daemonize
/usr/lib/ruby/vendor_ruby/bundler/spec_set.rb:92:in `block in materialize': Could not find rake-10.4.2 in any of the sources (Bundler::GemNotFound)
from /usr/lib/ruby/vendor_ruby/bundler/spec_set.rb:85:in `map!'
from /usr/lib/ruby/vendor_ruby/bundler/spec_set.rb:85:in `materialize'
from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:114:in `specs'
from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:159:in `specs_for'
from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:148:in `requested_specs'
from /usr/lib/ruby/vendor_ruby/bundler/environment.rb:18:in `requested_specs'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:13:in `setup'
from /usr/lib/ruby/vendor_ruby/bundler.rb:120:in `setup'
from /usr/lib/ruby/vendor_ruby/bundler/setup.rb:17:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
该错误是由于使用从 rbenv 安装的 ruby 引起的;红宝石位于 /home/ubuntu/.rbenv/bin/ 目录中。我猜当 ubuntu 启动时,系统 ruby 被执行了,但是它对使用 rbenv 的 ruby 和 gem 安装的包一无所知。
我该如何解决这个问题?有没有办法让 rbenv 中的 ruby 成为系统的 ruby?
为了得到错误,我使用了这篇文章中的提示:Run script with rc.local: script works, but not at boot。
编辑
mwp 的回答很好,但我想我最好把事情说清楚。
开发包
运行bundle --deployment --binstubs创建./vendor并复制bundle目录下的文件。
setup.sh
#!/bin/bash
export APP_ROOT="/home/ubuntu/webapp/rails/passenger-ruby-rails-demo"
export APP_USER="ubuntu"
export APP_PORT="8000"
export RBENV_ROOT="/home/ubuntu/.rbenv"
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"
# Assuming you installed bundle with --binstubs...
$APP_ROOT/bin/passenger start --port $APP_PORT --user $APP_USER --daemonize
rc.local 文件
cd /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
sh ./setup.sh
exit 0
【问题讨论】:
-
仅供参考,
rbenv init将为您将shims添加到PATH。并且像我一样引用APP_ROOT变量是为了防止包含空格的目录路径。无论如何,我很高兴你找到了一个满意的解决方案!
标签: ruby-on-rails ruby ubuntu rbenv