简体   繁体   English

每当宝石上的aws opsworks

[英]Whenever gem on aws opsworks

Does anyone have experience/success using the whenever gem on aws opsworks? 有没有人在aws opsworks上使用when gem时有经验/成功? 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!!! 谢谢!!!

EDIT: 编辑:

We ended up doing it a bit differently... 我们最终做的有点不同......

Code: 码:

Can't really post the real code, but it's like this: 无法真正发布真实代码,但它是这样的:

in deploy/before_migrate.rb: 在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

in deploy/after_restart.rb: 在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

in config/schedule.rb.erb: 在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

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 . 我们在我们的仓库中有一个随时随地使用的菜谱,欢迎您使用: https//github.com/freerunningtech/frt-opsworks-cookbooks I assume you're familiar with adding custom cookbooks to your opsworks stacks. 我假设您熟悉将自定义cookbook添加到opsworks堆栈中。

We generally run it on its own layer that also includes the rails cookbooks required for application deployment (while not the app server): 我们通常在它自己的层上运行它,它还包括应用程序部署所需的rails cookbook(而不是app服务器):

  • Configure: rails::configure 配置:rails :: configure
  • Deploy: deploy::rails whenever 部署:deploy :: rails
  • Undeploy: deploy::rails-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. 但是,我们通常也会将此实例部署为应用程序服务器,这意味着我们最终还会从我们正在使用的框中提供请求。

There is one "gotcha", in that you must set your path in the env at the top of the schedule.rb like this: 有一个“问题”,因为你必须在schedule.rb顶部的env中设置你的路径,如下所示:

env :PATH, ENV['PATH']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM