Search code examples
ruby-on-railsunicorn

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


Solution

  • 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.