【问题标题】:Why can't run start delayed job command when use crontab为什么使用 crontab 时无法运行启动延迟作业命令
【发布时间】:2018-02-25 22:00:43
【问题描述】:
#!/bin/bash
#!/usr/bin/env ruby

cd /var/www/project
if [ ! -f tmp/pids/delayed_job.pid ]; then
  echo "File not found!"
  pwd
  ./bin/delayed_job start

  echo "Run script successful!"
fi

在我的代码中,正常启动是可以工作的,但使用 crontab 运行时不起作用。

请有任何想法。

【问题讨论】:

  • 告诉我们更多关于您在此处尝试做什么的信息。什么控制tmp/pids/delayed_job.pid 的存在以及您的crontab 条目是什么样的?
  • 在这一行 tmp/pids/delayed_job.pid 我在 crontab 文件 * * * * * /var/www/project/delayed_job.sh >> /var/www/project/delayed_job.txt 中检查延迟的作业是运行是对还是错
  • 关于这个问题的更多信息我想在延迟作业消失时使用 crontab 自动启动延迟作业。
  • crontab 无法执行这一行./bin/delayed_job start
  • 谢谢@rnorris 我可以解决它。在 shell 脚本中不知道 ruby​​ 环境我使用 .rbenv 然后我将 ruby​​ $home 路径添加到 shell 脚本可以修复它。

标签: ruby-on-rails bash shell cron delayed-job


【解决方案1】:

解决了。

我使用 rbenv 进行 ruby​​ 安装并将其设置到 .bash_profile。是的环境工作,但我在 crontab 中运行 ruby​​ 不起作用。

解决方案:我将 .bash_profile 中的一些配置复制到我的脚本中,如下所示

#!/bin/sh

#below script from .bash_profile

PATH=$PATH:$HOME/bin export PATH export PATH=$HOME/.rbenv/bin:$PATH eval "$(rbenv init -)" export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
#end script from .bash_profile

RAILS_HOME="/var/www/{project}" if [ ! -f $RAILS_HOME/tmp/pids/delayed_job.pid ]; then echo "Starting Delayed job" $RAILS_HOME/bin/delayed_job start fi

【讨论】:

    猜你喜欢
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 2010-12-15
    • 2020-06-21
    • 1970-01-01
    • 2011-03-07
    • 2019-09-21
    • 1970-01-01
    相关资源
    最近更新 更多