diff options
author | Joey Hess <joey@kitenet.net> | 2014-04-19 15:17:26 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-04-19 15:17:26 -0400 |
commit | 81f23cc9393f6caadb6e9c34055982becbeb6ec5 (patch) | |
tree | f0da641930315a94899a1c331c05bee9d32d07eb | |
parent | c9088cdffcddd79328b0f47245d54ebfb2fe6151 (diff) | |
parent | c8862f4811eeb557b53ffbe58255c307fe79614e (diff) |
Merge remote-tracking branch 'remotes/smcv/ready/apache24'
-rwxr-xr-x | ikisite | 57 | ||||
-rw-r--r-- | templates/apache-site.tmpl | 24 |
2 files changed, 72 insertions, 9 deletions
@@ -6,6 +6,20 @@ use strict; use IkiWiki; use IkiWiki::Hosting; +my $apache_before_2_4=undef; + +sub apache_before_2_4 { + return $apache_before_2_4 if defined $apache_before_2_4; + my $query_result = getshell('dpkg-query', '-W', 'apache2.2-common'); + if ($query_result =~ m/^apache2.2-common\s+2\.[012]\./) { + $apache_before_2_4=1; + } + else { + $apache_before_2_4=0; + } + return $apache_before_2_4; +} + sub meta_create { required => [qw{hostname}], options => [qw{type=s vcs=s wikiname=s owner=s admin=s adminemail=s createnonce!}], @@ -1611,7 +1625,7 @@ sub enable { # write and enable apache config file my $apache_site="ikisite-".$url->host; - my $apache_conf_file="/etc/apache2/sites-available/$apache_site"; + my $apache_conf_file="/etc/apache2/sites-available/$apache_site.conf"; outtemplate($apache_conf_file, "apache-site.tmpl", @apache_template_vars, # If an apache.conf.tmpl is available, @@ -1626,7 +1640,12 @@ sub enable { ); my %setup; $setup{$url->host}=1; - shell("a2ensite", $apache_site); + if (apache_before_2_4()) { + shell("a2ensite", "$apache_site.conf"); + } + else { + shell("a2ensite", $apache_site); + } # generate apache config files for alias urls, that redirect to the # main url @@ -1634,7 +1653,7 @@ sub enable { next if $setup{$alias}; $setup{$alias}=1; $apache_site="ikisite-$alias"; - $apache_conf_file="/etc/apache2/sites-available/$apache_site"; + $apache_conf_file="/etc/apache2/sites-available/$apache_site.conf"; outtemplate($apache_conf_file, "apache-sitealias.tmpl", suexec => (cgidir($hostname) =~ m!^/var/www!), user => $user, @@ -1650,7 +1669,12 @@ sub enable { https_url_escaped => quotemeta($httpsredirurl), @ssl_template_vars ); - shell("a2ensite", $apache_site); + if (apache_before_2_4()) { + shell("a2ensite", "$apache_site.conf"); + } + else { + shell("a2ensite", $apache_site); + } } # reload apache config @@ -1658,8 +1682,14 @@ sub enable { if ($@) { # avoid leaving apache in a broken state foreach my $site (keys %setup) { - shell("a2dissite", $site); + if (apache_before_2_4()) { + shell("a2dissite", "$site.conf"); + } + else { + shell("a2dissite", $site); + } } + shell("apache2ctl", "graceful"); error "apache2ctl graceful failed"; } @@ -1698,14 +1728,27 @@ sub disable { my $reload=0; foreach my $url (@urls) { my $apache_site="ikisite-".$url->host; - my $apache_conf_file="/etc/apache2/sites-available/$apache_site"; + my $apache_conf_file="/etc/apache2/sites-available/$apache_site.conf"; if (-e $apache_conf_file) { # inside guard because a2dissite fails if the config # file does not exist, and this needs to be idempotent - shell("a2dissite", $apache_site); + if (apache_before_2_4()) { + shell("a2dissite", "$apache_site.conf"); + } + else { + shell("a2dissite", $apache_site); + } unlink($apache_conf_file); $reload=1; } + # If we're now using Apache 2.4, there might be old versions + # from Apache 2.2 still lying around + foreach my $detritus ( + "/etc/apache2/sites-enabled/$apache_site", + "/etc/apache2/sites-available/$apache_site") { + unlink $detritus || error("unlink $detritus: $!"); + $reload=1; + } } shell("apache2ctl", "graceful") if $reload && ! $options{temporary}; diff --git a/templates/apache-site.tmpl b/templates/apache-site.tmpl index ec4a62a..f8855e9 100644 --- a/templates/apache-site.tmpl +++ b/templates/apache-site.tmpl @@ -23,14 +23,24 @@ <Directory <TMPL_VAR DESTDIR>> Options Indexes MultiViews<TMPL_UNLESS SUEXEC> ExecCGI</TMPL_UNLESS> AllowOverride None + <IfVersion < 2.4> Order allow,deny allow from all + </IfVersion> + <IfVersion >= 2.4> + Require all granted + </IfVersion> </Directory> - <Directory /var/www> + <Directory /var/www/<TMPL_VAR USER>> Options ExecCGI AllowOverride None + <IfVersion < 2.4> Order allow,deny allow from all + </IfVersion> + <IfVersion >= 2.4> + Require all granted + </IfVersion> </Directory> ScriptAlias /ikiwiki.cgi <TMPL_VAR CGIDIR>/ikiwiki.cgi @@ -71,14 +81,24 @@ <Directory <TMPL_VAR DESTDIR>> Options Indexes MultiViews<TMPL_UNLESS SUEXEC> ExecCGI</TMPL_UNLESS> AllowOverride None + <IfVersion < 2.4> Order allow,deny allow from all + </IfVersion> + <IfVersion >= 2.4> + Require all granted + </IfVersion> </Directory> - <Directory /var/www> + <Directory /var/www/<TMPL_VAR USER>> Options ExecCGI AllowOverride None + <IfVersion < 2.4> Order allow,deny allow from all + </IfVersion> + <IfVersion >= 2.4> + Require all granted + </IfVersion> </Directory> ScriptAlias /ikiwiki.cgi <TMPL_VAR CGIDIR>/ikiwiki.cgi |