[英]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部署了两个环境(
staging
和production
)。每个环境的部署相互干扰,完全替代了另一个环境的工作。
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
作业均被删除。 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
作业均已删除。 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: 我需要解决以下两种情况之一:
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
版本) 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 版本
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.