简体   繁体   中英

Rails Unicorn init script not executing. Says Ruby can't be found

Having trouble getting unicorn to run as a service. when I call "sudo service unicorn restart", I get the error below.

If I call '/var/www/mysite/bin/unicorn -D -c /var/www/mysite/config/unicorn.rb -E production' from the app's root directory, it runs just fine. And I can even call "sudo service unicorn restart" after that just fine.

Any help is much appreciated!

ubuntu@ip:$ sudo service unicorn restart
Couldn't reload, starting '/var/www/mysite/bin/unicorn -D -c /var/www/mysite/config/unicorn.rb -E production' instead
/usr/bin/env: ruby: No such file or directory

Here's the terminal output to show which ruby the system is using.

ubuntu@ip:$ which ruby
/home/ubuntu/.rbenv/shims/ruby

I'm running on Ubuntu 12.04. Rails 4, Ruby 2.1 and nginx

I had the same issue, but I was using rbenv installed on per user basis. I used this init script

I figured out that since my rbenv installed on per user basis I need to slightly change this:

CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"

with this:

CMD="cd $APP_ROOT; ~/.rbenv/bin/rbenv exec bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"

Hope it will help you!

Your problem is that your rbenv installation is only loaded for the ubuntu user, but you're running unicorn as root.

You might want to install rbenv for your root user, or install it globally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM