Rails cron whenever, bundle: command not found

后端 未结 13 1496
星月不相逢
星月不相逢 2020-12-04 17:57

I am trying to use whenever to execute a rake task onces a day. Im getting this error

/bin/bash: bundle: command not found
/home/app/.rvm/rubies/ruby-1.9.2-p         


        
相关标签:
13条回答
  • 2020-12-04 18:17

    By executing a command that way: /bin/bash -l -c

    You are launching a bash command as a login shell which is going to source (execute) /etc/profile bash file as a setup file. By doing so, if you check this file, it might have bash command lines that erase your previous $PATH which you do not want to since it contains your path to your bundle and all your other commands in the first place.

    To fix this issue you just have to remove the lines related to set up the $PATH variable in your /etc/profile file.

    0 讨论(0)
  • 2020-12-04 18:18

    I think you should try explicitly setting the GEM_HOME and GEM_PATH environment variables in your crontab. You could also try running something like gem list --local or gem environment through cron and checking the output.

    0 讨论(0)
  • 2020-12-04 18:19

    This is a ENV['PATH'] not set issue. The most elegant way to fix this is to append the rvm related scripts to the path right after the install. Add the following lines to beginning of .bashrc ( beginning and not end as when .bashrc is accessed by a non-interactive shell, the line [ -z "$PS1" ] && return throws error and the subsequent lines are not executed.

    PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
    

    and not try to explicitly set PATH and sully environment variables.

    0 讨论(0)
  • 2020-12-04 18:21

    I played around with this all afternoon and couldn't find a better solution. Here is what I have come up with

    bundle install --binstubs
    

    and then run

    bin/rake daily:stats
    
    0 讨论(0)
  • 2020-12-04 18:28

    I hate this problem - I've spent hours trying to solve it too.

    What works for me is to add

    RAILS_ENV=production; source /usr/local/rvm/scripts/rvm;
    

    before the bundle command.

    0 讨论(0)
  • 2020-12-04 18:28

    For modern fix, add this line in capistrano deploy.rb,

    set :whenever_command, "bundle exec whenever"
    
    0 讨论(0)
提交回复
热议问题