I'm trying to start the rails app when Ubuntu starts up.
For this, I added these lines in /etc/rc.local
.
cd /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
bundle exec passenger start --port 8000 --user ubuntu --daemonize
However, the rc.local
exits with error
+ 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'
The error is caused from using the ruby installed from rbenv; the ruby is in /home/ubuntu/.rbenv/bin/ directory. I guess when ubuntu starts up, the system ruby is executed, but it does not know anything about installed packges with rbenv's ruby and gem.
How can I solve this issue? Is there any way to make the ruby from rbenv as system's ruby?
For getting the error, I used the hints from this post: Run script with rc.local: script works, but not at boot.
EDIT
mwp's answer works fine, but I think I'd better make things clearer.
development bundle
Run bundle --deployment --binstubs
to create ./vendor and copy files in bundle directory.
The 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
The rc.local file
cd /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
sh ./setup.sh
exit 0