Skip to content

Commit

Permalink
Merge pull request #704 from JCotton1123/fastcgi-resource
Browse files Browse the repository at this point in the history
Add fastcgi external server defined type
  • Loading branch information
Ashley Penney committed Jun 26, 2014
2 parents 7907c65 + 2ea49e1 commit c9a5404
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [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)
* [Defined Type: apache::fastcgi::server](#defined-type-fastcgi-server)
* [Virtual Host Examples - Demonstrations of some configuration options](#virtual-host-examples)
* [Load Balancing](#load-balancing)
* [Defined Type: apache::balancer](#defined-type-apachebalancer)
Expand Down Expand Up @@ -1627,6 +1628,56 @@ An array:

Specifies whether or not to use [SSLProxyEngine](http://httpd.apache.org/docs/current/mod/mod_ssl.html#sslproxyengine). Valid values are 'true' and 'false'. Defaults to 'false'.

####Defined Type: FastCGI Server

This type is intended for use with mod_fastcgi. It allows you to define one or more external FastCGI servers to handle specific file types.

Ex:

```puppet
apache::fastcgi::server { 'php':
host => '127.0.0.1:9000',
timeout => 15,
flush => false,
faux_path => '/var/www/php.fcgi',
alias => '/php.fcgi',
file_type => 'application/x-httpd-php'
}
```

Within your virtual host, you can then configure the specified file type to be handled by the fastcgi server specified above.

```puppet
apache::vhost { 'www':
...
custom_fragment = 'AddType application/x-httpd-php .php'
...
}
```

#####`host`

The hostname or IP address and TCP port number (1-65535) of the FastCGI server.

#####`timeout`

The number of seconds of FastCGI application inactivity allowed before the request is aborted and the event is logged (at the error LogLevel). The inactivity timer applies only as long as a connection is pending with the FastCGI application. If a request is queued to an application, but the application doesn't respond (by writing and flushing) within this period, the request will be aborted. If communication is complete with the application but incomplete with the client (the response is buffered), the timeout does not apply.

#####`flush`

Force a write to the client as data is received from the application. By default, mod_fastcgi buffers data in order to free the application as quickly as possible.

#####`faux_path`

`faux_path` does not have to exist in the local filesystem. URIs that Apache resolves to this filename will be handled by this external FastCGI application.

#####`alias`

A unique alias. This is used internally to link the action with the FastCGI server.

#####`file_type`

The MIME-type of the file's that will be processed by the FastCGI server.

###Virtual Host Examples

Expand Down
23 changes: 23 additions & 0 deletions manifests/fastcgi/server.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
define apache::fastcgi::server (
$host = '127.0.0.1:9000',
$timeout = 15,
$flush = false,
$faux_path = "/var/www/$name.fcgi",
$alias = "/$name.fcgi",
$file_type = 'application/x-httpd-php'
) {

Apache::Mod['fastcgi'] -> Apache::Fastcgi::Server["$title"]

file { "fastcgi-pool-$name.conf":
ensure => present,
path => "${::apache::confd_dir}/fastcgi-pool-$name.conf",
owner => 'root',
group => $::apache::params::root_group,
mode => '0644',
content => template('apache/fastcgi/server.erb'),
require => Exec["mkdir ${::apache::confd_dir}"],
before => File[$::apache::confd_dir],
notify => Service['httpd']
}
}
90 changes: 90 additions & 0 deletions spec/defines/fastcgi_server_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
require 'spec_helper'

describe 'apache::fastcgi::server', :type => :define do
let :pre_condition do
'include apache'
end
let :title do
'www'
end
describe 'os-dependent items' do
context "on RedHat based systems" do
let :default_facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
let :facts do default_facts end
it { should contain_class("apache") }
it { should contain_class("apache::mod::fastcgi") }
it { should contain_file("fastcgi-pool-#{title}.conf").with(
:ensure => 'present',
:path => "/etc/httpd/conf.d/fastcgi-pool-#{title}.conf"
) }
end
context "on Debian based systems" do
let :default_facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
let :facts do default_facts end
it { should contain_class("apache") }
it { should contain_class("apache::mod::fastcgi") }
it { should contain_file("fastcgi-pool-#{title}.conf").with(
:ensure => 'present',
:path => "/etc/apache2/conf.d/fastcgi-pool-#{title}.conf"
) }
end
context "on FreeBSD systems" do
let :default_facts do
{
:osfamily => 'FreeBSD',
:operatingsystemrelease => '9',
:concat_basedir => '/dne',
}
end
let :facts do default_facts end
it { should contain_class("apache") }
it { should contain_class("apache::mod::fastcgi") }
it { should contain_file("fastcgi-pool-#{title}.conf").with(
:ensure => 'present',
:path => "/usr/local/etc/apache22/Includes/fastcgi-pool-#{title}.conf"
) }
end
end
describe 'os-independent items' do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
describe ".conf content" do
let :params do
{
:host => '127.0.0.1:9001',
:timeout => 30,
:flush => true,
:faux_path => '/var/www/php-www.fcgi',
:alias => '/php-www.fcgi',
:file_type => 'application/x-httpd-php'
}
end
let :expected do
'FastCGIExternalServer /var/www/php-www.fcgi -idle-timeout 30 -flush -host 127.0.0.1:9001
Alias /php-www.fcgi /var/www/php-www.fcgi
Action application/x-httpd-php /php-www.fcgi
'
end
it do
should contain_file("fastcgi-pool-www.conf").with_content(expected)
end
end
end
end
3 changes: 3 additions & 0 deletions templates/fastcgi/server.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FastCGIExternalServer <%= @faux_path %> -idle-timeout <%= @timeout %> <%= if @flush then '-flush' end %> -host <%= @host %>
Alias <%= @alias %> <%= faux_path %>
Action <%= @file_type %> <%= @alias %>

0 comments on commit c9a5404

Please sign in to comment.