(CRON) error (grandchild #26321 failed with exit status 127) - ruby-on-rails

I am using whenever gem my schedule.rb content is
every 2.minutes do runner
"Refinery::Page.update_publishing_date_to_list_in_menu" end
I get this by crontab -l
# Begin Whenever generated tasks for: /home/harssh/Documents/Aptana Studio 3 Workspacwinbox/wineboxnew/config/schedule.rb
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58
* * * * /bin/bash -l -c 'cd /home/harssh/Documents/Aptana\ Studio\ 3\ Workspacwinbox/wineboxnew && RAILS_ENV=production bundle exec rake page:publish --silent'
# End Whenever generated tasks for: /home/harssh/Documents/Aptana Studio 3 Workspacwinbox/wineboxnew/config/schedule.rb
This runs well on my ubuntu 10.10
But I get (CRON) error (grandchild #26321 failed with exit status 127) on my debian server
where I am using apache and passenger with rvm using Ruby 1.9.3
If I use script in terminal in debian it also runs properly but automated cron task gives error

I am also faced same problem, Finally I resolved this issue.
Problem 1: Ruby path in script/runner file
ruby path in script/runner file:
#!/usr/local/bin/ruby
You can replace (/usr/local/bin/ruby) with your machine ruby path. You can check ruby path with the following command in your machine:
which ruby
Problem 2: I think your runner don't have execution permission.
You can set execution permission to runner file the following way:
Ruby project path/script> chmod +x ruuner

Related

AppEngine Flexible Ruby environment, application startup error: /usr/bin/env: 'ruby2.5': No such file or directory

I'm trying to deploy an API-only Rails 5 application to AppEngine Flex w/ the standard Ruby runtime, and I'm getting the following error at the very end:
Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
/usr/bin/env: 'ruby2.5': No such file or directory
I'm specifying ruby '2.5.1' in my Gemfile and I've added an explicit .ruby-version file to the root of my project set to 2.5.1 as well.
I have no other debugging information available to me in the logs, no other fancieness. My entrypoint command is:
bundle exec rails server Puma -p $PORT
I can provide more details if needed, not sure what else might be relevant. Any pointers? As far as I can tell, nothing on my side is asking for a version of ruby that specifically at execution time.
Thanks!
EDIT: Here's my app.yaml file
entrypoint: bundle exec rails server Puma -p $PORT
env: flex
runtime: ruby
UPDATE:
I can verify that I'm having similar problems when trying to exec rake tasks like db:migrate:
--------- EXECUTE COMMAND ----------
bundle exec rake db:migrate
/usr/bin/env: 'ruby2.5': No such file or directory
ERROR
ERROR: build step 0 "gcr.io/google-appengine/exec-wrapper:latest" failed: exit status 127
--------------------------------------------------------------------------------------------------------------------------------------------------------
OK I now see what has happened after debugging the docker image locally. Because I was on ubuntu and had used system ruby to install gems it had embedded /usr/bin/env ruby2.5 into every executable script that was bundled into my app. I deleted all gems and switched to rbenv for managing Ruby version which mitigated this odd behavior between unbuntu's ruby and my app.

Can't execute Rails rake task with cron

I'm trying to run rake task with cron on Ubuntu with rvm
My crontab -l
* * * * * cd /media/sf_visa-tracker/ && /home/ruslan/.rvm/gems/ruby-2.1.0/bin/rake parse RAILS_ENV=production >> /var/log/visa-parse.log 2>&1
which rake says
/home/ruslan/.rvm/gems/ruby-2.1.0/bin/rake
And I keep getting this error in my log (/var/log/visa-parse.log)
/usr/bin/env: ruby_executable_hooks: No such file or directory
Also, if I run cd /media/sf_visa-tracker/ && /home/ruslan/.rvm/gems/ruby-2.1.0/bin/rake parse RAILS_ENV=production from my terminal, rake task works.
Pls help ;)
The simplest way to use rvm with cron is to use rvm's wrappers. Your shell sets up a whole bunch of rvm-related environment when it starts, and that's missing from your cron job. The wrappers are versions of the Ruby-related commands that take care of this for you.
In this case, if you have rvm installed to /usr/local, your cron job should look something like this:
* * * * * cd /media/sf_visa-tracker/ && /usr/local/rvm/wrappers/ruby-2.1.0/bin/rake parse RAILS_ENV=production >> /var/log/visa-parse.log 2>&1
You could also bundle up your rvm setup into a shell script that loads rvm before invoking rake; there's more details of both approaches in rvm's documentation on working with cron.
I struggled to get something that worked and seemed clean. Here's what I ended up doing in case it helps.
crontab
0 5 * * * /home/deploy/apps/myproject/shared/cron/daily_updates.sh
I put the script in myproject/shared since I'm using Capistrano and that seemed like a good place for things that would persist between releases.
shared/cron/daily_updates.sh
#!/usr/bin/env bash
# You will need to update this as you bump ruby versions
source /home/deploy/.rvm/environments/ruby-2.3.1#myproject
# Since I had a separate place for Rails specific environment variables (e.g. secrets, app keys)
# you should set the permissions on that file to be owner read/write only
source /home/deploy/.rails_env
cd /home/deploy/apps/myproject/current
rake RAILS_ENV=production daily_update:send_updates 2>&1

Cron + whenever not working with RVM

I am using RVM environment. RUby version : 2.1.2 rails : 4.1.1
schedule.rb :
every 1.minute do
runner "note.send_mail"
end
I used whenever --update-crontab to update the cron tab.
when I check the jobs using crontab -l it shows up as below with no proper time set up.
and the cron job does not work.
* * * * * /bin/bash -l -c 'cd /Desktop/folder1/blog2 && bin/rails runner -e production '\''note.send_mail'\'''
Can some one help me out fix this. Thanks!
Go to your ~/.rvmrc file and add the following:
rvm_trust_rvmrcs_flag=1
Then whenever --update-crontab again. According to the README of whenever:
If your production environment uses RVM (Ruby Version Manager) you will run into a gotcha that causes your cron jobs to hang. This is not directly related to Whenever, and can be tricky to debug. Your .rvmrc files must be trusted or else the cron jobs will hang waiting for the file to be trusted. A solution is to disable the prompt by adding this line to your user rvm file in ~/.rvmrc
rvm_trust_rvmrcs_flag=1
This tells rvm to trust all rvmrc files.
If that doesn't work for you, try other solutions mentioned in this page: RVM-Notes.
You could define a custom runner that loads rvm on the command line, like
job_type :runner_with_rvm, 'source /etc/profile.d/rvm.sh; cd :path;rvm 2.0#gemset do bundle exec script/rails runner -e :environment ':task' :output'
every 1.minute do
runner_with_rvm "Note.send_email"
end
Replace 2.0#gemset with your desired ruby version and gemset.
Could be that /etc/profile.d/rvm.sh is something else in your environment too.

Cron to trigger a Rails Rake in DigitalOcean?

I have a rake task that I'd like to schedule a cron to run. My Rails 4 project is hosted on a DigitalOcean droplet is running Ubuntu 12.10 (Nginx + Unicorn).
Here's what I have in crontab:
SHELL=/bin/bash
PATH=/sbin:/bin/usr/bin
HOME=/
MAILTO="xxx#gmail.com"
* * * * * /bin/bash -l -c 'source ~/.bash_profile && cd /home/rails && RAILS_ENV=production bin/rake populate:fetch_nr_songs'
However I get this error:
/etc/profile.d/rvm.sh: line 9: ps: command not found
/etc/profile.d/rvm.sh: line 10: ps: command not found
/usr/local/rvm/scripts/rvm: line 96: dirname: command not found
ERROR: Missing proper 'which' command. Make sure it is installed before using RVM!
Any fix would be much appreciated thanks
Seems like somethings wrong with RVM installation. Try re-installing it https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-ubuntu-12-04-lts-precise-pangolin-with-rvm
Note: you can effortlessly manage crontab using whenever

Capistrano custom task fails because "Rails requires RubyGems >= 1.3.2"

My custom capistrano task "app:sample" fails with the following error message:
mnylen ilmo-on-rails $ cap app:sample
* executing `app:sample'
* executing "export RAILS_ENV=production; cd /home/mnylen/ilmo-on-rails/current; ruby script/coursegen 10"
servers: ["rails.cs.helsinki.fi"]
* establishing connection to gateway `melkinpaasi.cs.helsinki.fi'
* Creating gateway using melkinpaasi.cs.helsinki.fi
* establishing connection to `rails.cs.helsinki.fi' via gateway
Password:
[rails.cs.helsinki.fi] executing command
*** [err :: rails.cs.helsinki.fi] Rails requires RubyGems >= 1.3.2. Please install RubyGems and try again: http://rubygems.rubyforge.org
command finished
failed: "sh -c 'export RAILS_ENV=production; cd /home/mnylen/ilmo-on-rails/current; ruby script/coursegen 10'" on rails.cs.helsinki.fi
Am I missing something or doing something wrong? The task is:
namespace :app do
desc "Run sample data on production2
task :sample do
run "export RAILS_ENV=production; cd #{current_path}; ruby script/coursegen 10"
end
end
If I run the same command from the actual server, it works fine.
Cap is running the remote command as an unexpected user - and that user does not have the correct path to ruby and gem. Check your settings in your recipe for :user and :use_sudo. Carefully read the cap output to see what user is being connected. I see you are using a :gateway; there can be two users in this case. One to connect to the gateway, and another to actually run commands on the target server.
Okay, solved.
The problem was that there was two Ruby installations on the production server.
The .profile file under my home directory on the production server set the PATH environment variable to point to the correct Ruby version.
run command, it seems, doesn't source the .profile file and thus, running ruby script/coursegen 10 in the task used the wrong Ruby version, which was the reason for the weird error message about RubyGems version. This also explains why it worked when manually running the command from production servers shell.
My solution was to use full path to the Ruby executable in my run task, like this:
run "export RAILS_ENV=production; cd #{current_path}; /opt/ruby-enterprise-1.8.7-2009.10/bin/ruby script/coursegen 10"
Of course, this isn't pretty, but it works. If anyone has any prettier solutions, I'd be more than glad to use those instead. :)
Seems like you should update your RubyGems on the remote server.

Resources