当gem没有执行任务时

时间:2021-07-08 08:01:47

I set up a rails project to use the Whenever gem. Now I deploy my project with Capistrano and the tasks are nicely added to crontab list. But when I see only one line:

我建立了一个rails项目来使用这个gem。现在我用Capistrano部署我的项目,这些任务很好地添加到crontab列表中。但当我只看到一行:

/bin/bash: bundle: command not found

So I read a couple of articles online so I added this on top of my schedule.rb file

我在网上读了几篇文章,所以我把它加在了我的课程表上。rb文件

env 'PATH', ENV['PATH']

So you should think problem solved, because this will add this next line to the crontab:

所以你应该认为问题已经解决了,因为这将为crontab添加下一行:

PATH=/var/rails/alfa_paints/shared/bundle/ruby/1.9.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

So you should think bundle is in the path when the command gets executed. But still no luck. I ran the command and the deployment with a seperate user. So to make sure everything runs with that user, deployer in this case. I asssumed the role of deployer and ran the command as specified in crontab. I didn't experience any problems when executing this command.

因此,当命令执行时,您应该认为bundle位于路径中。但是仍然没有运气。我使用一个独立的用户运行命令和部署。为了确保所有东西都能运行,在这个例子中是部署者。我分析了部署人员的角色,并按照crontab中指定的方式运行命令。执行此命令时,我没有遇到任何问题。

I'm running out of options and was wondering if anybody else experienced this strange behavior? I'm hoping for some advise. This is the output in my crontab:

我已经没有选择的余地了,我想知道是否还有其他人经历过这种奇怪的行为?我希望得到一些建议。这是我的crontab的输出:

# Begin Whenever generated tasks for: alfa_paints
 PATH=/var/rails/alfa_paints/shared/bundle/ruby/1.9.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

0 1 * * * /bin/bash -l -c 'cd /var/rails/alfa_paints/releases/20130127192223 && RAILS_ENV=production bundle exec rake alfa:cleanup --silent >> /var/rails/alfa_paints/shared/log/whenever.log 2>&1'

# End Whenever generated tasks for: alfa_paints

Any help welkom!

任何帮助welkom !

2 个解决方案

#1


1  

You'll need to pass in the necessary environment variables in crontab.

您需要在crontab中传递必要的环境变量。

Add these lines at the top of your crontab (crontab -e)

在你的crontab (crontab -e)的顶部添加这些线条

(obviously you'll modify the values of the variables to represent those in your environment)

(显然,您将修改变量的值以表示您的环境中的变量)

(in this case I'm using RVM)

(这里我用的是RVM)

PATH=/home/deploy/.rvm/gems/ruby-2.0.0-p247/bin:/home/deploy/.rvm/gems/ruby-2.0.0p247@global/bin:/home/deploy/.rvm/rubies/ruby-2.0.0p247/bin:/home/deploy/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/bin/:/home/deploy/.rvm/bin

路径= / home /部署/ .rvm /珠宝/ ruby-2.0.0-p247 / bin:/ home /部署/ .rvm /珠宝/ ruby-2.0.0p247@global / bin:/ home /部署/ .rvm /红宝石/ ruby-2.0.0p247 / bin:/ home /部署/ .rvm / bin:/ usr /地方/ bin:/ usr / bin:/ bin:/ usr /地方/游戏:/ usr /游戏:/ usr / bin /:/ home /部署/ .rvm / bin

GEM_HOME=/home/deploy/.rvm/gems/ruby-2.0.0-p247

GEM_HOME = / home /部署/ .rvm /珠宝/ ruby-2.0.0-p247

GEM_PATH=/home/deploy/.rvm/gems/ruby-2.0.0-p247/home/deploy/.rvm/gems/ruby-2.0.0-p247@global

GEM_PATH = / home /部署/ .rvm /珠宝/ ruby-2.0.0-p247 / home /部署/ .rvm /珠宝/ ruby-2.0.0-p247@global

MY_RUBY_HOME=/home/deploy/.rvm/rubies/ruby-2.0.0-p247

MY_RUBY_HOME = / home /部署/ .rvm /红宝石/ ruby-2.0.0-p247

#2


1  

Which shell are you using? Since I have seen whenever adds 'bash -l -c ' in job command. Either set

你用的是哪个壳层?因为我曾见过在job command中添加bash -l -c。要么设置

set :job_template, nil

设置:job_template,nil

or if you are using zsh then

或者如果你使用zsh

set :job_template, "zsh -l -c ':job'"

set:job_template "zsh -l -c ':job'"

This solved my issue

这解决了我的问题

#1


1  

You'll need to pass in the necessary environment variables in crontab.

您需要在crontab中传递必要的环境变量。

Add these lines at the top of your crontab (crontab -e)

在你的crontab (crontab -e)的顶部添加这些线条

(obviously you'll modify the values of the variables to represent those in your environment)

(显然,您将修改变量的值以表示您的环境中的变量)

(in this case I'm using RVM)

(这里我用的是RVM)

PATH=/home/deploy/.rvm/gems/ruby-2.0.0-p247/bin:/home/deploy/.rvm/gems/ruby-2.0.0p247@global/bin:/home/deploy/.rvm/rubies/ruby-2.0.0p247/bin:/home/deploy/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/bin/:/home/deploy/.rvm/bin

路径= / home /部署/ .rvm /珠宝/ ruby-2.0.0-p247 / bin:/ home /部署/ .rvm /珠宝/ ruby-2.0.0p247@global / bin:/ home /部署/ .rvm /红宝石/ ruby-2.0.0p247 / bin:/ home /部署/ .rvm / bin:/ usr /地方/ bin:/ usr / bin:/ bin:/ usr /地方/游戏:/ usr /游戏:/ usr / bin /:/ home /部署/ .rvm / bin

GEM_HOME=/home/deploy/.rvm/gems/ruby-2.0.0-p247

GEM_HOME = / home /部署/ .rvm /珠宝/ ruby-2.0.0-p247

GEM_PATH=/home/deploy/.rvm/gems/ruby-2.0.0-p247/home/deploy/.rvm/gems/ruby-2.0.0-p247@global

GEM_PATH = / home /部署/ .rvm /珠宝/ ruby-2.0.0-p247 / home /部署/ .rvm /珠宝/ ruby-2.0.0-p247@global

MY_RUBY_HOME=/home/deploy/.rvm/rubies/ruby-2.0.0-p247

MY_RUBY_HOME = / home /部署/ .rvm /红宝石/ ruby-2.0.0-p247

#2


1  

Which shell are you using? Since I have seen whenever adds 'bash -l -c ' in job command. Either set

你用的是哪个壳层?因为我曾见过在job command中添加bash -l -c。要么设置

set :job_template, nil

设置:job_template,nil

or if you are using zsh then

或者如果你使用zsh

set :job_template, "zsh -l -c ':job'"

set:job_template "zsh -l -c ':job'"

This solved my issue

这解决了我的问题