0
问题似乎是,在capistrano部署期间,创建的cron作业有RAILS_ENV=staging
,因为部署环境为staging
。然而,在Capistrano的回滚创建的cron作业具有RAILS_ENV=new_staging
其中new_staging
是Capistrano的阶段被回滚。Capistrano回滚破坏每当Cronjob
我的日程安排文件
set :job_template, nil
job_type :rake, "cd :path && :environment_variable=:environment bundle exec rake :task :output"
every 15.minute, roles: [:db] do
rake "jobs:publish", output: lambda { "2>&1 >> /path/to/capistrano_directory/shared/log/jobs.log" }
end
我的部署/ new_staging.rb文件
set :branch, "develop"
set :deploy_env, 'staging'
set :rails_env, 'staging'
server "[email protected]_ip", :web, :app, :db, :metrics
role :db, "[email protected]_ip", :primary => true # This is where Rails migrations will run
ssh_options[:forward_agent] = false # use local SSH keys remotely
ssh_options[:paranoid] = false
set :use_sudo, false
set :deploy_to, "/path/to/capistrano_directory"
set :unicorn_conf, "#{deploy_to}/current/config/environments/#{deploy_env}/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
before 'deploy:finalize_update', 'set_current_release'
before "deploy:finalize_update", "deploy:update_crontab"
after 'deploy:update_code', 'deploy:symlink_db'
namespace :deploy do
task :symlink_db, :roles => :app do
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{deploy_to}/current && bundle exec unicorn -C#{unicorn_conf} -E #{deploy_env} -D"
end
task :stop do
run "#{try_sudo} kill -QUIT `cat #{unicorn_pid}`"
end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
end
end
task :set_current_release, :roles => :app, :except => { :no_release => true } do
set :current_release, latest_release
end
而且我deploy.rb
require 'bundler/capistrano'
require 'capistrano/ext/multistage'
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer { stage }
set :whenever_roles, [:db, :metrics]
require "whenever/capistrano"
set :stages, %w(production staging new_staging)
set :application, "###"
set :repository, "###"
set :deploy_via, :remote_cache
set :scm, :git
default_run_options[:shell] = '/bin/bash --login'
ssh_options[:forward_agent] = false
ssh_options[:paranoid] = false
namespace :deploy do
desc "Update the crontab file"
task :update_crontab do
run "cd #{release_path} && RAILS_ENV=#{fetch(:rails_env)} bundle exec whenever --update-crontab #{application} --set environment=#{fetch(:rails_env)}"
end
end
- 每当版本(0.9.7)
- Capistrano版本(2.12.0)
什么导致回滚使用capistrano舞台而不是rails_env运行时每当宝石?我怎样才能正确使用rails_env?
是的,我们是在把我们的系统临时环境从古老拥挤的服务器的一个新奉献的过程d一个......我认为这可能很简单,但我不确定常规部署为什么使用正确的变量?任务是否覆盖它? –
通过定期部署你的意思是部署到'生产'或'分期'?我认为这些工作,因为Capistrano的阶段是一样的'当你'帽new_staging deploy'你的'stage'变量设置为舞台指定rails_env'('new_staging'),这意味着它不会与匹配'rails_env'。我可能已经错过了你的问题虽然:) –
嗯......做'捆绑高管帽new_staging deploy'导致'RAILS_ENV = staging'在cron作业,但'捆绑高管帽new_staging部署:rollback'导致'RAILS_ENV = new_staging '。 –