Skip to content

Commit

Permalink
Add the ability to show diffs when checking Apache configurations
Browse files Browse the repository at this point in the history
Closes #48
  • Loading branch information
Patrick J Cherry committed Jul 7, 2017
1 parent 2f56ec4 commit 977a1c9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion httpd/debian/control
Expand Up @@ -9,7 +9,7 @@ XS-Ruby-Versions: all

Package: symbiosis-httpd
Architecture: all
Depends: apache2, libapache2-mod-php7.0, webalizer, libapache2-mod-vhost-bytemark (>= 2015:0101), ${misc:Depends}, symbiosis-common (>= 2017:0328), ruby | ruby-interpreter, ruby-eventmachine
Depends: apache2, libapache2-mod-php7.0, webalizer, libapache2-mod-vhost-bytemark (>= 2015:0101), ${misc:Depends}, symbiosis-common (>= 2017:0328), ruby | ruby-interpreter, ruby-eventmachine, ruby-diffy
Recommends: php7.0-mysql | php7.0-mysqli | php7.0-mysqlnd, php7.0-curl, php7.0-imagick, php7.0-mcrypt, php7.0-mhash, php7.0-xmlrpc, php7.0-gd, geoip-database
Description: Tools to manage Apache virtual hosting in Symbiosis
This package contains tools to manage the virtual hosting of websites
Expand Down
16 changes: 15 additions & 1 deletion httpd/lib/symbiosis/config_files/apache.rb
Expand Up @@ -2,6 +2,7 @@
require 'symbiosis/domain/http'
require 'symbiosis/host'
require 'tempfile'
require 'diffy'

module Symbiosis
module ConfigFiles
Expand Down Expand Up @@ -36,6 +37,19 @@ def ok?
end
end

def diff
config = self.generate_config(self.template)

tempfile = Tempfile.new(File.basename(self.filename))
tempfile.puts(config)
tempfile.close(false)

fn = ( File.exists?(self.filename) ? self.filename : '/dev/null' )

Diffy::Diff.new(fn, tempfile.path, :source => 'files', :include_diff_info => true)
ensure
tmpfile.unlink
end

#
# This checks a site has its config file linked into the sites-enabled
Expand Down Expand Up @@ -275,7 +289,7 @@ def mandatory_ssl?
false
end
end

#
# This returns the FQDN
#
Expand Down
18 changes: 18 additions & 0 deletions httpd/sbin/symbiosis-httpd-configure
Expand Up @@ -33,6 +33,9 @@
# non-SSL sites. Defaults to
# /etc/symbiosis/apache.d/zz-mass-hosting.template.erb
#
# --diff-only, -d Show the differences in the new configuration, without
# making any changes.
#
# --force, -f Force the re-creation of all sites.
#
# --no-reload, -n Do not reload Apache even if changes have taken place.
Expand Down Expand Up @@ -120,12 +123,14 @@ mass_non_ssl_template = nil
mass_ssl_template = nil
apache2_dir = nil
no_reload = false
diff_only = false

opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--manual', '-m', GetoptLong::NO_ARGUMENT ],
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
[ '--force', '-f', GetoptLong::NO_ARGUMENT ],
[ '--diff-only', '-d', GetoptLong::NO_ARGUMENT ],
[ '--no-reload', '-n', GetoptLong::NO_ARGUMENT],
[ '--no-restart', '-N', GetoptLong::NO_ARGUMENT],
[ '--ssl-template', '-s', GetoptLong::REQUIRED_ARGUMENT ],
Expand Down Expand Up @@ -156,6 +161,8 @@ begin
# This is a legacy option.
when '--no-restart'
no_reload = true
when '--diff-only'
diff_only = true
when '--help'
help = true
when '--manual'
Expand Down Expand Up @@ -442,6 +449,17 @@ configurations.each do |config|
# This gets apache2 to check the configuration using a temporary file.
#
if recreate

#
# If we're only showing the diff, then check the config, and continue to
# the next domain.
#
if diff_only
puts config.diff.to_s(:color)
puts "\tW: Apache has rejected this configuration change" unless config.ok?
next
end

if config.ok?

verbose "\tWriting configuration"
Expand Down

0 comments on commit 977a1c9

Please sign in to comment.