Rails 3 - Whenever gem error: /usr/bin/env: ruby: No such file or directory - ruby-on-rails-3

When using the 'whenever gem', I get an error in the log:
/usr/bin/env: ruby: No such file or directory
It works when I run the job manually. I've installed everything with RVM.
I've used the which command to find where my Ruby installation is, and I get:
kevin#lovely:/opt/personal$ which ruby
/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
and I've checked my $PATH variable, where it returns:
kevin#lovely:/opt/personal$ echo $PATH
/home/kevin/.rvm/gems/ruby-1.9.2-p290/bin:/home/kevin/.rvm/gems/ruby-1.9.2-p290#global/bin:/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin:/home/kevin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
I believe this should be set up right, but I'm probably wrong since it doesn't work. Can anyone point me in the right direction?
If you're interested, this is what my whenever crontab output is:
# Begin Whenever generated tasks for: rss
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /opt/personal && script/rails runner -e development '\''FeedEntry.update_from_feed("http://lovely/blog/feed/")'\'' >> /opt/personal/log/feedzirra.log 2>&1'

You're probably long past this issue but for future reference:
I had a similar problem only I was getting
/usr/bin/env: ruby: No such file or directory
It turned out the first line of the file script\rails was #!/usr/bin/env ruby1.9.1, which tells the system to invoke it with ruby1.9.1 as explained here. But it should have been #!/usr/bin/env ruby1.9.3 since that was the version I had installed.
Hope this helps someone in the future :)

My issue was that ruby is in /usr/local/bin which is not in the path of a headless bash. So I just made my rake task line in schedule.rb:
job_type :rake, "cd :path && PATH=/usr/local/bin:$PATH RAILS_ENV=:environment bundle exec rake :task :output"

I am successfully using whenever with RVM and bundler in production. Here are the relevant pieces of my capistrano setup that may help you:
# rvm and bundler integration
require 'rvm/capistrano'
require 'bundler/capistrano'
# RVM environment
set :rvm_ruby_string, "ruby-1.9.2#mygemset"
# crontab
set :whenever_roles, :cron
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer { stage }
require 'whenever/capistrano'
The :whenever_environment setting is because I am using a multi-stage deployment setup. You can ignore that or set it to a string that matches your setup if needed.
Most of this information can be found at the whenever github page under the "Capistrano integration" and "RVM Integration" section headers in the README.
I hope that helps.

I solved the problem about the same as Duke. Except I figure out that $PATH variable is not working for me.
sys_path = '/home/[user]/.rbenv/versions/[ruby_version]/bin'
job_type :runner, "cd :path && PATH=#{sys_path} bin/rails runner -e :environment ':task' :output"
job_type :rake, "cd :path && PATH=#{sys_path} :environment_variable=:environment bin/bundle exec rake :task --silent :output"

If none of these worked for you, try:
gem install rails
This did the job for me, hope it helps!

Related

Capistrano 3 error when deploy

Following is the debug log,
[a4e2341c] Running /usr/bin/env [ ! -d ~/.rbenv/versions/2.1.0 ] on xxx.xxx.xxx
[a4e2341c] Command: [ ! -d ~/.rbenv/versions/2.1.0 ]
[a4e2341c] Finished in 6.761 seconds with exit status 1 (failed).
what does this failure means? the directory doesn't exist? but it do exist.
also another one,
Running ~/.rbenv/bin/rbenv exec bundle exec rake tmp:cache:clear on www.neonan.com
Command: cd /home/ben/staging/releases/20140305160352 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.0 ~/.rbenv/bin/rbenv exec bundle exec rake tmp:cache:clear )
fatal: Not a git repository (or any parent up to mount point /home)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
what does this mean? help!
I had a similar issue. It looks like one of the gem you are using requires a git command to be run. With capistrano version 3, ".git" folder is no longer kept in releases folder. Instead it uses a folder called "repo".
You should probably fix the gem as a long term solution so that it is not needed.
I worked around the problem by basically adding in a task that copied "repo" folder as ".git" folder under the releases folder.
namespace :deploy do
desc 'Copies .git folder'
task :copy_git do
on roles(:app) do
puts release_path
within release_path do
execute :cp, '-r', repo_path, '.git'
end
end
end
before 'bundler:install', 'deploy:copy_git'
end
#akshah123 thanks for the info. I had this issue deploying via Capistrano 3 to a test area where my solution wasn't ready to be delivered as a packaged gem. The .gemspec file had the following idiom
spec.files = `git ls-files`.split($/)
replaced it with
spec.files = `if [ -d '.git' ]; then git ls-files; fi`.split($/)

