2015-01-14 2 views
1

저는 Rails 3.2에 capistrano v2를 사용하고 있습니다. deploy.rb에 bundler 태스크가 있습니다. 내가 cap deploy:rollback을 실행하면capistrano on_rollback을 호출하지 않습니다.

# Bundler tasks 
namespace :bundler do 
    desc "Create a symlink" 
    task :create_symlink, :roles => :app do 
    shared_dir = File.join(shared_path, 'bundle') 
    release_dir = File.join(release_path, '.bundle') 
    run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}") 
    end 

    desc "Install required gems" 
    task :install, :roles => :app do 
    puts "New Release" 
    run "cd #{release_path} && #{bundle_path} install" 

    on_rollback do 
     if previous_release 
     puts "Rollback" 
     run "cd #{previous_release} && #{bundle_path} install" 
     else 
     logger.important "no previous release to rollback to, rollback of bundler:install skipped" 
     end 
    end 
    end 

    desc "Run bundler on new release" 
    task :bundle_new_release, :roles => :db do 
    bundler.create_symlink 
    bundler.install 
    end 
end 

after "deploy:update_code", "bundler:bundle_new_release" 
after "deploy:rollback:revision", "bundler:install" 

그것은이 CD {release_path}를 실행하려고하여 on_rollback 코드를 실행하지 않습니다.

이 예제는 http://kazjote.eu/2010/08/04/bundler-and-capistrano-the-right-way에서 가져 왔습니다.

+0

Capistrano는'cap db : rollback'보다는'cap deploy rollback'을 호출 할 때만 on_rollback 블록을 실행할 수 있다고 생각합니다. db : rollback 작업은 어떻게 생겼습니까? – johnsorrentino

+0

죄송합니다. 배포를 실행했습니다 : 롤백, 내 기록 만 보았습니다. – map7

답변

1

로그를 제공하지 않았으므로 deploy : 롤백은 이전 버전을 사용해야하는 것처럼 말할 수는 없지만 배포를 혼란스럽게합니다. 롤백 (작업), on_rollback (작업) 훅).

on_rollback은 작업 : 설치가 실패한 경우에만 호출됩니다. 그러나 실제로 실행하기 위해 on_rollback 훅에 대한 트랜잭션을 정의해야한다고 생각합니다. (실제로는 실행 CD보다 먼저 on_rollback을 정의해야합니다.)

배포 : 롤백은 배포 작업을 실행해야합니다. . 이전의 성공적인 출시와 함께

여기 간단한 예를 발견

http://pedz-bits.blogspot.com/2012/09/capistrano-errors-ensure-and-onrollback.html

namespace :fun do 
    desc "Sample showing rescue, ensure, and on_rollback inside a transaction" 
    task :stuff, :roles => :app do 
    transaction do 
     on_rollback { logger.debug "my rollback" } 
     begin 
     logger.debug "main" 
     # Either run or run_locally will work the same 
     # run_locally "false" 
     run "false" 
     rescue => e 
     logger.debug "rescue #{e.class}" 
     raise e 
     ensure 
     logger.debug "ensure" 
     end 
    end 
    end 
end 

Command output: 

cap fun:stuff 
    * executingD `fun:stuff' 
** transaction: start 
    * main 
    * executingB "false" 
    servers: ["condor.austin.ibm.com"] 
    [condor.austin.ibm.com] executingA command 
    command finished in 771ms 
    * rescue Capistrano::CommandError 
    * ensure 
*** [fun:stuff] rolling back 
    * my rollback 
failed: "bash -l -c 'false'" on condor.austin.ibm.com 

노트를

  1. on_rollback은 트랜잭션이 활성화되어있을 때 오류가 발생하는 경우에만 실행됩니다.
  2. on_rollback도 트랜잭션 내에서 정의되어야합니다.
  3. 오류가 발생하거나 더 높은 수준의 프로세스가있는 태스크가 성공적으로 완료되었다고 가정하면 e를 발생시킵니다.
  4. 예상대로 작동합니다.
관련 문제