I would refactor this to never use mv; only use cp or better use a symlink;

Check in an index.enabled.html and a index.disabled.html

Then your enable disable tasks just need to rewrite the symlink of index.html 
to the matching state; you can even check in the symlink to your preferred 
state. 


On Sep 15, 2011, at 4:47 PM, patrick99e99 <[email protected]> wrote:

> Hi everyone,
> 
> I am just wondering what the proper way to setup an on_rollback method
> is?
> 
> As of right now, my deploy.rb file does this:
> 
> before "deploy", "deploy:web:disable"
> after "deploy", "deploy:web:enable"
> 
> disable_path = "#{shared_path}/system/maintenance"
> namespace :deploy do
>  namespace :web do
>    desc "Disables the website by putting the maintenance files live."
>    task :disable, :roles => :web, :except => { :no_release => true }
> do
>      on_rollback { run "mv #{disable_path}/index.html #{disable_path}/
> index.disabled.html" }
>      run "mv #{disable_path}/index.disabled.html #{disable_path}/
> index.html"
>    end
> 
>    desc "Enables the website by disabling the maintenance files."
>    task :enable, :roles => :web, :except => { :no_release => true }
> do
>        run "rm -f #{disable_path}/index.html"
>    end
> 
>    desc "Copies your maintenance from public/maintenance to shared/
> system/maintenance."
>    task :update_maintenance_page, :roles => :web, :except =>
> { :no_release => true } do
>      run "cp -R #{release_path}/public/maintenance/*
> #{disable_path}/"
>    end
>  end
> end
> 
> ....
> 
> But if a deploy fails, then the next time you try to deploy it fails
> because it can't find index.disabled.html...  So I want to add a hook
> for rollback that will move the index.html back to index.disabled.html
> 
> I found this:
> https://github.com/capistrano/capistrano/wiki/2.x-DSL-Configuration-Execution-On-Rollback
> 
> But I am not quite sure if that's the proper way to do it?
> 
> If I am understanding correctly, I would need to modify my deploy.rb
> to have in it:
> 
> include Capistrano::Configuration::Execution
> 
> on_rollback { find_and_execute_task("deploy:web:enable") }
> 
> ...
> 
> Is this correct?  Or is there a better way?
> 
> Thanks!
> 
> -patrick
> 
> -- 
> * You received this message because you are subscribed to the Google Groups 
> "Capistrano" group.
> * To post to this group, send email to [email protected]
> * To unsubscribe from this group, send email to 
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/capistrano?hl=en

-- 
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to [email protected]
* To unsubscribe from this group, send email to 
[email protected] For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en

Reply via email to