apn_sender gem daemon not running

Im using apn_sender for rails 3 and i have been able to install the gem and get it working just fine by using
rake apn:sender
I have tried to get it started in production mode on a ubuntu box by starting the daemon and it does not seem to work. When i type
script/apn_sender --environment=production --verbose start
I dont see anything. No log present.
when i try to type
script/apn_sender status
It returns with
apn_sender: no instances running
Just trying to understand why it is not running.
i just solved this problem. Try to create a file called 'script' in generators/apn_sender/templates . .
Put this in your script file
# !/usr/bin/env ruby
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require 'rubygems'
require 'apn'
require 'apn/sender_daemon'
APN::SenderDaemon.new(ARGV).daemonize
bash 'rails g apn_sender' in your terminal and will create 'script/apn_server' with same content as above
After that bash this code
./script/apn_server --environment=production --verbose start
it will create log/apn_sender.log . Try running
APN.notify('token',{:alert => '#' , :badge => 1})
or else in rails c to confirm if it works or not , and of course
rake apn:sender
Hope it will help :)
EDIT
You have to install redis and configure

git-push and rvm issues

I'm just starting to use git-deploy instead of capistrano, the problem is though that I'm using rvm on my server and the two are not mixing well.
Here is a link to the git-deploy which I'm using:
https://github.com/mislav/git-deploy
I'm using ruby 1.9.2-p180 on my server installed through rvm for the user. When I run my git push and git deploy runs my scripts in the deploy it installs the gems in vendor/.bundle instead of my gems directory: /home/vps/.rvm/gems
Here is my deploy/after_push script
#!/usr/bin/env bash
set -e
oldrev=$1
newrev=$2
run() {
[ -x $1 ] && $1 $oldrev $newrev
}
echo files changed: $(git diff $oldrev $newrev --diff-filter=ACDMR --name-only | wc -l)
umask 002
git submodule init && git submodule sync && git submodule update
export GEM_HOME=/home/vps/.rvm/gems/ruby-1.9.2-p180
export MY_RUBY_HOME=/home/vps/.rvm/rubies/ruby-1.9.2-p180
export GEM_PATH=/home/vps/.rvm/gems/ruby-1.9.2-p180:/home/vps/.rvm/gems/ruby-1.9.2-p180#global
export RUBY_VERSION=ruby-1.9.2-p180
export PATH=/home/vps/.rvm/gems/ruby-1.9.2-p180/bin:/home/vps/.rvm/gems/ruby-1.9.2-p180#global/bin:/home/vps/.rvm/rubies/ruby-1.9.2-p180/bin:/home/vps/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
export rvm_config_path=/home/vps/.rvm/config
export rvm_path=/home/vps/.rvm
export rvm_examples_path=/home/vps/.rvm/examples
export rvm_rubies_path=/home/vps/.rvm/rubies
export rvm_usr_path=/home/vps/.rvm/usr
export rvm_src_path=/home/vps/.rvm/src
export rvm_version=1.6.3
export rvm_gems_path=/home/vps/.rvm/gems
export rvm_ruby_string=ruby-1.9.2-p180
export rvm_tmp_path=/home/vps/.rvm/tmp
export rvm_lib_path=/home/vps/.rvm/lib
export rvm_repos_path=/home/vps/.rvm/repos
export rvm_log_path=/home/vps/.rvm/log
export rvm_help_path=/home/vps/.rvm/help
export rvm_environments_path=/home/vps/.rvm/environments
export rvm_archives_path=/home/vps/.rvm/archives
rvm use 1.9.2
run deploy/before_restart
run deploy/restart && run deploy/after_restart
Here is my deploy/before_restart
#!/home/vps/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
oldrev, newrev = ARGV
def run(cmd)
exit($?.exitstatus) unless system "umask 002 && #{cmd}"
end
RAILS_ENV = ENV['RAILS_ENV'] || 'production'
use_bundler = File.file? 'Gemfile'
rake_cmd = use_bundler ? 'bundle exec rake' : 'rake'
if use_bundler
bundler_args = ['--deployment']
BUNDLE_WITHOUT = ENV['BUNDLE_WITHOUT'] || 'development:test'
bundler_args << '--without' << BUNDLE_WITHOUT unless BUNDLE_WITHOUT.empty?
# update gem bundle
run "bundle install #{bundler_args.join(' ')}"
end
if File.file? 'Rakefile'
num_migrations = `git diff #{oldrev} #{newrev} --diff-filter=A --name-only`.split("\n").size
# run migrations if new ones have been added
run "#{rake_cmd} db:migrate RAILS_ENV=#{RAILS_ENV}" if num_migrations > 0
end
# clear cached assets (unversioned/ignored files)
run "git clean -x -f -- public/stylesheets public/javascripts"
# clean unversioned files from vendor/plugins (e.g. old submodules)
run "git clean -d -f -- vendor/plugins"
Not only does it install it in vendor/.bundle but it installs it for the system version of ruby which is 1.9.1 so I cannot use it with my rvm version which is what apache2 is running. My current work around for all this is to manually ssh in and run bundle install in that directory.
Is there a cleaner way of doing this?
Do I have to have all those exports in my script file?
Update:
Even when I manually go into the directory and run bundle install it puts the gems into vendor/bundle for some reason.
Update:
After entering the following in my before_restart
run "ruby -v"
run "type ruby"
I get this result:
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
ruby is /home/vps/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
I've taken out the bundler_args, but it still insists on installing my gems in vendor/bundle for ruby 1.9.1
Running bundle install --deloyment intentionally places gems in the vendor directory.
It's pretty unlikely that you actually have Ruby 1.9.1 installed. If you are using a Debian-derived distribution then it's because the package is misnamed as 1.9.1 when it actually installs 1.9.2.
Otherwise I'm not really sure why your rvm use 1.9.2 line would not be taking effect. Do run "ruby -v" perhaps in the before_restart script and check the version or run "type ruby" to check its path.

