2014-12-30 13:06:12 -05:00
|
|
|
#
|
|
|
|
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
|
|
|
|
#
|
|
|
|
# Author: Emilien Macchi <emilien.macchi@enovance.com>
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
|
|
|
# == Class: openstacklib::wsgi::apache
|
|
|
|
#
|
|
|
|
# Serve a service with apache mod_wsgi
|
|
|
|
# When using this class you should disable your service.
|
|
|
|
#
|
|
|
|
# == Parameters
|
|
|
|
#
|
|
|
|
# [*service_name*]
|
|
|
|
# (optional) Name of the service to run.
|
|
|
|
# Example: nova-api
|
|
|
|
# Defaults to $name
|
|
|
|
#
|
|
|
|
# [*servername*]
|
|
|
|
# (optional) The servername for the virtualhost.
|
|
|
|
# Defaults to $::fqdn
|
|
|
|
#
|
|
|
|
# [*bind_host*]
|
|
|
|
# (optional) The host/ip address Apache will listen on.
|
|
|
|
# Defaults to undef (listen on all ip addresses).
|
|
|
|
#
|
|
|
|
# [*bind_port*]
|
|
|
|
# (optional) The port to listen.
|
|
|
|
# Defaults to undef
|
|
|
|
#
|
|
|
|
# [*group*]
|
|
|
|
# (optional) Group with permissions on the script
|
|
|
|
# Defaults to undef
|
|
|
|
#
|
|
|
|
# [*path*]
|
|
|
|
# (optional) The prefix for the endpoint.
|
|
|
|
# Defaults to '/'
|
|
|
|
#
|
|
|
|
# [*priority*]
|
|
|
|
# (optional) The priority for the vhost.
|
|
|
|
# Defaults to '10'
|
|
|
|
#
|
|
|
|
# [*ssl*]
|
|
|
|
# (optional) Use ssl ? (boolean)
|
|
|
|
# Defaults to false
|
|
|
|
#
|
|
|
|
# [*ssl_cert*]
|
|
|
|
# (optional) Path to SSL certificate
|
|
|
|
# Default to apache::vhost 'ssl_*' defaults.
|
|
|
|
#
|
|
|
|
# [*ssl_key*]
|
|
|
|
# (optional) Path to SSL key
|
|
|
|
# Default to apache::vhost 'ssl_*' defaults.
|
|
|
|
#
|
|
|
|
# [*ssl_chain*]
|
|
|
|
# (optional) SSL chain
|
|
|
|
# Default to apache::vhost 'ssl_*' defaults.
|
|
|
|
#
|
|
|
|
# [*ssl_ca*]
|
|
|
|
# (optional) Path to SSL certificate authority
|
|
|
|
# Default to apache::vhost 'ssl_*' defaults.
|
|
|
|
#
|
|
|
|
# [*ssl_crl_path*]
|
|
|
|
# (optional) Path to SSL certificate revocation list
|
|
|
|
# Default to apache::vhost 'ssl_*' defaults.
|
|
|
|
#
|
|
|
|
# [*ssl_crl*]
|
|
|
|
# (optional) SSL certificate revocation list name
|
|
|
|
# Default to apache::vhost 'ssl_*' defaults.
|
|
|
|
#
|
|
|
|
# [*ssl_certs_dir*]
|
|
|
|
# (optional) Path to SSL certificate directory
|
|
|
|
# Default to apache::vhost 'ssl_*' defaults.
|
|
|
|
#
|
|
|
|
# [*threads*]
|
|
|
|
# (optional) The number of threads for the vhost.
|
2017-09-19 14:53:15 +03:00
|
|
|
# Defaults to 1
|
2014-12-30 13:06:12 -05:00
|
|
|
#
|
|
|
|
# [*user*]
|
|
|
|
# (optional) User with permissions on the script
|
|
|
|
# Defaults to undef
|
|
|
|
#
|
|
|
|
# [*workers*]
|
|
|
|
# (optional) The number of workers for the vhost.
|
2017-09-19 14:53:15 +03:00
|
|
|
# Defaults to $::os_workers
|
2014-12-30 13:06:12 -05:00
|
|
|
#
|
2014-12-30 18:01:03 -05:00
|
|
|
# [*wsgi_daemon_process*]
|
|
|
|
# (optional) Name of the WSGI daemon process.
|
|
|
|
# Defaults to $name
|
|
|
|
#
|
2016-12-15 15:18:42 +08:00
|
|
|
# [*wsgi_process_display_name*]
|
|
|
|
# (optional) Name of the WSGI process display-name.
|
|
|
|
# Defaults to $name
|
|
|
|
#
|
2015-04-07 10:00:49 -04:00
|
|
|
# [*wsgi_process_group*]
|
2014-12-30 18:01:03 -05:00
|
|
|
# (optional) Name of the WSGI process group.
|
|
|
|
# Defaults to $name
|
|
|
|
#
|
|
|
|
# [*wsgi_script_dir*]
|
|
|
|
# (optional) The directory path of the WSGI script.
|
|
|
|
# Defaults to undef
|
|
|
|
#
|
|
|
|
# [*wsgi_script_file*]
|
|
|
|
# (optional) The file path of the WSGI script.
|
2014-12-30 13:06:12 -05:00
|
|
|
# Defaults to undef
|
|
|
|
#
|
2014-12-30 18:01:03 -05:00
|
|
|
# [*wsgi_script_source*]
|
2014-12-30 13:06:12 -05:00
|
|
|
# (optional) The source of the WSGI script.
|
|
|
|
# Defaults to undef
|
|
|
|
#
|
2015-10-08 13:18:19 +03:00
|
|
|
# [*wsgi_application_group*]
|
|
|
|
# (optional) The application group of the WSGI script.
|
|
|
|
# Defaults to '%{GLOBAL}'
|
|
|
|
#
|
|
|
|
# [*wsgi_pass_authorization*]
|
|
|
|
# (optional) Whether HTTP authorisation headers are passed through to a WSGI
|
|
|
|
# script when the equivalent HTTP request headers are present.
|
|
|
|
# Defaults to undef
|
|
|
|
#
|
2016-11-17 10:34:26 +02:00
|
|
|
# [*wsgi_chunked_request*]
|
|
|
|
# (optional) Makes the vhost allow chunked requests which is useful for
|
|
|
|
# handling TE (Transfer-Encoding), chunked or gzip. This sets the
|
|
|
|
# WSGIChunkedRequest option in the vhost.
|
|
|
|
# Defaults to undef
|
|
|
|
#
|
2017-06-24 16:30:13 +02:00
|
|
|
# [*custom_wsgi_process_options*]
|
|
|
|
# (optional) gives you the oportunity to add custom process options or to
|
|
|
|
# overwrite the default options for the WSGI process.
|
|
|
|
# eg. to use a virtual python environment for the WSGI process
|
|
|
|
# you could set it to:
|
|
|
|
# { python-path => '/my/python/virtualenv' }
|
|
|
|
# Defaults to {}
|
|
|
|
#
|
2015-09-01 16:42:26 +03:00
|
|
|
# [*vhost_custom_fragment*]
|
|
|
|
# (optional) Passes a string of custom configuration
|
|
|
|
# directives to be placed at the end of the vhost configuration.
|
|
|
|
# Defaults to undef.
|
|
|
|
#
|
2016-11-10 15:34:19 +02:00
|
|
|
# [*allow_encoded_slashes*]
|
|
|
|
# (optional) If set, uses apache's AllowEncodedSlashes option in the vhost.
|
|
|
|
# This option is passed to puppetlabs-apache, which accepts only 4
|
|
|
|
# options: undef, "on", "off" or "nodecode". This is thus validated in the
|
|
|
|
# underlying vhost resource.
|
|
|
|
# Defaults to undef.
|
|
|
|
#
|
2017-10-03 12:51:27 +03:00
|
|
|
# [*access_log_file*]
|
|
|
|
# The log file name for the virtualhost.
|
|
|
|
# Optional. Defaults to false.
|
|
|
|
#
|
|
|
|
# [*access_log_format*]
|
|
|
|
# The log format for the virtualhost.
|
|
|
|
# Optional. Defaults to false.
|
|
|
|
#
|
|
|
|
# [*error_log_file*]
|
|
|
|
# The error log file name for the virtualhost.
|
|
|
|
# Optional. Defaults to undef.
|
|
|
|
#
|
2014-12-30 13:06:12 -05:00
|
|
|
define openstacklib::wsgi::apache (
|
2017-06-24 16:30:13 +02:00
|
|
|
$service_name = $name,
|
|
|
|
$bind_host = undef,
|
|
|
|
$bind_port = undef,
|
|
|
|
$group = undef,
|
|
|
|
$path = '/',
|
|
|
|
$priority = '10',
|
|
|
|
$servername = $::fqdn,
|
|
|
|
$ssl = false,
|
|
|
|
$ssl_ca = undef,
|
|
|
|
$ssl_cert = undef,
|
|
|
|
$ssl_certs_dir = undef,
|
|
|
|
$ssl_chain = undef,
|
|
|
|
$ssl_crl = undef,
|
|
|
|
$ssl_crl_path = undef,
|
|
|
|
$ssl_key = undef,
|
2017-09-19 14:53:15 +03:00
|
|
|
$threads = 1,
|
2017-06-24 16:30:13 +02:00
|
|
|
$user = undef,
|
2017-09-19 14:53:15 +03:00
|
|
|
$workers = $::os_workers,
|
2017-06-24 16:30:13 +02:00
|
|
|
$wsgi_daemon_process = $name,
|
|
|
|
$wsgi_process_display_name = $name,
|
|
|
|
$wsgi_process_group = $name,
|
|
|
|
$wsgi_script_dir = undef,
|
|
|
|
$wsgi_script_file = undef,
|
|
|
|
$wsgi_script_source = undef,
|
|
|
|
$wsgi_application_group = '%{GLOBAL}',
|
|
|
|
$wsgi_pass_authorization = undef,
|
|
|
|
$wsgi_chunked_request = undef,
|
|
|
|
$custom_wsgi_process_options = {},
|
|
|
|
$vhost_custom_fragment = undef,
|
|
|
|
$allow_encoded_slashes = undef,
|
2017-10-03 12:51:27 +03:00
|
|
|
$access_log_file = false,
|
|
|
|
$access_log_format = false,
|
|
|
|
$error_log_file = undef,
|
2014-12-30 13:06:12 -05:00
|
|
|
) {
|
|
|
|
|
|
|
|
include ::apache
|
|
|
|
include ::apache::mod::wsgi
|
|
|
|
if $ssl {
|
|
|
|
include ::apache::mod::ssl
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ensure there's no trailing '/' except if this is also the only character
|
|
|
|
$path_real = regsubst($path, '(^/.*)/$', '\1')
|
|
|
|
|
2014-12-30 18:01:03 -05:00
|
|
|
if !defined(File[$wsgi_script_dir]) {
|
|
|
|
file { $wsgi_script_dir:
|
2017-07-11 15:59:37 +08:00
|
|
|
ensure => directory,
|
|
|
|
owner => $user,
|
|
|
|
group => $group,
|
2014-12-30 13:06:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-30 16:50:26 -05:00
|
|
|
file { $service_name:
|
2017-07-11 15:59:37 +08:00
|
|
|
ensure => file,
|
|
|
|
links => follow,
|
|
|
|
path => "${wsgi_script_dir}/${wsgi_script_file}",
|
|
|
|
source => $wsgi_script_source,
|
|
|
|
owner => $user,
|
|
|
|
group => $group,
|
|
|
|
mode => '0644',
|
2014-12-30 13:06:12 -05:00
|
|
|
}
|
|
|
|
|
2017-06-24 16:30:13 +02:00
|
|
|
$wsgi_daemon_process_options = merge (
|
|
|
|
{
|
|
|
|
user => $user,
|
|
|
|
group => $group,
|
|
|
|
processes => $workers,
|
|
|
|
threads => $threads,
|
|
|
|
display-name => $wsgi_process_display_name,
|
|
|
|
},
|
|
|
|
$custom_wsgi_process_options,
|
|
|
|
)
|
2014-12-30 18:01:03 -05:00
|
|
|
$wsgi_script_aliases = hash([$path_real,"${wsgi_script_dir}/${wsgi_script_file}"])
|
2014-12-30 13:06:12 -05:00
|
|
|
|
2014-12-30 16:50:26 -05:00
|
|
|
::apache::vhost { $service_name:
|
2014-12-30 13:06:12 -05:00
|
|
|
ensure => 'present',
|
|
|
|
servername => $servername,
|
|
|
|
ip => $bind_host,
|
|
|
|
port => $bind_port,
|
2014-12-30 18:01:03 -05:00
|
|
|
docroot => $wsgi_script_dir,
|
2014-12-30 13:06:12 -05:00
|
|
|
docroot_owner => $user,
|
|
|
|
docroot_group => $group,
|
|
|
|
priority => $priority,
|
2016-07-01 22:09:29 +00:00
|
|
|
setenvif => ['X-Forwarded-Proto https HTTPS=1'],
|
2014-12-30 13:06:12 -05:00
|
|
|
ssl => $ssl,
|
|
|
|
ssl_cert => $ssl_cert,
|
|
|
|
ssl_key => $ssl_key,
|
|
|
|
ssl_chain => $ssl_chain,
|
|
|
|
ssl_ca => $ssl_ca,
|
|
|
|
ssl_crl_path => $ssl_crl_path,
|
|
|
|
ssl_crl => $ssl_crl,
|
|
|
|
ssl_certs_dir => $ssl_certs_dir,
|
2014-12-30 18:01:03 -05:00
|
|
|
wsgi_daemon_process => $wsgi_daemon_process,
|
2014-12-30 13:06:12 -05:00
|
|
|
wsgi_daemon_process_options => $wsgi_daemon_process_options,
|
2014-12-30 18:01:03 -05:00
|
|
|
wsgi_process_group => $wsgi_process_group,
|
2014-12-30 13:06:12 -05:00
|
|
|
wsgi_script_aliases => $wsgi_script_aliases,
|
2015-10-08 13:18:19 +03:00
|
|
|
wsgi_application_group => $wsgi_application_group,
|
|
|
|
wsgi_pass_authorization => $wsgi_pass_authorization,
|
2016-11-17 10:34:26 +02:00
|
|
|
wsgi_chunked_request => $wsgi_chunked_request,
|
2015-09-01 16:42:26 +03:00
|
|
|
custom_fragment => $vhost_custom_fragment,
|
2016-11-10 15:34:19 +02:00
|
|
|
allow_encoded_slashes => $allow_encoded_slashes,
|
2017-10-03 12:51:27 +03:00
|
|
|
access_log_file => $access_log_file,
|
|
|
|
access_log_format => $access_log_format,
|
|
|
|
error_log_file => $error_log_file,
|
2014-12-30 13:06:12 -05:00
|
|
|
}
|
|
|
|
|
2017-07-13 14:32:57 -06:00
|
|
|
Package<| title == 'httpd' |>
|
2017-07-11 15:59:37 +08:00
|
|
|
~> File<| title == $wsgi_script_dir |>
|
2017-07-13 14:32:57 -06:00
|
|
|
~> File<| title == $service_name |>
|
2017-07-11 15:59:37 +08:00
|
|
|
~> Apache::Vhost<| title == $service_name |>
|
2014-12-30 13:06:12 -05:00
|
|
|
}
|