summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifests/init.pp75
1 files changed, 59 insertions, 16 deletions
diff --git a/manifests/init.pp b/manifests/init.pp
index 14f4ecc..8df883b 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -18,9 +18,16 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
+#
+# Using code from Debian Apache2 recipe:
+#
+# http://reductivelabs.com/trac/puppet/wiki/Recipes/DebianApache2Recipe
+#
# TODO: log level, log files, etc
-# TODO: better variable names, enable value overwriting
+
+$apache2_sites = "/etc/apache2/sites"
+$apache2_mods = "/etc/apache2/mods"
+$apache2_macros = "/etc/apache2/conf.d/macros"
class apache {
@@ -29,18 +36,25 @@ class apache {
ensure => installed,
}
+ package { "mod_macro":
+ name => "libapache2-mod-macro",
+ ensure => installed,
+ }
+
service { "apache":
- ensure => running,
- require => Package["apache"],
+ ensure => running,
+ require => Package["apache"],
+ hasstatus => true,
+ hasrestart => true,
}
module { "macro":
ensure => present,
- require => "libapache2-mod-macro",
+ require => "mod_macro",
}
# apache mod_macro configuration
- file { "/etc/apache2/conf.d/macros":
+ file { "${apache2_macros}":
ensure => present,
content => template('apache/macros.erb'),
owner => root,
@@ -62,31 +76,51 @@ class apache {
# TODO: ensure folders exist with right modes and ownership
define website($ensure = present, $docroot = false, $redirect = false,
$protocol = 'http', $server_alias = false, $use = false) {
- file { "/etc/apache2/sites-available/$title":
+ file { "${apache2_sites}-available/$title":
ensure => $ensure,
content => template('apache/website.erb'),
owner => root,
group => root,
mode => 0644,
- require => File["/etc/apache2/conf.d/macros"],
+ require => File["${apache2_macros}"],
notify => Service["apache"],
}
$status = $ensure ? {
- 'present' => "/etc/apache2/sites-available/$title",
+ 'present' => "${apache2_sites}-available/$title",
default => 'absent',
}
- file { "/etc/apache2/sites-enabled/$title":
- ensure => $status,
- owner => root,
- group => root,
- require => File["/etc/apache2/sites-available/$title"],
- notify => Service["apache"],
+ # Enable the site without a2ensite
+ #file { "/etc/apache2/sites-enabled/$title":
+ # ensure => $status,
+ # owner => root,
+ # group => root,
+ # require => File["${apache2_sites}-available/$title"],
+ # notify => Service["apache"],
+ #}
+
+ case $ensure {
+ 'present': {
+ exec { "/usr/sbin/a2ensite $name":
+ unless => "/bin/sh -c '[ -L ${apache2_sites}-enabled/$name ] \
+ && [ ${apache2_sites}-enabled/$name -ef ${apache2_sites}-available/$name ]'",
+ notify => Exec["reload-apache2"],
+ require => Package[$require],
+ }
+ }
+ 'absent': {
+ exec { "/usr/sbin/a2dissite $name":
+ onlyif => "/bin/sh -c '[ -L ${apache2_sites}-enabled/$name ] \
+ && [ ${apache2_sites}-enabled/$name -ef ${apache2_sites}-available/$name ]'",
+ notify => Exec["reload-apache2"],
+ require => Package["apache2"],
+ }
+ }
+ default: { err ( "Unknown ensure value: '$ensure'" ) }
}
}
- # Code from http://reductivelabs.com/trac/puppet/wiki/Recipes/DebianApache2Recipe
# Define an apache2 module. Debian packages place the module config
# into /etc/apache2/mods-available.
#
@@ -115,6 +149,15 @@ class apache {
}
}
+ # Notify this when apache needs a reload. This is only needed when
+ # sites are added or removed, since a full restart then would be
+ # a waste of time. When the module-config changes, a force-reload is
+ # needed.
+ exec { "reload-apache2":
+ command => "/etc/init.d/apache2 reload",
+ refreshonly => true,
+ }
+
exec { "force-reload-apache2":
command => "/etc/init.d/apache2 force-reload",
refreshonly => true,