bundle exec fails when called from an init.d script

July 3, 2017 688 views
Ruby on Rails Ubuntu

I am trying to set up my server to use chruby to manage rubies and have unicorn started from a rails app bundle.

service unicorn start works fine from a shell. /etc/init.d/unicorn is calling a chruby wrapper for unicorn that calls bundle exec unicorn.

During the init process, bundle exec fails unable to "re-resolve" dependencies before running unicorn. It appears that it can't contact the gem sources to resolve things.

Can this be disabled or worked around somehow?

The message is:

Found changes from the lockfile, re-resolving dependencies because bundler is unlocking Could not find gem 'blah' in any of the gem sources listed in your Gemfile.

Any pointers would be greatly appreciated. Thanks.

1 comment
3 Answers
  • The gems are all installed already and everything works if I manually start unicorn.

    However this twigged a suspicion that the boot process couldn't find them. I had .bundle/config set with an bundle install path for the user. However, I think this path was not being found/read during boot.

    I added the appropriate lines to .bundle/config in the app itself and re bundled. It now works.

Adding BUNDLE_PATH directly to the app's .bundle/config and re bundling, appears to have fixed the issue.

Have another answer? Share your knowledge.