I ended up doing something similar to Denis, except used Ruby wrapper per RVM docs. This was really really annoying tbh, but according to top -c
and shift-M
it's working. Written semi-verbose because I hope this helps someone else.
My setup is: Digital Ocean, Ubuntu 14.10, Rails 4.0.x, Ruby 2.0.x, RVM 1.26.10. My Procfile is only for background jobs since I'm using Passenger 5+Nginx. The deploying user is 'rails'. I have a gemset called "ruby-2.0.0-p598@rockin" for my app called "rockin" since I run multiple apps on the box.
Adding in the absolute PATH
to bundle did NOT work for me.
Here's what I did:
Create rvm wrapper per docs. (user is rails)
rvm alias create rockin ruby-2.0.0-p598@rockin
Create .env file for RAILS_ENV and PATH for bundle
RAILS_ENV=production
Attempt to foreman export to upstart
rvmsudo foreman export upstart /etc/init -a rockin -u rails
Decided to tail the logs because of the bundle issue in another window as sanity check. (user is root)
tail -f /var/log/upstart/rockin-worker-1.log
Change the upstart file manually. The file I needed to edit was rockin-worker-1.conf
. Since most of the thing was pretty formatted and had what I needed, I changed the exec lines to truly point to bundle using the wrapper created above.
start on starting rockin-worker
stop on stopping rockin-worker
respawn
env PORT=5000
env RAILS_ENV='production'
setuid rails
chdir /home/rails/rockin
exec /usr/local/rvm/wrappers/rockin/bundle exec rake environment resque:work QUEUE=*
Run it!
sudo start rockin-worker
You can check with the tailed logs, but if you see no output, you're good to go! Then double-check top by doing top -c
and shift-M
. My resque worker started up and went into waiting mode. PERFECT.
This should work for anyone using rvm and other background workers like sidekiq.
To anyone saying PATH would have worked, I tried both which bundle
and whereis bundle
from the root dir of my app and using those paths for the .env file. Neither worked and both resulted in the logs complaining about /bin/sh: 1: exec: bundle: not found
.