|
2 | 2 | # To load this Capistrano configuration, require 'easy/deployment/apache' from deploy.rb
|
3 | 3 |
|
4 | 4 | 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 | + |
5 | 9 | namespace :apache do
|
6 | 10 | desc "Configure this site, test the configuration & gracefully reload the Apache configuration"
|
7 | 11 | task :configure_and_reload, :roles => :web, :except => { :no_release => true } do
|
|
10 | 14 | graceful
|
11 | 15 | end
|
12 | 16 |
|
13 |
| - desc "Configure this site" |
| 17 | + desc "Configure this site (with files from config/deploy/apache/* or config/deploy/apache.conf)" |
14 | 18 | 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 |
17 | 45 | end
|
18 | 46 |
|
19 | 47 | [:stop, :start, :restart, :graceful, :configtest].each do |action|
|
|
0 commit comments