Skip to content

Instantly share code, notes, and snippets.

@deeeki
Created October 2, 2012 13:33
Show Gist options
  • Save deeeki/3819191 to your computer and use it in GitHub Desktop.
Save deeeki/3819191 to your computer and use it in GitHub Desktop.
Capistrano Apache deployment recipe
#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