Skip to content

Commit

Permalink
Merge pull request #716 from ekohl/fcgid
Browse files Browse the repository at this point in the history
Add fcgid options
  • Loading branch information
igalic committed Jun 3, 2014
2 parents 222f61e + 179fb89 commit b02d29e
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 5 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [Class: apache::mod::php](#class-apachemodphp)
* [Class: apache::mod::ssl](#class-apachemodssl)
* [Class: apache::mod::wsgi](#class-apachemodwsgi)
* [Class: apache::mod::fcgid](#class-apachemodfcgid)
* [Defined Type: apache::vhost](#defined-type-apachevhost)
* [Parameter: `directories` for apache::vhost](#parameter-directories-for-apachevhost)
* [SSL parameters for apache::vhost](#ssl-parameters-for-apachevhost)
Expand Down Expand Up @@ -582,6 +583,41 @@ For customized parameters, which tell Apache how Python is currently configured

More information about [WSGI](http://modwsgi.readthedocs.org/en/latest/).

####Class: `apache::mod::fcgid`

Installs and configures mod_fcgid.

The class makes no effort to list all available options, but rather uses an options hash to allow for ultimate flexibility:

```puppet
class { 'apache::mod::fcgid':
options => {
'FcgidIPCDir' => '/var/run/fcgidsock',
'SharememPath' => '/var/run/fcgid_shm',
'AddHandler' => 'fcgid-script .fcgi',
},
}
```

For a full list op options, see the [official mod_fcgid documentation](https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html).

It is also possible to set the FcgidWrapper per directory per vhost. You must ensure the fcgid module is loaded because there is no auto loading.

```puppet
include apache::mod::fcgid
apache::vhost { 'example.org':
docroot => '/var/www/html',
directories => {
path => '/var/www/html',
fcgiwrapper => {
command => '/usr/local/bin/fcgiwrapper',
}
},
}
```

See [FcgidWrapper documentation](https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidwrapper) for more information.

####Defined Type: `apache::vhost`

The Apache module allows a lot of flexibility in the setup and configuration of virtual hosts. This flexibility is due, in part, to `vhost`'s being a defined resource type, which allows it to be evaluated multiple times with different parameters.
Expand Down
15 changes: 14 additions & 1 deletion manifests/mod/fcgid.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
class apache::mod::fcgid {
class apache::mod::fcgid(
$options = {},
) {
::apache::mod { 'fcgid': }

# Template uses:
# - $options
file { 'fcgid.conf':
ensure => file,
path => "${::apache::mod_dir}/fcgid.conf",
content => template('apache/mod/fcgid.conf.erb'),
require => Exec["mkdir ${::apache::mod_dir}"],
before => File[$::apache::mod_dir],
notify => Service['httpd'],
}
}
62 changes: 62 additions & 0 deletions spec/acceptance/mod_fcgid_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'spec_helper_acceptance'

describe 'apache::mod::fcgid class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
case fact('osfamily')
when 'Debian'
# Not implemented
when 'RedHat'
context "default fcgid config" do
it 'succeeds in puppeting fcgid' do
pp = <<-EOS
class { 'epel': } # mod_fcgid lives in epel
class { 'apache': }
class { 'apache::mod::php': } # For /usr/bin/php-cgi
class { 'apache::mod::fcgid':
options => {
'FcgidIPCDir' => '/var/run/fcgidsock',
},
}
apache::vhost { 'fcgid.example.com':
port => '80',
docroot => '/var/www/fcgid',
directories => {
path => '/var/www/fcgid',
options => '+ExecCGI',
addhandlers => {
handler => 'fcgid-script',
extensions => '.php',
},
fcgiwrapper => {
command => '/usr/bin/php-cgi',
suffix => '.php',
}
},
}
file { '/var/www/fcgid/index.php':
ensure => file,
owner => 'root',
group => 'root',
content => "<?php echo 'Hello world'; ?>\\n",
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe service('httpd') do
it { should be_enabled }
it { should be_running }
end

it 'should answer to fcgid.example.com' do
shell("/usr/bin/curl -H 'Host: fcgid.example.com' 127.0.0.1:80") do |r|
r.stdout.should =~ /^Hello world$/
r.exit_code.should == 0
end
end

it 'should run a php-cgi process' do
shell("pgrep -u apache php-cgi", :acceptable_exit_codes => [0])
end
end
end
end
40 changes: 36 additions & 4 deletions spec/classes/mod/fcgid_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
describe 'apache::mod::fcgid', :type => :class do
require 'spec_helper'

describe 'apache::mod::fcgid' do
let :pre_condition do
'include apache'
end

context "on a Debian OS" do
let :facts do
{
Expand All @@ -14,6 +17,7 @@
it { should contain_apache__mod('fcgid') }
it { should contain_package("libapache2-mod-fcgid") }
end

context "on a RedHat OS" do
let :facts do
{
Expand All @@ -22,10 +26,37 @@
:concat_basedir => '/dne',
}
end
it { should contain_class("apache::params") }
it { should contain_apache__mod('fcgid') }
it { should contain_package("mod_fcgid") }

describe 'without parameters' do
it { should contain_class("apache::params") }
it { should contain_apache__mod('fcgid') }
it { should contain_package("mod_fcgid") }
end

describe 'with parameters' do
let :params do {
:options => {
'FcgidIPCDir' => '/var/run/fcgidsock',
'SharememPath' => '/var/run/fcgid_shm',
'FcgidMinProcessesPerClass' => '0',
'AddHandler' => 'fcgid-script .fcgi',
}
} end

it 'should contain the correct config' do
content = subject.resource('file', 'fcgid.conf').send(:parameters)[:content]
content.split("\n").reject { |c| c =~ /(^#|^$)/ }.should == [
'<IfModule mod_fcgid.c>',
' AddHandler fcgid-script .fcgi',
' FcgidIPCDir /var/run/fcgidsock',
' FcgidMinProcessesPerClass 0',
' SharememPath /var/run/fcgid_shm',
'</IfModule>',
]
end
end
end

context "on a FreeBSD OS" do
let :facts do
{
Expand All @@ -34,6 +65,7 @@
:concat_basedir => '/dne',
}
end

it { should contain_class("apache::params") }
it { should contain_apache__mod('fcgid') }
it { should contain_package("www/mod_fcgid") }
Expand Down
36 changes: 36 additions & 0 deletions spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,42 @@
end
end

describe 'fcgid directory options' do
describe 'No fcgiwrapper' do
let :params do
default_params.merge({
:directories => { 'path' => '/srv/www' },
})
end

it { should_not contain_file("25-#{title}.conf").with_content(%r{FcgidWrapper}) }
end

describe 'Only a command' do
let :params do
default_params.merge({
:directories => { 'path' => '/srv/www',
'fcgiwrapper' => { 'command' => '/usr/local/bin/fcgiwrapper' },
}
})
end

it { should contain_file("25-#{title}.conf").with_content(%r{^ FcgidWrapper /usr/local/bin/fcgiwrapper $}) }
end

describe 'All parameters' do
let :params do
default_params.merge({
:directories => { 'path' => '/srv/www',
'fcgiwrapper' => { 'command' => '/usr/local/bin/fcgiwrapper', 'suffix' => '.php', 'virtual' => 'virtual' },
}
})
end

it { should contain_file("25-#{title}.conf").with_content(%r{^ FcgidWrapper /usr/local/bin/fcgiwrapper .php virtual$}) }
end
end

describe 'various ip/port combos' do
describe 'when ip_based is true' do
let :params do default_params.merge({ :ip_based => true }) end
Expand Down
5 changes: 5 additions & 0 deletions templates/mod/fcgid.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<IfModule mod_fcgid.c>
<% @options.sort_by {|key, value| key}.each do |key, value| -%>
<%= key %> <%= value %>
<% end -%>
</IfModule>
3 changes: 3 additions & 0 deletions templates/vhost/_directories.erb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
<%- if directory['suphp'] and @suphp_engine == 'on' -%>
suPHP_UserGroup <%= directory['suphp']['user'] %> <%= directory['suphp']['group'] %>
<%- end -%>
<%- if directory['fcgiwrapper'] -%>
FcgidWrapper <%= directory['fcgiwrapper']['command'] %> <%= directory['fcgiwrapper']['suffix'] %> <%= directory['fcgiwrapper']['virtual'] %>
<%- end -%>
<%- if directory['custom_fragment'] -%>
<%= directory['custom_fragment'] %>
<%- end -%>
Expand Down

0 comments on commit b02d29e

Please sign in to comment.