running delayed_job under monit with ubuntu

I'm struggling to get delayed_job working under rails 3.0.9 (ruby 1.9.2). The only way I have succeeded to run is to tape manualy the command rake jobs:work.
But I want that to be automatically started when the rails application is starting.
I have installed monit under ubuntu and I configured it to launch a file located in my app. This fails looks like:
check process delayed_job with pidfile /home/me/myapp/tmp/pids/delayed_job.pid
start program = "/home/me/myapp/script/delayed_job start"
stop program = "/home/me/myapp/script/delayed_job stop"
And I added the environment setting in the delayed_job script file:
#!/usr/bin/env ruby
ENV['RAILS_ENV'] = "development"
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize
When I run the command "sudo monit start delayed_job" I get the following error:
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- bundler/setup (LoadError)
So I guess it is because sudo is using a wrong version of ruby environment
I tried then the solution of:
rvm monit delayed_job
by adding rvm -S in the start program / stop program lines.
But it still failing with the error : rvm command not found
my rvm dir is located in my home dir /home/me/.rvm
I tried to find workarounds in (sudo changes PATH - why?) to change the PATH environment variable by adding
/usr/bin/env PATH=/home/me/.rvm/bin:$PATH
The command "sudo monit start delayed_job" succeeded! and the worker started.
But the issue is: When I launch sudo /etc/init.d/monit start and when I look to the syslog I still get 'delayed_job' failed to start
So I don't know how to investigate more, how to get more verbose errors for monit.
I have finally succeeded to solve this issue.
I modified the monit file like this:
check process delayed_job with pidfile /home/me/myapp/tmp/pids/delayed_job.pid
start program = "/bin/su - me -c 'cd /home/me/myapp/; script/delayed_job start'"
stop program = "/bin/su - me -c 'cd /home/me/myapp/; script/delayed_job stop'"
I have also downgraded the daemons gem because it seems that there are problems with the latest version. So I'm using now daemons v 1.0.10
I also modified the rights of the log file /home/me/myapp/log/delayed_job.log, because it seems that is was created before my root and my user had no access to it (I had problems to test the command "script/delayed_job start" with "me" user)
This i s the only line that worked for me that read the ENV properly
start program = "/usr/local/rvm/bin/rvm-shell -c 'cd /var/www/[APP]/current/; RAILS_ENV=production bundle exec bin/delayed_job start'"
Hope it helps!

rake aborted! no such file to load -- bundler/setup

I run a rake task every night via cron (as root), when it runs it gives the error:
rake aborted!
no such file to load -- bundler/setup
which I get in an email
When I run it manually (as root), it runs just fine.
I am running rvm if that helps.
I am not really sure what to add to help, but here are a few things.
# ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
# rails -v
Rails 3.0.9
# gem -v
1.8.5
try to set up your cron task like this
* * * * * /bin/bash -l -c 'rake blah:blah'