Module: Moonshadow::Manifest::Rails::Apache

Included in:
Moonshadow::Manifest::Rails
Defined in:
lib/moonshine/manifest/rails/apache.rb

Instance Method Summary collapse

Instance Method Details

#apache_serverObject

Installs Apache 2.2 and enables mod_rewrite and mod_status. Enables mod_ssl if configuration[:ssl] is present



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/moonshine/manifest/rails/apache.rb', line 5

def apache_server
  package "apache2-mpm-worker", :ensure => :installed
  service "apache2", :require => package("apache2-mpm-worker"), :restart => '/etc/init.d/apache2 restart', :ensure => :running
  a2enmod('rewrite')
  a2enmod('status')
  if configuration[:ssl]
    a2enmod('headers')
    a2enmod('ssl')
  end
  if configuration[:apache] && configuration[:apache][:users]
    htpasswd = configuration[:apache][:htpasswd] || "#{configuration[:deploy_to]}/shared/config/htpasswd"
    
    file htpasswd, :ensure => :file, :owner => 'rails', :mode => '644'
    
    configuration[:apache][:users].each do |user,pass|
      exec "htpasswd #{user}",
        :command => "htpasswd -b #{htpasswd} #{user} #{pass}",
        :unless  => "grep '#{user}' #{htpasswd}"
    end
  end
  status = "<IfModule mod_status.c>\nExtendedStatus On\n<Location /server-status>\n   SetHandler server-status\n   order deny,allow\n   deny from all\n   allow from 127.0.0.1\n</Location>\n</IfModule>\n"
  file '/etc/apache2/mods-available/status.conf',
    :ensure => :present,
    :mode => '644',
    :require => exec('a2enmod status'),
    :content => status,
    :notify => service("apache2")
  file '/etc/logrotate.d/varlogapachelog.conf', :ensure => :absent
end