Skip to content

Commit 0d5e0be

Browse files
committed
Fix wsgi_daemon_process to support hash data type
The README states wsgi_daemon_process is a hash data type however the ERB template interpolates it as a string. As this type it currently cannot accept multiple daemon processes per vhost, and requires wsgi_daemon_process_options to manage parameters. This commit adds logic to the parameter to support this data type while maintaining original functionality. The data type allows for multiple daemons per vhost, and deprecates wsgi_daemon_process_options.
1 parent ae502ab commit 0d5e0be

5 files changed

Lines changed: 34 additions & 18 deletions

File tree

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,13 @@ apache::vhost { 'wsgi.example.com':
561561
port => '80',
562562
docroot => '/var/www/pythonapp',
563563
wsgi_application_group => '%{GLOBAL}',
564-
wsgi_daemon_process => 'wsgi',
565-
wsgi_daemon_process_options => {
566-
processes => '2',
567-
threads => '15',
568-
display-name => '%{GROUP}',
564+
wsgi_daemon_process => {
565+
'wsgi' => {
566+
processes => '2',
567+
threads => '15',
568+
display-name => '%{GROUP}',
569+
},
570+
'foo' => {},
569571
},
570572
wsgi_import_script => '/var/www/demo.wsgi',
571573
wsgi_import_script_options => {
@@ -4853,7 +4855,7 @@ apache::vhost { 'subdomain.loc':
48534855
Sets up a virtual host with [WSGI](https://github.com/GrahamDumpleton/mod_wsgi).
48544856

48554857
* `wsgi_daemon_process`: A hash that sets the name of the WSGI daemon, accepting [certain keys](http://modwsgi.readthedocs.org/en/latest/configuration-directives/WSGIDaemonProcess.html). Default: `undef`.
4856-
* `wsgi_daemon_process_options`. _Optional._ Default: `undef`.
4858+
* `wsgi_daemon_process_options`. _Optional._ Default: `undef`. **Deprecated:** Please add values inside Hash `wsgi_daemon_process`.
48574859
* `wsgi_process_group`: Sets the group ID that the virtual host runs under. Default: `undef`.
48584860
* `wsgi_script_aliases`: Requires a hash of web paths to filesystem .wsgi paths. Default: `undef`.
48594861
* `wsgi_script_aliases_match`: Requires a hash of web path regexes to filesystem .wsgi paths. Default: `undef`
@@ -4866,12 +4868,14 @@ An example virtual host configuration with WSGI:
48664868
apache::vhost { 'wsgi.example.com':
48674869
port => '80',
48684870
docroot => '/var/www/pythonapp',
4869-
wsgi_daemon_process => 'wsgi',
4870-
wsgi_daemon_process_options =>
4871-
{ processes => '2',
4871+
wsgi_daemon_process => {
4872+
'wsgi' => {
4873+
processes => '2',
48724874
threads => '15',
48734875
display-name => '%{GROUP}',
4874-
},
4876+
},
4877+
'foo' => {},
4878+
},
48754879
wsgi_process_group => 'wsgi',
48764880
wsgi_script_aliases => { '/' => '/var/www/demo.wsgi' },
48774881
wsgi_chunked_request => 'On',

manifests/vhost.pp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
$block = [],
115115
Enum['absent', 'present'] $ensure = 'present',
116116
$wsgi_application_group = undef,
117-
$wsgi_daemon_process = undef,
117+
Optional[Variant[String,Hash]] $wsgi_daemon_process = undef,
118118
Optional[Hash] $wsgi_daemon_process_options = undef,
119119
$wsgi_import_script = undef,
120120
Optional[Hash] $wsgi_import_script_options = undef,
@@ -933,6 +933,9 @@
933933
# - $wsgi_process_group
934934
# - $wsgi_script_aliases
935935
# - $wsgi_pass_authorization
936+
if $wsgi_daemon_process_options {
937+
deprecation('apache::vhost::wsgi_daemon_process_options', 'This parameter is deprecated. Please add values inside Hash `wsgi_daemon_process`.')
938+
}
936939
if $wsgi_application_group or $wsgi_daemon_process or ($wsgi_import_script and $wsgi_import_script_options) or $wsgi_process_group or ($wsgi_script_aliases and ! empty($wsgi_script_aliases)) or $wsgi_pass_authorization {
937940
concat::fragment { "${name}-wsgi":
938941
target => "${priority_real}${filename}.conf",

spec/acceptance/vhost_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ class { 'apache::mod::wsgi': }
15101510
apache::vhost { 'test.server':
15111511
docroot => '/tmp',
15121512
wsgi_application_group => '%{GLOBAL}',
1513-
wsgi_daemon_process => 'wsgi',
1513+
wsgi_daemon_process => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} },
15141514
wsgi_daemon_process_options => {processes => '2'},
15151515
wsgi_process_group => 'nobody',
15161516
wsgi_script_aliases => { '/test' => '/test1' },
@@ -1531,7 +1531,7 @@ class { 'apache::mod::wsgi': }
15311531
apache::vhost { 'test.server':
15321532
docroot => '/tmp',
15331533
wsgi_application_group => '%{GLOBAL}',
1534-
wsgi_daemon_process => 'wsgi',
1534+
wsgi_daemon_process => { 'wsgi' => { 'python-home' => '/usr' }, 'foo' => {} },
15351535
wsgi_daemon_process_options => {processes => '2'},
15361536
wsgi_import_script => '/test1',
15371537
wsgi_import_script_options => { application-group => '%{GLOBAL}', process-group => 'wsgi' },
@@ -1549,7 +1549,8 @@ class { 'apache::mod::wsgi': }
15491549
describe file("#{$vhost_dir}/25-test.server.conf") do
15501550
it { is_expected.to be_file }
15511551
it { is_expected.to contain 'WSGIApplicationGroup %{GLOBAL}' }
1552-
it { is_expected.to contain 'WSGIDaemonProcess wsgi processes=2' }
1552+
it { is_expected.to contain 'WSGIDaemonProcess foo' }
1553+
it { is_expected.to contain 'WSGIDaemonProcess wsgi python-home=/usr' }
15531554
it { is_expected.to contain 'WSGIImportScript /test1 application-group=%{GLOBAL} process-group=wsgi' }
15541555
it { is_expected.to contain 'WSGIProcessGroup nobody' }
15551556
it { is_expected.to contain 'WSGIScriptAlias /test "/test1"' }

spec/defines/vhost_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
'setenvifnocase' => 'REMOTE_ADDR ^127.0.0.1 localhost=true',
321321
'block' => 'scm',
322322
'wsgi_application_group' => '%{GLOBAL}',
323-
'wsgi_daemon_process' => 'wsgi',
323+
'wsgi_daemon_process' => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} },
324324
'wsgi_daemon_process_options' => {
325325
'processes' => '2',
326326
'threads' => '15',
@@ -1691,7 +1691,7 @@
16911691
let :params do
16921692
{
16931693
'docroot' => '/rspec/docroot',
1694-
'wsgi_daemon_process' => 'wsgi',
1694+
'wsgi_daemon_process' => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} },
16951695
}
16961696
end
16971697

templates/vhost/_wsgi.erb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
<% if @wsgi_application_group -%>
66
WSGIApplicationGroup <%= @wsgi_application_group %>
77
<% end -%>
8-
<% if @wsgi_daemon_process and @wsgi_daemon_process_options -%>
8+
<% if @wsgi_daemon_process.is_a? String and @wsgi_daemon_process_options -%>
99
WSGIDaemonProcess <%= @wsgi_daemon_process %> <%= @wsgi_daemon_process_options.collect { |k,v| "#{k}=#{v}"}.sort.join(' ') %>
10-
<% elsif @wsgi_daemon_process and !@wsgi_daemon_process_options -%>
10+
<% elsif @wsgi_daemon_process.is_a? String and !@wsgi_daemon_process_options -%>
1111
WSGIDaemonProcess <%= @wsgi_daemon_process %>
12+
<% elsif @wsgi_daemon_process.is_a? Hash -%>
13+
<%- @wsgi_daemon_process.each do |key, val| -%>
14+
<%- if val.empty? -%>
15+
WSGIDaemonProcess <%= key %>
16+
<%- else -%>
17+
WSGIDaemonProcess <%= key %> <%= val.collect { |k,v| "#{k}=#{v}"}.sort.join(' ') %>
18+
<% end -%>
19+
<% end -%>
1220
<% end -%>
1321
<% if @wsgi_import_script and @wsgi_import_script_options -%>
1422
WSGIImportScript <%= @wsgi_import_script %> <%= @wsgi_import_script_options.collect { |k,v| "#{k}=#{v}"}.sort.join(' ') %>

0 commit comments

Comments
 (0)