Skip to content

Commit 5219bb8

Browse files
author
Shevaun Coker
committed
allow apache configuration to be a folder of config files (or a single file), also add passenger settings configuration
1 parent e5817ac commit 5219bb8

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

lib/easy/deployment/apache.rb

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# To load this Capistrano configuration, require 'easy/deployment/apache' from deploy.rb
33

44
Capistrano::Configuration.instance(:must_exist).load do
5+
def remote_file_exists?(full_path)
6+
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
7+
end
8+
59
namespace :apache do
610
desc "Configure this site, test the configuration & gracefully reload the Apache configuration"
711
task :configure_and_reload, :roles => :web, :except => { :no_release => true } do
@@ -10,10 +14,34 @@
1014
graceful
1115
end
1216

13-
desc "Configure this site"
17+
desc "Configure this site (with files from config/deploy/apache/* or config/deploy/apache.conf)"
1418
task :configure, :roles => :web, :except => { :no_release => true } do
15-
run "cp -f #{current_path}/config/deploy/#{stage}/apache.conf /etc/apache2/sites-available/#{application}"
16-
run "ln -fs /etc/apache2/sites-available/#{application} /etc/apache2/sites-enabled/#{application}"
19+
apache_dir_path = "#{current_path}/config/deploy/#{stage}/apache"
20+
if remote_file_exists?(apache_dir_path) # multiple apache files
21+
files = capture("for f in #{apache_dir_path}/*; do echo $f; done").split("\r\n")
22+
files.each do |file|
23+
file_name = file.split(/\/([^\/]+)$/)[1]
24+
run "cp -f #{file} /etc/apache2/sites-available/#{file_name}"
25+
run "ln -fs /etc/apache2/sites-available/#{file_name} /etc/apache2/sites-enabled/#{file_name}"
26+
end
27+
else # single apache file (to be deprecated)
28+
run "cp -f #{current_path}/config/deploy/#{stage}/apache.conf /etc/apache2/sites-available/#{application}"
29+
run "ln -fs /etc/apache2/sites-available/#{application} /etc/apache2/sites-enabled/#{application}"
30+
end
31+
32+
configure_mods
33+
end
34+
35+
desc "Configure apache mods (currently only supports passenger.conf)"
36+
task :configure_mods, :roles => :web, :except => { :no_release => true } do
37+
passenger_conf = "#{current_path}/config/deploy/#{stage}/passenger.conf"
38+
39+
if remote_file_exists?(passenger_conf)
40+
run "cp -f #{passenger_conf} /etc/apache2/mods-available/passenger.conf"
41+
run "ln -fs /etc/apache2/mods-available/passenger.conf /etc/apache2/mods-enabled/passenger.conf"
42+
else
43+
puts "Passenger.conf not found, not configuring any apache mods"
44+
end
1745
end
1846

1947
[:stop, :start, :restart, :graceful, :configtest].each do |action|

0 commit comments

Comments
 (0)