Created
October 2, 2012 13:33
-
-
Save deeeki/3819191 to your computer and use it in GitHub Desktop.
Capistrano Apache deployment recipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#for RHEL distributions | |
namespace :httpd do | |
namespace :deploy do | |
set :local_src_path, "#{Dir.pwd}/config/httpd/conf.d" | |
set :remote_src_path, "#{shared_path}/httpd/conf.d" | |
set :remote_dest_path, '/etc/httpd/conf.d' | |
task :default, :roles => :web do | |
transaction do | |
on_rollback do | |
run "for file in `find #{remote_dest_path} -type l`; do sudo rm $file; done;", :pty => true | |
run "rm -rf #{remote_src_path}" | |
run "cp -rf #{remote_src_path}.prev #{remote_src_path}" | |
sudo "ln -s #{remote_src_path}/*.{conf,passwd} #{remote_dest_path}", :pty => true | |
end | |
update | |
reload | |
end | |
end | |
task :setup, :roles => :web do | |
run "mkdir -p #{shared_path}/httpd/conf.d #{shared_path}/httpd/conf.d.prev" | |
end | |
task :update, :roles => :web do | |
#remove old symlinks | |
run "for file in `find #{remote_dest_path} -type l`; do sudo rm $file; done;", :pty => true | |
#backup old files | |
run "rm -rf #{remote_src_path}.prev" | |
run "cp -rf #{remote_src_path} #{remote_src_path}.prev" | |
#upload new files | |
Dir.glob("#{local_src_path}/{*,environments/#{stage}}.{conf,passwd}").each do |file| | |
upload(file, remote_src_path, :via => :scp) | |
end | |
#create new symlinks | |
sudo "ln -s #{remote_src_path}/*.{conf,passwd} #{remote_dest_path}", :pty => true | |
end | |
task :reload, :roles => :web do | |
sudo '/etc/init.d/httpd configtest', :pty => true | |
sudo '/etc/init.d/httpd reload', :pty => true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment