一般来说,我将使用cmd开始delay_job:
RAILS_ENV=production bin/delayed_job start
现在,我编写了一个简单的启动脚本,以在重新启动后自动启动延迟的作业。
我发现,如果我在脚本中编写了上面的cmd,它将失败。
# this is the execution in the upstart conf
exec RAILS_ENV=production bin/delayed_job start
经过一番谷歌测试之后,我发现这可以在我的脚本中运行:
exec bundle exec /usr/bin/env RAILS_ENV=production bin/delayed_job start
这导致了我的问题,我猜/usr/bin/env RAILS_ENV=production
是将环境变量传递到bin / delay_job脚本中,捆绑执行在这里如何?
脚本中没有bundle exec,它将引发与
有关的错误 require': cannot load such file -- bundler/setup (LoadError)
。
我意识到使用bundle exec可以在某些环境下运行rails,但是为什么在脚本中有此必要呢?
还是我想在脚本中执行bundle exec
或bin/delayed_job
之类的cmd时需要rake
吗?
谢谢。
已更新
我将upstart脚本复制到另一个节点并以相同的方式执行它。 但是,它引发了不兼容的库版本错误... 我跑
bundle exec /usr/bin/env RAILS_ENV=production bin/delayed_job start
直接在终端上运行,并且按预期方式工作,但是将上述命令放在脚本中失败。
有人可以告诉我为什么执行相同命令但在不同位置时结果不同吗?