]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/openstacklib/manifests/wsgi/apache.pp
try with modules from master
[dsa-puppet.git] / 3rdparty / modules / openstacklib / manifests / wsgi / apache.pp
1 #
2 # Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
3 #
4 # Author: Emilien Macchi <emilien.macchi@enovance.com>
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
16 # under the License.
17 #
18 # == Class: openstacklib::wsgi::apache
19 #
20 # Serve a service with apache mod_wsgi
21 # When using this class you should disable your service.
22 #
23 # == Parameters
24 #
25 # [*service_name*]
26 #   (optional) Name of the service to run.
27 #   Example: nova-api
28 #   Defaults to $name
29 #
30 # [*servername*]
31 #   (optional) The servername for the virtualhost.
32 #   Defaults to $::fqdn
33 #
34 # [*bind_host*]
35 #   (optional) The host/ip address Apache will listen on.
36 #   Defaults to undef (listen on all ip addresses).
37 #
38 # [*bind_port*]
39 #   (optional) The port to listen.
40 #   Defaults to undef
41 #
42 # [*group*]
43 #   (optional) Group with permissions on the script
44 #   Defaults to undef
45 #
46 # [*path*]
47 #   (optional) The prefix for the endpoint.
48 #   Defaults to '/'
49 #
50 # [*priority*]
51 #   (optional) The priority for the vhost.
52 #   Defaults to '10'
53 #
54 # [*ssl*]
55 #   (optional) Use ssl ? (boolean)
56 #   Defaults to false
57 #
58 # [*ssl_cert*]
59 #   (optional) Path to SSL certificate
60 #   Default to apache::vhost 'ssl_*' defaults.
61 #
62 # [*ssl_key*]
63 #   (optional) Path to SSL key
64 #   Default to apache::vhost 'ssl_*' defaults.
65 #
66 # [*ssl_chain*]
67 #   (optional) SSL chain
68 #   Default to apache::vhost 'ssl_*' defaults.
69 #
70 # [*ssl_ca*]
71 #   (optional) Path to SSL certificate authority
72 #   Default to apache::vhost 'ssl_*' defaults.
73 #
74 # [*ssl_crl_path*]
75 #   (optional) Path to SSL certificate revocation list
76 #   Default to apache::vhost 'ssl_*' defaults.
77 #
78 # [*ssl_crl*]
79 #   (optional) SSL certificate revocation list name
80 #   Default to apache::vhost 'ssl_*' defaults.
81 #
82 # [*ssl_certs_dir*]
83 #   (optional) Path to SSL certificate directory
84 #   Default to apache::vhost 'ssl_*' defaults.
85 #
86 # [*threads*]
87 #   (optional) The number of threads for the vhost.
88 #   Defaults to $::processorcount
89 #
90 # [*user*]
91 #   (optional) User with permissions on the script
92 #   Defaults to undef
93 #
94 # [*workers*]
95 #   (optional) The number of workers for the vhost.
96 #   Defaults to '1'
97 #
98 # [*wsgi_daemon_process*]
99 #   (optional) Name of the WSGI daemon process.
100 #   Defaults to $name
101 #
102 # [*wsgi_process_group*]
103 #   (optional) Name of the WSGI process group.
104 #   Defaults to $name
105 #
106 # [*wsgi_script_dir*]
107 #   (optional) The directory path of the WSGI script.
108 #   Defaults to undef
109 #
110 # [*wsgi_script_file*]
111 #   (optional) The file path of the WSGI script.
112 #   Defaults to undef
113 #
114 # [*wsgi_script_source*]
115 #   (optional) The source of the WSGI script.
116 #   Defaults to undef
117 #
118 define openstacklib::wsgi::apache (
119   $service_name        = $name,
120   $bind_host           = undef,
121   $bind_port           = undef,
122   $group               = undef,
123   $path                = '/',
124   $priority            = '10',
125   $servername          = $::fqdn,
126   $ssl                 = false,
127   $ssl_ca              = undef,
128   $ssl_cert            = undef,
129   $ssl_certs_dir       = undef,
130   $ssl_chain           = undef,
131   $ssl_crl             = undef,
132   $ssl_crl_path        = undef,
133   $ssl_key             = undef,
134   $threads             = $::processorcount,
135   $user                = undef,
136   $workers             = 1,
137   $wsgi_daemon_process = $name,
138   $wsgi_process_group  = $name,
139   $wsgi_script_dir     = undef,
140   $wsgi_script_file    = undef,
141   $wsgi_script_source  = undef,
142 ) {
143
144   include ::apache
145   include ::apache::mod::wsgi
146   if $ssl {
147     include ::apache::mod::ssl
148   }
149
150   # Ensure there's no trailing '/' except if this is also the only character
151   $path_real = regsubst($path, '(^/.*)/$', '\1')
152
153   if !defined(File[$wsgi_script_dir]) {
154     file { $wsgi_script_dir:
155       ensure  => directory,
156       owner   => $user,
157       group   => $group,
158       require => Package['httpd'],
159     }
160   }
161
162   file { $service_name:
163     ensure  => file,
164     path    => "${wsgi_script_dir}/${wsgi_script_file}",
165     source  => $wsgi_script_source,
166     owner   => $user,
167     group   => $group,
168     mode    => '0644',
169     require => File[$wsgi_script_dir],
170   }
171
172   $wsgi_daemon_process_options = {
173     user      => $user,
174     group     => $group,
175     processes => $workers,
176     threads   => $threads,
177   }
178   $wsgi_script_aliases = hash([$path_real,"${wsgi_script_dir}/${wsgi_script_file}"])
179
180   ::apache::vhost { $service_name:
181     ensure                      => 'present',
182     servername                  => $servername,
183     ip                          => $bind_host,
184     port                        => $bind_port,
185     docroot                     => $wsgi_script_dir,
186     docroot_owner               => $user,
187     docroot_group               => $group,
188     priority                    => $priority,
189     ssl                         => $ssl,
190     ssl_cert                    => $ssl_cert,
191     ssl_key                     => $ssl_key,
192     ssl_chain                   => $ssl_chain,
193     ssl_ca                      => $ssl_ca,
194     ssl_crl_path                => $ssl_crl_path,
195     ssl_crl                     => $ssl_crl,
196     ssl_certs_dir               => $ssl_certs_dir,
197     wsgi_daemon_process         => $wsgi_daemon_process,
198     wsgi_daemon_process_options => $wsgi_daemon_process_options,
199     wsgi_process_group          => $wsgi_process_group,
200     wsgi_script_aliases         => $wsgi_script_aliases,
201     require                     => File[$service_name],
202   }
203
204 }