summaryrefslogtreecommitdiffstats
path: root/puppet/modules/network_test_server/manifests/linux/apache2.pp
blob: bed5c41ab961a527381fabbd29eda151c9a0be0c (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
class network_test_server::linux::apache2 {
    package {
        "apache2":          ensure  =>  present;
    }

    $spdy_filename = $::architecture ? {
        i386    => "mod-spdy-beta_current_i386.deb",
        x86     => "mod-spdy-beta_current_i386.deb",
        x86_64  => "mod-spdy-beta_current_amd64.deb",
        amd64   => "mod-spdy-beta_current_amd64.deb",
        default => "mod-spdy-beta_current_amd64.deb",
    }

    exec {
        "download SPDY module":
            command => "/usr/bin/wget https://dl-ssl.google.com/dl/linux/direct/$spdy_filename --directory-prefix=/home/qt-test-server",
            creates => "/home/qt-test-server/$spdy_filename",
            notify  =>  Service["apache2"]
        ;
    }

    package {
        "mod_spdy":
            ensure   => installed,
            provider => dpkg,
            source   => "/home/qt-test-server/$spdy_filename",
            notify   => Service["apache2"],
            require  => [ Package["apache2"], Exec["download SPDY module"] ]
    }

    service { "apache2":
        enable  =>  true,
        ensure  =>  running,
        require =>  Package["apache2", "mod_spdy"],
    }

    apache2_module {
        "ssl":              ensure  =>  present;
        "dav_fs":           ensure  =>  present;
        "headers":          ensure  =>  present;

        # enable mod_deflate, but make sure our custom deflate.conf is
        # deployed first (otherwise all requests will be gzipped and
        # tests will fail when they receive an unexpected Content-Length)
        "deflate":
            ensure  =>  present,
            require =>  File["/etc/apache2/mods-available/deflate.conf"],
        ;

        # used by auth-digest paths
        "auth_digest":      ensure  =>  present;
    }

    apache2_conf {
        "main.conf":    ensure  =>  present;
        "security":     ensure  =>  present;
        "ssl.conf":     ensure  =>  present;
        "dav.conf":     ensure  =>  present;
    }

    # replace the default mod_deflate conf with an empty one.
    #
    # The distro package typically provides a configuration for mod_deflate
    # which turns on deflate for all paths, for HTML and text formats.
    #
    # We do not want this, because it makes our Content-Length less predictable.
    # So, we'll make sure the global configuration does _not_ turn on deflate.
    #
    # Certain paths on the server will explicitly enable deflate (e.g. look for
    # `DEFLATE' in other .conf files)
    file { "/etc/apache2/mods-available/deflate.conf":
        source  =>  "puppet:///modules/network_test_server/config/apache2/deflate.conf",
        require =>  Package["apache2"],
        notify  =>  Service["apache2"],
    }

    # dav upload directory
    file { "/home/writeables/dav":
        ensure  =>  directory,
        mode    =>  1777,
        require =>  File["/home/writeables"],
    }

    # Disable all of the "default" apache2 sites
    exec { "/usr/sbin/a2dissite '*'":
        onlyif  =>  "/bin/sh -c 'test $(ls /etc/apache2/sites-enabled | wc -l) -gt 0'",
        require =>  Package["apache2"],
        notify  =>  Service["apache2"],
    }

    # Deploy docs and scripts
    file { "/home/qt-test-server/www":
        ensure  =>  directory,
        recurse =>  remote,
        source  =>  "puppet:///modules/network_test_server/www",
        require =>  User["qt-test-server"],
    }

    # Hardcoded timestamps for testing purposes on a few files
    file_timestamp {
        "/home/qt-test-server/www/htdocs/fluke.gif":
            timestamp   =>  '2007-05-22 12:04:57 GMT',
            require =>  File["/home/qt-test-server/www"],
        ;
        "/home/qt-test-server/www/htdocs/index.html":
            timestamp   =>  '2008-11-15 13:52 GMT',
            require =>  File["/home/qt-test-server/www"],
        ;
    }

    # Some testdata created by special means
    exec {
        "make mediumfile":
            command => "/bin/dd if=/dev/zero of=/home/qt-test-server/www/htdocs/mediumfile bs=1 count=0 seek=10000000",
            creates =>  "/home/qt-test-server/www/htdocs/mediumfile",
            require =>  File["/home/qt-test-server/www"],
        ;
    }

}

# Set mtime on file to given timestamp
# timestamp may be anything parseable by /bin/date
# FIXME: add support directly to puppet for this
define file_timestamp($timestamp) {
    $since_epoch = generate("/bin/sh", "-c", "date -d '$timestamp' +%s | tr -d '\n'")
    exec {
        "/usr/bin/touch -d '@$since_epoch' '$name'":
            onlyif  =>  "/bin/sh -c \"/usr/bin/stat -c '%Y' '$name' | /bin/grep -v -q '$since_epoch'\"",
        ;
    }   
}

define apache2_module($ensure) {
    if $ensure == "present" {
        exec { "/usr/sbin/a2enmod $name":
            creates =>  "/etc/apache2/mods-enabled/$name.load",
            require =>  Package["apache2"],
            notify  =>  Service["apache2"],
        }
    }
    else {
        exec { "/usr/sbin/a2dismod $name":
            onlyif  =>  "/usr/bin/test -e /etc/apache2/mods-enabled/$name.load",
            require =>  Package["apache2"],
            notify  =>  Service["apache2"],
        }
    }
}

define apache2_site($ensure) {
    if $ensure == "present" {
    }
    else {
        exec { "/usr/sbin/a2dismod $name":
            onlyif  =>  "/usr/bin/test -e /etc/apache2/mods-enabled/$name.load",
            require =>  Package["apache2"],
            notify  =>  Service["apache2"],
        }
    }
}

define apache2_conf($ensure) {
    if $ensure == "present" {
        file { "/etc/apache2/conf.d/$name":
            source  =>  "puppet:///modules/network_test_server/config/apache2/$name",
            require =>  Package["apache2"],
            notify  =>  Service["apache2"],
        }
    }
    else {
        file { "/etc/apache2/conf.d/$name":
            ensure  =>  absent,
            notify  =>  Service["apache2"],
        }
    }
}