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
|
define apache::site::manage(
$ensure = 'present',
$docroot = false,
$manage_docroot = true,
$owner = 'root',
$group = 'root',
$vhost = $name,
) {
case $ensure {
'present': {
if ($docroot != false) and ($manage_docroot == true) {
if !defined(File["${docroot}"]) {
file { "${docroot}":
ensure => present,
owner => $owner,
group => $group,
mode => '0755',
recurse => false,
}
}
if !defined(Exec["check_docroot_${docroot}"]) {
# Ensure parent folder exist
exec { "check_docroot_${docroot}":
command => "/bin/mkdir -p ${docroot}",
unless => "/bin/sh -c '[ -e ${docroot} ]'",
user => root,
before => File["${docroot}"],
}
}
}
exec { "/usr/sbin/a2ensite $vhost":
command => $::lsbdistcodename ? {
'wheezy' => "/usr/sbin/a2ensite $vhost.conf",
default => "/usr/sbin/a2ensite $vhost",
},
unless => "/bin/sh -c '[ -L ${apache::conf_sites}-enabled/$vhost.conf ] \
&& [ ${apache::conf_sites}-enabled/$vhost.conf -ef ${apache::conf_sites}-available/$vhost.conf ]'",
require => Apache::Site::Config[$name],
notify => Exec["reload-apache2"],
}
}
'absent': {
exec { "/usr/sbin/a2dissite $vhost":
command => $::lsbdistcodename ? {
'wheezy' => "/usr/sbin/a2dissite $vhost.conf",
default => "/usr/sbin/a2dissite $vhost",
},
onlyif => "/bin/sh -c '[ -L ${apache::conf_sites}-enabled/$vhost.conf ] \
&& [ ${apache::conf_sites}-enabled/$vhost.conf -ef ${apache::conf_sites}-available/$vhost.conf ]'",
require => Apache::Site::Config[$name],
notify => Exec["reload-apache2"],
}
file { "${apache::conf_sites}-enabled/$vhost.conf":
ensure => absent,
notify => Exec["reload-apache2"],
}
}
default: { err ("Unknown ensure value: '$ensure'") }
}
}
|