Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreman rvm upstart not work

Unicorn not runs by upstart script.

rvm 1.25.23 ruby 2.1.1 Rails 4.1

config/deploy.rb

  desc 'Foreman init'
  task :foreman_init do
    on roles(:all) do
      foreman_temp = "/home/deployer/tmp/foreman"
      execute  "mkdir -p #{foreman_temp}"
      execute "ln -s #{release_path} #{current_path}"
      within current_path do
        execute "cd #{current_path}"
        execute :bundle, "exec foreman export upstart #{foreman_temp} -a #{application} -u deployer -l /home/deployer/apps/#{application}/log -d #{current_path}"
      end
      sudo "mv #{foreman_temp}/* /etc/init/"
      sudo "rm -r #{foreman_temp}"
    end
  end

/etc/init/depl-web-1.conf

start on starting depl-web
stop on stopping depl-web
respawn

env PORT=5000

setuid deployer

chdir /home/deployer/apps/depl/current

exec bundle exec unicorn_rails -c /home/deployer/apps/depl/current/config/unicorn.rb -E production

/log/upstart/depl-web-1.log and production.log clear

if you go to the application's directory and manually run the command

bundle exec unicorn_rails -c /home/deployer/apps/depl/current/config/unicorn.rb -E production

Unicorn successfully launched.

If in /etc/init/depl-web-1.conf exec line add port

exec bundle exec unicorn_rails -p $PORT -c

/home/deployer/apps/depl/current/config/unicorn.rb -E production

error:

/bin/sh: 1: exec: bundle: not found

i use rvm

which bundle
/home/deployer/.rvm/gems/ruby-2.1.1/bin/bundle
which rvm
/home/deployer/.rvm/bin/rvm
like image 444
Denis Avatar asked Apr 26 '14 06:04

Denis


2 Answers

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:

  1. Create rvm wrapper per docs. (user is rails)

    rvm alias create rockin ruby-2.0.0-p598@rockin
    
  2. Create .env file for RAILS_ENV and PATH for bundle

    RAILS_ENV=production 
    
  3. Attempt to foreman export to upstart

    rvmsudo foreman export upstart /etc/init -a rockin -u rails
    
  4. 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
    
  5. 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=*
    
  6. Run it!

    sudo start rockin-worker 
    
  7. 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.

like image 174
risa_risa Avatar answered Sep 18 '22 08:09

risa_risa


I manually edited.

start on starting depl-web
stop on stopping depl-web
respawn

env PORT=5000
env RVM_SHELL=/home/deployer/.rvm/bin/rvm-shell
env RUBY_VERSION="2.1.5"
setuid deployer
script
chdir /home/deployer/apps/depl/current
$RVM_SHELL $RUBY_VERSION -c 'bundle exec unicorn_rails -c /home/deployer/apps/depl/current/config/unicorn.rb -E production'
end script
like image 23
Denis Avatar answered Sep 20 '22 08:09

Denis