a bunch more real-world changes
This commit is contained in:
parent
c28918d905
commit
d19c5d6934
@ -8,11 +8,17 @@ module Apache
|
|||||||
include Apache::Master
|
include Apache::Master
|
||||||
include Apache::Quoteize
|
include Apache::Quoteize
|
||||||
include Apache::Permissions
|
include Apache::Permissions
|
||||||
|
include Apache::Directories
|
||||||
|
include Apache::Logging
|
||||||
|
|
||||||
def build(target = nil, &block)
|
def build(target = nil, &block)
|
||||||
reset!
|
reset!
|
||||||
|
|
||||||
self.instance_eval(&block)
|
self.instance_eval(&block)
|
||||||
|
|
||||||
|
File.open(target, 'w') { |f| f.puts @config * "\n" } if target
|
||||||
|
|
||||||
|
@config
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reset the current settings
|
# Reset the current settings
|
||||||
@ -35,7 +41,7 @@ module Apache
|
|||||||
#
|
#
|
||||||
# Split the provided name on underscores and capitalize the individual parts
|
# Split the provided name on underscores and capitalize the individual parts
|
||||||
def apachify(name)
|
def apachify(name)
|
||||||
name.to_s.split("_").collect(&:capitalize).join
|
name.to_s.split("_").collect(&:capitalize).join.gsub('Ssl', 'SSL')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Handle options that aren't specially handled
|
# Handle options that aren't specially handled
|
||||||
@ -60,28 +66,57 @@ module Apache
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def if_module(mod, &block)
|
||||||
|
blockify(apachify('if_module'), "#{mod}_module".to_sym, &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def directory(dir, &block)
|
||||||
|
directory? dir
|
||||||
|
blockify(apachify('directory'), dir, &block)
|
||||||
|
end
|
||||||
|
|
||||||
# Handle the blockification of a provided block
|
# Handle the blockification of a provided block
|
||||||
def blockify(tag_name, name, &block)
|
def blockify(tag_name, name, &block)
|
||||||
start = [ tag_name ]
|
start = [ tag_name ]
|
||||||
|
|
||||||
case name
|
case name
|
||||||
when String
|
when String
|
||||||
start << quoteize(name).first if name
|
start << quoteize(name).first
|
||||||
when Array
|
when Array
|
||||||
start << (quoteize(*name) * " ") if name
|
start << (quoteize(*name) * " ")
|
||||||
|
when Symbol
|
||||||
|
start << name.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
start = start.join(' ')
|
start = start.join(' ')
|
||||||
|
|
||||||
self << "" if (@indent == 0)
|
self << "" if (@line_indent == 0)
|
||||||
self << "<#{start}>"
|
self << "<#{start}>"
|
||||||
@line_indent += 1
|
@line_indent += 1
|
||||||
self.instance_eval(&block)
|
self.instance_eval(&block)
|
||||||
@line_indent -= 1
|
@line_indent -= 1
|
||||||
self << "</#{tag_name}>"
|
self << "</#{tag_name}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def apache_include(*opts)
|
||||||
|
self << "Include #{opts * " "}"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def writable?(path)
|
||||||
|
if !File.directory? File.split(path).first
|
||||||
|
puts "[warn] #{path} may not be writable!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def directory?(path)
|
||||||
|
if !File.directory? path
|
||||||
|
puts "[warn] #{path} does not exist!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
block_methods :if_module, :directory, :virtual_host
|
block_methods :virtual_host, :files_match
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
8
lib/apache/directory.rb
Normal file
8
lib/apache/directory.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module Apache
|
||||||
|
module Directories
|
||||||
|
def options(*opt)
|
||||||
|
opt = opt.collect { |o| apachify(o) }
|
||||||
|
self << "Options #{opt * " "}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
21
lib/apache/logging.rb
Normal file
21
lib/apache/logging.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
module Apache
|
||||||
|
module Logging
|
||||||
|
def error_log(*opts)
|
||||||
|
writable? opts.first
|
||||||
|
self << "ErrorLog #{opts * " "}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def custom_log(*opts)
|
||||||
|
writable? opts.first
|
||||||
|
self << "CustomLog #{opts * " "}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def combined_log_format(name = 'combined')
|
||||||
|
log_format '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"', name.to_sym
|
||||||
|
end
|
||||||
|
|
||||||
|
def common_log_format(name = 'common')
|
||||||
|
log_format '%h %l %u %t \"%r\" %>s %b', name.to_sym
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -15,10 +15,13 @@ module Apache
|
|||||||
passenger_ruby "#{ruby_root}/bin/ruby"
|
passenger_ruby "#{ruby_root}/bin/ruby"
|
||||||
end
|
end
|
||||||
|
|
||||||
def order(*args)
|
def enable_gzip!
|
||||||
self << "Order #{args * ','}"
|
directory '/' do
|
||||||
|
add_output_filter_by_type! :DEFLATE, 'text/html', 'text/plain', 'text/css', 'text/javascript', 'application/javascript'
|
||||||
|
browser_match! '^Mozilla/4', "gzip-only-text/html"
|
||||||
|
browser_match! '^Mozilla/4\.0[678]', "no-gzip"
|
||||||
|
browser_match! '\bMSIE', '!no-gzip', '!gzip-only-text/html'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :order! :order
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ module Apache
|
|||||||
modules.each { |m| self.send(m) }
|
modules.each { |m| self.send(m) }
|
||||||
self.instance_eval(&block) if block
|
self.instance_eval(&block) if block
|
||||||
|
|
||||||
@modules
|
[ '' ] + @modules + [ '' ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(method, *args)
|
def method_missing(method, *args)
|
||||||
|
@ -9,5 +9,26 @@ module Apache
|
|||||||
order :allow, :deny
|
order :allow, :deny
|
||||||
allow :from_all
|
allow :from_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def order(*args)
|
||||||
|
self << "Order #{args * ','}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_restrictive!
|
||||||
|
directory '/' do
|
||||||
|
options :follow_sym_links
|
||||||
|
allow_override :none
|
||||||
|
deny_from_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def no_htfiles!
|
||||||
|
files_match '^\.ht' do
|
||||||
|
deny_from_all
|
||||||
|
satisfy :all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
alias :order! :order
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
24
lib/apache/rake/create.rb
Normal file
24
lib/apache/rake/create.rb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
require 'fileutils'
|
||||||
|
require 'apache/config'
|
||||||
|
require 'apache/rake/create'
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
|
namespace :apache do
|
||||||
|
desc "Create all defined configs for the specified environment"
|
||||||
|
task :create, :environment do |t, args|
|
||||||
|
APACHE_ENV = (args[:environment] || 'production').to_sym
|
||||||
|
|
||||||
|
CONFIG = YAML.load_file('config.yml')
|
||||||
|
|
||||||
|
CONFIG['source_path'] = File.expand_path(CONFIG['source'])
|
||||||
|
CONFIG['dest_path'] = File.expand_path(CONFIG['destination'])
|
||||||
|
|
||||||
|
FileUtils.mkdir_p CONFIG['dest_path']
|
||||||
|
Dir.chdir CONFIG['dest_path']
|
||||||
|
|
||||||
|
Dir[File.join(CONFIG['source_path'], '**', '*.rb')].each do |file|
|
||||||
|
puts file
|
||||||
|
require file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
0
lib/apache/ssl.rb
Normal file
0
lib/apache/ssl.rb
Normal file
@ -29,6 +29,7 @@ describe Apache::Config, "should handle the basics of Apache config" do
|
|||||||
it "should Apachify the name" do
|
it "should Apachify the name" do
|
||||||
Apache::Config.apachify("test").should == "Test"
|
Apache::Config.apachify("test").should == "Test"
|
||||||
Apache::Config.apachify("test_full_name").should == "TestFullName"
|
Apache::Config.apachify("test_full_name").should == "TestFullName"
|
||||||
|
Apache::Config.apachify("ssl_option").should == "SSLOption"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should quoteize properly" do
|
it "should quoteize properly" do
|
||||||
@ -39,13 +40,13 @@ describe Apache::Config, "should handle the basics of Apache config" do
|
|||||||
it "should blockify a block" do
|
it "should blockify a block" do
|
||||||
Apache::Config.blockify("Tag", [ 'part', 'part2' ]) do
|
Apache::Config.blockify("Tag", [ 'part', 'part2' ]) do
|
||||||
something "goes here"
|
something "goes here"
|
||||||
end.should == ['<Tag "part" "part2">', ' Something "goes here"', '</Tag>']
|
end.should == ['', '<Tag "part" "part2">', ' Something "goes here"', '</Tag>']
|
||||||
|
|
||||||
Apache::Config.reset!
|
Apache::Config.reset!
|
||||||
|
|
||||||
Apache::Config.blockify("Tag", 'part') do
|
Apache::Config.blockify("Tag", 'part') do
|
||||||
something "goes here"
|
something "goes here"
|
||||||
end.should == ['<Tag "part">', ' Something "goes here"', '</Tag>']
|
end.should == ['', '<Tag "part">', ' Something "goes here"', '</Tag>']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should handle a build" do
|
it "should handle a build" do
|
||||||
|
@ -11,9 +11,17 @@ describe Apache::Master, "should provide basic helpers for configuration" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
Apache::Config.config.should == [
|
Apache::Config.config.should == [
|
||||||
|
'',
|
||||||
'LoadModule "this_module" "modules/mod_this.so"',
|
'LoadModule "this_module" "modules/mod_this.so"',
|
||||||
'LoadModule "that_module" "modules/mod_that.so"',
|
'LoadModule "that_module" "modules/mod_that.so"',
|
||||||
'LoadModule "my_module" "is here"',
|
'LoadModule "my_module" "is here"',
|
||||||
|
''
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should set up the runner" do
|
||||||
|
Apache::Config.runner('test', 'test2')
|
||||||
|
|
||||||
|
Apache::Config.config.should == [ 'User test', 'Group test2' ]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,9 +15,11 @@ describe Apache::Modules, "should build a list of modules" do
|
|||||||
Apache::Modules.build(:this, :that) do
|
Apache::Modules.build(:this, :that) do
|
||||||
mine "my_path"
|
mine "my_path"
|
||||||
end.should == [
|
end.should == [
|
||||||
|
'',
|
||||||
'LoadModule "this_module" "modules/mod_this.so"',
|
'LoadModule "this_module" "modules/mod_this.so"',
|
||||||
'LoadModule "that_module" "modules/mod_that.so"',
|
'LoadModule "that_module" "modules/mod_that.so"',
|
||||||
'LoadModule "mine_module" "my_path"'
|
'LoadModule "mine_module" "my_path"',
|
||||||
|
''
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user