1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#
# Puppet module for Apache
#
# This module is distributed under the GNU Affero General Public License:
#
# Backup module for puppet
# Copyright (C) 2009 Sarava Group
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# 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/>.
# TODO: log level, log files, etc
# TODO: better variable names, enable value overwriting
class apache {
package { "apache":
name => "apache2",
ensure => installed,
}
service { "apache":
ensure => running,
require => Package["apache"],
}
module { "macro":
ensure => present,
require => "libapache2-mod-macro",
}
# apache mod_macro configuration
file { "/etc/apache2/conf.d/macros":
ensure => present,
content => template('apache/macros.erb'),
owner => root,
group => root,
mode => 0644,
require => Module["macro"],
notify => Service["apache"],
}
# prepare variables to use in templates
case $apache_sites_folder {
'': { $apache_sites_folder = '/var/www/sites' }
}
case $apache_www_folder {
'': { $apache_www_folder= '/var/www' }
}
# 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":
ensure => $ensure,
content => template('apache/website.erb'),
owner => root,
group => root,
mode => 0644,
require => File["/etc/apache2/conf.d/macros"],
notify => Service["apache"],
}
$status = $ensure ? {
'present' => "/etc/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"],
}
}
# 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.
#
# You can add a custom require (string) if the module depends on
# packages that aren't part of the default apache2 package. Because of
# the package dependencies, apache2 will automagically be included.
define module ( $ensure = 'present', $require = 'apache2' ) {
case $ensure {
'present' : {
exec { "/usr/sbin/a2enmod $name":
unless => "/bin/sh -c '[ -L ${apache2_mods}-enabled/${name}.load ] \
&& [ ${apache2_mods}-enabled/${name}.load -ef ${apache2_mods}-available/${name}.load ]'",
notify => Exec["force-reload-apache2"],
require => Package[$require],
}
}
'absent': {
exec { "/usr/sbin/a2dismod $name":
onlyif => "/bin/sh -c '[ -L ${apache2_mods}-enabled/${name}.load ] \
&& [ ${apache2_mods}-enabled/${name}.load -ef ${apache2_mods}-available/${name}.load ]'",
notify => Exec["force-reload-apache2"],
require => Package["apache2"],
}
}
default: { err ( "Unknown ensure value: '$ensure'" ) }
}
}
exec { "force-reload-apache2":
command => "/etc/init.d/apache2 force-reload",
refreshonly => true,
}
}
|