EC2 实例移动时执行 Rails 'whenever' gem

Executing Rails 'whenever' gem when EC2 Instance Moves

我在 EC2 中为我的 rails cron 文件使用 'whenever' gem,它运行良好。 "Whenever -w" 写了它,我再也不用担心了。问题是当我的实例有计划的重启时。 rails 应用程序被传递到一个新实例,整个过程是无缝的,没有停机时间,但新实例没有我的 cron 文件。

如何确保在移动到新实例时写入 cron 文件?有没有办法在应用程序启动时 运行 之类的?谢谢

无论何时都是命令。如果你 运行:

bundle exec whenever --help 

您将获得完整的旗帜列表。你会想要:

bundle exec whenever -w /path/to/schedule.rb

您可以将简单的 shell 脚本添加到 /etc/init.d

#!/bin/bash
cd /to/app && /full/path/to/bundle exec whenever -w /full/path/to/schedule.rb