简体   繁体   English

我如何在任何时候/ capistrano都不覆盖其他环境的工作?

[英]How do I keep whenever/capistrano from overwriting jobs for other environments?

I have two environments, staging and production , on one server, being deployed with capistrano 3. The deploys for each environment clobber each other, fully replacing the other environment's jobs. 我在一台服务器上使用capistrano 3部署了两个环境( stagingproduction )。每个环境的部署相互干扰,完全替代了另一个环境的工作。

  • If I deploy staging , then all of the cronjobs are removed and replaced with jobs referencing the staging release path and environment. 如果我部署了staging ,那么所有cronjobs都将被删除,并替换为引用staging发行路径和环境的作业。 All of the production jobs are removed. 所有production作业均被删除。
  • If I deploy production , then all of the cronjobs are removed and replaced with jobs referencing the production release path and environment. 如果部署production ,那么所有cronjob都将被删除,并替换为引用production发布路径和环境的作业。 All of the staging jobs are removed. 所有staging作业均已删除。
  • If I do a case statement in schedule.rb on @environment , and only have jobs set for a when 'production' situation, then when staging is deployed it completely clears the cronjobs. 如果我在@environment schedule.rb执行了一条case语句,并且仅针对when 'production'情况设置了作业,那么在部署staging时,它将完全清除cronjobs。 All of the jobs are gone. 所有的工作都不见了。

I need to get to either of these two situations: 我需要解决以下两种情况之一:

  • Have two sets of jobs (one for staging and one for production ) that each persist through either environment's deploy (so, in my example at the bottom, there would be two jobs listed - one for the staging release and one for the production release) 有两组作业(一组用于staging ,一组用于production ),它们在任何一个环境的部署中都可以持续存在(因此,在我下面的示例中,将列出两份作业-一组用于staging版本,另一组用于production版本)
  • One set of jobs (just for production ) that persists through either environment's deploy (so, the staging deploy should not remove it) 在任何一个环境的部署中都会保留的一组作业(仅用于production )(因此, staging部署不应删除它)

Can anyone explain how this is done? 谁能解释这是怎么做的? I've included my current configuration, below, in case it's helpful. 如果有帮助,我在下面提供了当前配置。

Versions 版本

  • capistrano: 3.3.5 capistrano:3.3.5
  • whenever: 0.9.4 每当:0.9.4
  • ruby: 2.1.5 红宝石:2.1.5
  • rails: 3.2.21 导轨:3.2.21

Capfile Capfile

require 'whenever/capistrano'

Relevant line in config/deploy/deploy.rb config / deploy / deploy.rb中的相关行

set :application, 'application_name'

config/deploy/production.rb 配置/部署/ production.rb

server '1.2.3.4', user: 'username', roles: %w{web app}
set :branch, 'master'
set :deploy_to, '/home/username/production'
set :rails_env, 'production'
set :stage, :production
set :whenever_environment, -> { fetch(:stage) }
set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" }

config/deploy/staging.rb 配置/部署/ staging.rb

server '1.2.3.4', user: 'username', roles: %w{web app}
set :branch, 'staging'
set :deploy_to, '/home/username/staging'
set :rails_env, 'staging'
set :stage, :staging
set :whenever_environment, -> { fetch(:stage) }
set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" }

config/schedule.rb 配置/ schedule.rb

set :output, '/log/cron.log'
every 10.minutes do
  runner 'ModelName.method_name'
end

The resulting cronjob after a staging deploy staging部署后产生的cronjob

# Begin Whenever generated tasks for: application_name
0,10,20,30,40,50 * * * * /bin/bash -l -c 'cd /home/username/staging/releases/20150317012814 && script/rails runner -e staging '\''ModelName.method_name'\'' >> /log/cron.log 2>&1'

# End Whenever generated tasks for: application_name

You don't have any comment blocks surrounding the actual cron jobs? 您对实际的cron作业没有任何评论栏吗? I have an old Rails 3 app that uses this (and just this) and it works. 我有一个旧的Rails 3应用程序,它使用了这个(也就是这个)并且可以正常工作。 Maybe it will help: 也许会有所帮助:

config/deploy.rb:set :whenever_environment, defer { stage }
config/deploy.rb:set :whenever_identifier, defer { "#{application}_#{stage}" }
config/deploy.rb:set :whenever_command, 'bundle exec whenever'

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

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