Skip to content

Commit

Permalink
Added management of /etc/apache2/apache2.conf
Browse files Browse the repository at this point in the history
You can now specify the following apache directives using configuration:

 * Timeout => :timeout (default 300)
 * KeepAlive => :keep_alive (default 'Off')
 * MaxKeepAliveRequests => :max_keep_alive_requests (default 100)
 * MaxKeepAliveTimeout => :keep_alive_timeout (default 15)
 * MaxClients => :max_clients (default 150)
 * ServerLimit => :server_limit (default 16)
 * Timeout => :timeout (default 300)
  • Loading branch information
technicalpickles committed Feb 27, 2010
1 parent 1a85339 commit 3f46140
Show file tree
Hide file tree
Showing 10 changed files with 641 additions and 57 deletions.
26 changes: 17 additions & 9 deletions lib/moonshine/manifest.rb
Expand Up @@ -121,20 +121,28 @@ def on_stage(*args)
end
end

def local_template_dir
@local_template_dir ||= rails_root.join('app/manifests/templates')
end

def local_template(pathname)
(local_template_dir + pathname.basename).expand_path
end

# Render the ERB template located at <tt>pathname</tt>. If a template exists
# with the same basename at <tt>RAILS_ROOT/app/manifests/templates</tt>, it
# is used instead. This is useful to override templates provided by plugins
# to customize application configuration files.
def template(pathname, b = binding)
template_contents = nil
basename = pathname.index('/') ? pathname.split('/').last : pathname
if File.exist?(File.expand_path(File.join(rails_root, 'app', 'manifests', 'templates', basename)))
template_contents = File.read(File.expand_path(File.join(rails_root, 'app', 'manifests', 'templates', basename)))
elsif File.exist?(File.expand_path(pathname))
template_contents = File.read(File.expand_path(pathname))
else
raise LoadError, "Can't find template #{pathname}"
end
pathname = Pathname.new(pathname) unless pathname.kind_of?(Pathname)

template_contents = if local_template(pathname).exist?
template_contents = local_template(pathname).read
elsif pathname.exist?
template_contents = pathname.read
else
raise LoadError, "Can't find template #{pathname}"
end
ERB.new(template_contents).result(b)
end

Expand Down
4 changes: 4 additions & 0 deletions lib/moonshine/manifest/rails.rb
Expand Up @@ -55,4 +55,8 @@ def default_stack
recipe :rails_rake_environment, :rails_gems, :rails_directories, :rails_bootstrap, :rails_migrations, :rails_logrotate
recipe :ntp, :time_zone, :postfix, :cron_packages, :motd, :security_updates
end

def rails_template_dir
@rails_template_dir ||= Pathname.new(__FILE__).dirname.join('rails', 'templates').expand_path
end
end
26 changes: 25 additions & 1 deletion lib/moonshine/manifest/rails/apache.rb
@@ -1,4 +1,14 @@
module Moonshine::Manifest::Rails::Apache
def self.included(manifest)
manifest.configure :apache => {
:keep_alive => 'Off',
:max_keep_alive_requests => 100,
:keep_alive_timeout => 15,
:max_clients => 150,
:server_limit => 16,
:timeout => 300
}
end

# Installs Apache 2.2 and enables mod_rewrite and mod_status. Enables mod_ssl
# if <tt>configuration[:ssl]</tt> is present
Expand All @@ -12,7 +22,8 @@ def apache_server
a2enmod('headers')
a2enmod('ssl')
end
if configuration[:apache] && configuration[:apache][:users]

if configuration[:apache][:users]
htpasswd = configuration[:apache][:htpasswd] || "#{configuration[:deploy_to]}/shared/config/htpasswd"

file htpasswd, :ensure => :file, :owner => configuration[:user], :mode => '644'
Expand All @@ -23,6 +34,15 @@ def apache_server
:unless => "grep '#{user}' #{htpasswd}"
end
end

apache2_conf = template(rails_template_dir.join('apache2.conf.erb'), binding)
file '/etc/apache2/apache2.conf',
:ensure => :present,
:content => apache2_conf,
:mode => '644',
:require => package('apache2-mpm-worker'),
:notify => service('apache2')

status = <<-STATUS
<IfModule mod_status.c>
ExtendedStatus On
Expand All @@ -34,13 +54,17 @@ def apache_server
</Location>
</IfModule>
STATUS



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

private
Expand Down
6 changes: 4 additions & 2 deletions lib/moonshine/manifest/rails/mysql.rb
Expand Up @@ -10,8 +10,10 @@ def mysql_server
package('mysql-server'),
package('mysql')
]
#ensure the mysql key is present on the configuration hash

# ensure the mysql key is present on the configuration hash
configure(:mysql => {})

file '/etc/mysql', :ensure => :directory
file '/etc/mysql/conf.d', :ensure => :directory
file '/etc/mysql/conf.d/innodb.cnf',
Expand Down Expand Up @@ -76,4 +78,4 @@ def mysql_query(sql)
"su -c \'/usr/bin/mysql -u root -e \"#{sql}\"\'"
end

end
end

0 comments on commit 3f46140

Please sign in to comment.