Commit d932ebc6 authored by Patrick J Cherry's avatar Patrick J Cherry
Browse files

httpd: Added ability to specify domains on command line for configure

This allows a single domain's config to be overridden/reset using
--force.
parent 57b3988e
......@@ -11,7 +11,10 @@ docs: man/symbiosis-httpd-configure.man man/symbiosis-httpd-logger.man man/symb
test:
$(MAKE) -C vhost-alias test
[ -z "`which ruby2.1`" ] || ruby2.1 -I ../common/lib -I lib/ test.d/t*.rb
.PHONY: test clean all docs
man/%.man: ./sbin/%
[ -d man ] || mkdir man
RUBYLIB=./lib:../common/lib $< --manual | sed -e 's/^=\+$$//' | txt2man -s 1 -t $(notdir $<) | sed -e 's/\\\\fB/\\fB/' > $@
......
......@@ -5,9 +5,9 @@
# symbiosis-httpd-configure - Auto-configure Apache2 sites with specified IPs
#
# SYNOPSIS
# symbiosis-httpd-configure [ --ssl-template | -s <file> ]
# [ --non-ssl-template | -t <file> ]
# [ --apache2-dir | -a <directory> ]
# symbiosis-httpd-configure [ --ssl-template | -s <file> ]
# [ --non-ssl-template | -t <file> ]
# [ --apache2-dir | -a <directory> ]
# [ --force | -f ] [ --no-reload | -n ]
# [ --help | -h ] [ --manual | -m ] [ --verbose | -v ]
#
......@@ -81,10 +81,10 @@ $RELOAD=false
# The root directory -- '/' by default.
#
root = "/"
non_ssl_template = nil
ssl_template = nil
mass_non_ssl_template = nil
mass_ssl_template = nil
non_ssl_template = nil
ssl_template = nil
mass_non_ssl_template = nil
mass_ssl_template = nil
apache2_dir = nil
no_reload = false
......@@ -207,11 +207,16 @@ unless apache_mass_hosting_enabled
verbose "Symbiosis automatic mass-hosting configuration disabled. Explicitly configuring all sites."
end
domains = Symbiosis::Domains.all(prefix)
if domains_to_configure.length > 0
domains = domains.select{|domain| domains_to_configure.include?(domain.name)}
end
#
# For each domain.
#
Symbiosis::Domains.each(prefix) do |domain|
domains.each do |domain|
verbose "Domain: #{domain.name}"
if domain.is_alias?
......@@ -219,7 +224,7 @@ Symbiosis::Domains.each(prefix) do |domain|
next
end
if apache_mass_hosting_enabled and domain.ips.any?{|ip| primary_ips.include?(ip)}
if apache_mass_hosting_enabled and domain.ips.any?{|ip| primary_ips.include?(ip)}
if domain.ssl_enabled?
verbose "\tThis site has SSL enabled, and is using the host's primary IPs -- continuing with SNI."
else
......@@ -250,7 +255,7 @@ end
unless this_config.is_a?(Symbiosis::ConfigFiles::Apache)
verbose "\tA valid configuration could not be created for this mass-hosting template. Skipping."
next
next
end
#
......@@ -282,7 +287,13 @@ end
filenames_available = configurations.collect{|c| c.filename }
filenames_enabled = filenames_available.collect{|filename| filename.sub("sites-available","sites-enabled") }
Dir.foreach(File.join(apache2_dir, "sites-enabled")) do |filename|
#
# No need to do anything here if there were domains on the command line
#
next if domains_to_configure.length >= 0
#
# Prepend full path before the filename
#
......@@ -296,7 +307,7 @@ Dir.foreach(File.join(apache2_dir, "sites-enabled")) do |filename|
next if File.directory?(filename)
begin
verbose "Configuration file: #{filename}"
verbose "Configuration file: #{filename}"
#
# We only deal with symlinks.
......@@ -322,7 +333,7 @@ Dir.foreach(File.join(apache2_dir, "sites-enabled")) do |filename|
verbose "\tConfiguration #{filename_source} not managed by Symbiosis -- skipping"
next
end
verbose "\tRemoving orphaned configuration file"
config.disable(filename, $FORCE)
......
......@@ -6,7 +6,6 @@ require 'tempfile'
require 'symbiosis/domain'
require 'symbiosis/domain/http'
require 'symbiosis/host'
require 'pp'
class TestSymbiosisHttpdConfigure < Test::Unit::TestCase
......@@ -71,7 +70,7 @@ class TestSymbiosisHttpdConfigure < Test::Unit::TestCase
system("#{@script} --root-dir #{@root} --no-reload")
assert_equal($?,0,"#{@script} exited with a non-zero status")
assert_equal(0,$?.exitstatus,"#{@script} exited with a non-zero status")
mass_hosting_files.each do |fn|
assert(File.exist?(fn), "File #{fn} missing")
......@@ -115,7 +114,7 @@ class TestSymbiosisHttpdConfigure < Test::Unit::TestCase
end
def test_site_pruning
#
#
# This is a standard file in sites-available. It should never be removed.
#
unmanaged_config = File.join(@apache2_dir,"sites-enabled","default")
......@@ -159,7 +158,7 @@ class TestSymbiosisHttpdConfigure < Test::Unit::TestCase
end
assert(!File.exist?(domain_conf_fn), "File #{domain_conf_fn} missing when it should have been generated.")
end
def test_bug_7593
......@@ -184,7 +183,7 @@ class TestSymbiosisHttpdConfigure < Test::Unit::TestCase
system("#{@script} --root-dir #{@root} --no-reload")
assert_equal($?,0,"#{@script} exited with a non-zero status")
assert_equal(0,$?.exitstatus,"#{@script} exited with a non-zero status")
conf_files.each do |fn|
assert(!File.exist?(fn), "File #{fn} present, when it shouldn't be.")
......@@ -192,4 +191,41 @@ class TestSymbiosisHttpdConfigure < Test::Unit::TestCase
end
def test_domains_on_command_line
domain = Symbiosis::Domain.new(nil, @prefix)
domain.create
name = domain.name
FileUtils.mkdir_p(domain.htdocs_dir)
domain2 = Symbiosis::Domain.new(nil, @prefix)
domain2.create
name2 = domain2.name
FileUtils.mkdir_p(domain2.htdocs_dir)
#
# These are the files we expect to be in place.
#
domain_conf_fn = File.join(@apache2_dir, "sites-enabled", domain.name+".conf")
domain2_conf_fn = File.join(@apache2_dir, "sites-enabled", domain2.name+".conf")
#
# Don't create a public/htdocs directory for this domain and
# disable mass hosting
#
FileUtils.touch("#{@root}/etc/symbiosis/apache.d/disabled.zz-mass-hosting")
system("#{@script} --root-dir #{@root} --no-reload #{domain.name}")
assert_equal(0,$?.exitstatus,"#{@script} exited with a non-zero status")
assert(File.exist?(domain_conf_fn), "File #{domain_conf_fn} is not present when it was on the cmd line.")
assert(!File.exist?(domain2_conf_fn), "File #{domain2_conf_fn} is present when it wasn't on the cmd line.")
system("#{@script} --root-dir #{@root} --no-reload #{domain2.name}")
assert(File.exist?(domain_conf_fn), "File #{domain_conf_fn} is not present when it was on the cmd line.")
assert(File.exist?(domain2_conf_fn), "File #{domain2_conf_fn} is present when it wasn't on the cmd line.")
system("#{@script} --root-dir #{@root} --no-reload #{domain2.name}")
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment