每当AWS上的宝石opsworks [英] Whenever gem on aws opsworks
问题描述
有人在aws opsworks上使用everyth gem有经验/成功吗?有什么好食谱吗?我可以将该配方放在单独的层上,然后将一个实例与该另外的层相关联吗?还是有更好的方法呢?谢谢!!!
Does anyone have experience/success using the whenever gem on aws opsworks? Is there a good recipe? Can I put that recipe on a separate layer and associate one instance with that additional layer? Or is there a better way to do it? Thanks!!!
我们最终做了一些不同的事情...
We ended up doing it a bit differently...
代码:
不能真正发布真实的代码,但这是这样的:
Can’t really post the real code, but it’s like this:
在deploy/before_migrate.rb中:
in deploy/before_migrate.rb:
[:schedule].each do |config_name|
Chef::Log.info("Processing config for #{config_name}")
begin
template "#{release_path}/config/#{config_name}.rb" do |_config_file|
variables(
config_name => node[:deploy][:APP_NAME][:config_files][config_name]
)
local true
source "#{release_path}/config/#{config_name}.rb.erb"
end
rescue => e
Chef::Log.error e
raise "Error processing config for #{config_name}: #{e}"
end
end
在deploy/after_restart.rb中:
in deploy/after_restart.rb:
execute 'start whenever' do
cwd release_path
user node[:deploy][:APP_NAME][:user] || 'deploy'
command 'bundle exec whenever -i APP_NAME'
end
在config/schedule.rb.erb中:
in config/schedule.rb.erb:
<% schedule = @schedule || {} %>
set :job_template, "bash -l -c 'export PATH=/usr/local/bin:${PATH} && :job'"
job_type :runner, 'cd :path && bundle exec rails runner -e :environment ":task" :output'
job_type :five_runner, 'cd :path && timeout 300 bundle exec rails runner -e :environment ":task" :output'
set :output, 'log/five_minute_job.log'
every 5.minutes, at: <%= schedule[:five_minute_job_minute] || 0 %> do
five_runner 'Model.method'
end
推荐答案
我们在回购协议中有一个随时使用的食谱,我们非常欢迎您在这里使用:https://github.com/freerunningtech/frt-opsworks-cookbooks .我认为您熟悉将自定义食谱添加到opsworks堆栈中的情况.
We have a whenever cookbook in our repo we use that you would be more than welcome to use here: https://github.com/freerunningtech/frt-opsworks-cookbooks. I assume you're familiar with adding custom cookbooks to your opsworks stacks.
我们通常在它自己的层上运行它,其中还包括应用程序部署(而不是应用程序服务器)所需的rails食谱:
We generally run it on its own layer that also includes the rails cookbooks required for application deployment (while not the app server):
- 配置:rails :: configure
- 部署:每当部署 :: rails
- 取消部署:deploy :: rails-undeploy
- Configure: rails::configure
- Deploy: deploy::rails whenever
- Undeploy: deploy::rails-undeploy
但是,我们通常也将此实例部署为应用程序服务器,这意味着我们也确实会在任何时候都从所使用的框中提供请求.
However, we usually also deploy this instance as an application server, meaning we do end up serving requests from the box we're using for whenever as well.
有一个陷阱",因为您必须在schedule.rb顶部的环境中设置路径,如下所示:
There is one "gotcha", in that you must set your path in the env at the top of the schedule.rb like this:
env :PATH, ENV['PATH']
这篇关于每当AWS上的宝石opsworks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!