script/runner:3:in `require': 无法加载这样的文件 -- commands/runner (LoadError)

script/runner:3:in `require': cannot load such file -- commands/runner (LoadError)

我正在尝试使用 cron 和 systemd 在我的 Rails 模型中启动一个 class 方法。

不幸的是,当 cron 尝试激活正确的 Rails 方法时,似乎存在某种路径问题。

下面是我的运行脚本,导致问题的是第 3 行:

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'

完成后的错误信息如下所示:

Apr 01 09:00:01 myapp systemd[1]: Started Myapp ModelA method b.
Apr 01 09:00:02 myapp runner[25783]: /srv/myapp/current/script/runner:3:in `require': cannot load such file -- commands/runner (LoadError)
Apr 01 09:00:02 myapp runner[25783]: from /srv/myapp/current/script/runner:3:in `<main>'

或者是因为 Rails 在跟我开 4 月 1 日的傻瓜玩笑?

问题是 myapp 最近从 Rails 2.3 更新到 Rails 4.1,作为遗留问题,/script 文件夹仍然用于启动跑步者。

在 Rails 4 中启动跑步者的正确方法是使用这样的 bin/rails 脚本:

bin/rails runner "Model.method"

我遇到的另一个问题是我在 .gitignore 文件中指定了 bin/*,所以 bin/rails 脚本甚至不在服务器中。

我得到了 this Whosebug post and from RailsGuides page 的帮助。