I'm in the process of writing a Ruby-based daemon to sit and run on one of my Ubuntu servers. I'll be wanting this to run on startup, so will be writing an upstart job file for it. However, I've used bundler for managing the various gems it uses and intend to do this after deploying it to the server:
bundle install --deployment
This puts bundler into the so-called 'deployment mode', whereby various options are set and all the gems are installed into a 'vendor' directory rather than system-wide. However this creates a problem with running it, whereby it must be executed from its own directory as this is where the gems end up:
<in the app's dir>
$ ./runmyapp
<it runs>
If I cd
to a different location and then try to run it using it's full path, it fails:
<in another directory>
$ /path/to/runmyapp
<it crashes as it can't locate its gems>
I've read through lots of bundler documentation and this entire scenario is never even covered? Should I just install the gems to the system instead? Is there something else I ought to do?
You use bundler as gem manager for your app. I think in this case using bundle exec
is the best way to run executables.
If you run your app from different directory than directory that contains Gemfile you should set Gemfile location by setting BUNDLE_GEMFILE (see bundle help exec
). Following will help you:
BUNDLE_GEMFILE=/path/to/Gemfile bundle exec /path/to/runmyapp