Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow environment variables when configuring FPM pools #650

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions manifests/fpm/pool.pp
Original file line number Diff line number Diff line change
Expand Up @@ -121,50 +121,50 @@
# '/etc/php5/fpm/pool.d' or '/etc/php-fpm.d'
#
define php::fpm::pool (
Enum['present', 'absent'] $ensure = 'present',
String[1] $listen = '127.0.0.1:9000',
Integer[-1] $listen_backlog = -1,
Optional[String[1]] $listen_allowed_clients = undef,
Optional[String[1]] $listen_owner = undef,
Optional[String[1]] $listen_group = undef,
Optional[Stdlib::Filemode] $listen_mode = undef,
String[1] $user = $php::fpm::config::user,
String[1] $group = $php::fpm::config::group,
Optional[String[1]] $apparmor_hat = undef,
String[1] $pm = 'dynamic',
Integer[1] $pm_max_children = 50,
Integer[0] $pm_start_servers = 5,
Integer[0] $pm_min_spare_servers = 5,
Integer[0] $pm_max_spare_servers = 35,
Integer[0] $pm_max_requests = 0,
Php::Duration $pm_process_idle_timeout = '10s',
Optional[Stdlib::Absolutepath] $pm_status_path = undef,
Optional[Stdlib::Absolutepath] $ping_path = undef,
String[1] $ping_response = 'pong',
Optional[Stdlib::Absolutepath] $access_log = undef,
String[1] $access_log_format = '"%R - %u %t \"%m %r\" %s"',
Php::Duration $request_terminate_timeout = 0,
Php::Duration $request_slowlog_timeout = 0,
Array[String[1]] $security_limit_extensions = [],
Stdlib::Absolutepath $slowlog = "/var/log/php-fpm/${name}-slow.log",
String[1] $template = 'php/fpm/pool.conf.erb',
Optional[Integer] $rlimit_files = undef,
Optional[Integer] $rlimit_core = undef,
Optional[Stdlib::Absolutepath] $chroot = undef,
Optional[Stdlib::Absolutepath] $chdir = undef,
Enum['yes', 'no'] $catch_workers_output = 'no',
Optional[String[1]] $include = undef,
Array[String[1]] $env = [],
Hash $env_value = {},
Boolean $clear_env = true,
Hash $options = {},
Hash $php_value = {},
Hash $php_flag = {},
Hash $php_admin_value = {},
Hash $php_admin_flag = {},
Array[String[1]] $php_directives = [],
String[1] $root_group = $php::params::root_group,
Optional[Stdlib::Absolutepath] $base_dir = undef,
Enum['present', 'absent'] $ensure = 'present',
String[1] $listen = '127.0.0.1:9000',
Integer[-1] $listen_backlog = -1,
Optional[String[1]] $listen_allowed_clients = undef,
Optional[String[1]] $listen_owner = undef,
Optional[String[1]] $listen_group = undef,
Optional[Stdlib::Filemode] $listen_mode = undef,
String[1] $user = $php::fpm::config::user,
String[1] $group = $php::fpm::config::group,
Optional[String[1]] $apparmor_hat = undef,
String[1] $pm = 'dynamic',
Variant[Integer[1], Php::EnvString] $pm_max_children = 50,
Variant[Integer[0], Php::EnvString] $pm_start_servers = 5,
Variant[Integer[0], Php::EnvString] $pm_min_spare_servers = 5,
Variant[Integer[0], Php::EnvString] $pm_max_spare_servers = 35,
Variant[Integer[0], Php::EnvString] $pm_max_requests = 0,
Variant[Php::Duration, Php::EnvString] $pm_process_idle_timeout = '10s',
Optional[Stdlib::Absolutepath] $pm_status_path = undef,
Optional[Stdlib::Absolutepath] $ping_path = undef,
String[1] $ping_response = 'pong',
Optional[Stdlib::Absolutepath] $access_log = undef,
String[1] $access_log_format = '"%R - %u %t \"%m %r\" %s"',
Variant[Php::Duration, Php::EnvString] $request_terminate_timeout = 0,
Variant[Php::Duration, Php::EnvString] $request_slowlog_timeout = 0,
Array[String[1]] $security_limit_extensions = [],
Stdlib::Absolutepath $slowlog = "/var/log/php-fpm/${name}-slow.log",
String[1] $template = 'php/fpm/pool.conf.erb',
Optional[Integer] $rlimit_files = undef,
Optional[Integer] $rlimit_core = undef,
Optional[Stdlib::Absolutepath] $chroot = undef,
Optional[Stdlib::Absolutepath] $chdir = undef,
Enum['yes', 'no'] $catch_workers_output = 'no',
Optional[String[1]] $include = undef,
Array[String[1]] $env = [],
Hash $env_value = {},
Boolean $clear_env = true,
Hash $options = {},
Hash $php_value = {},
Hash $php_flag = {},
Hash $php_admin_value = {},
Hash $php_admin_flag = {},
Array[String[1]] $php_directives = [],
String[1] $root_group = $php::params::root_group,
Optional[Stdlib::Absolutepath] $base_dir = undef,
) {
# The base class must be included first because it is used by parameter defaults
if ! defined(Class['php']) {
Expand Down
20 changes: 20 additions & 0 deletions spec/defines/fpm_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@
end
let(:pre_condition) { 'include php' }

context 'with environment based config' do
let(:title) { 'env-config' }
let(:params) do
{
pm_max_children: '${PM_MAX_CHILDREN}',
pm_start_servers: '${PM_START_SERVERS}',
pm_min_spare_servers: '${PM_MIN_SPARE_SERVERS}',
pm_max_spare_servers: '${PM_MAX_SPARE_SERVERS}',
pm_max_requests: '${PM_MAX_REQUESTS}',
pm_process_idle_timeout: '${PM_PROCESS_IDLE_TIMEOUT}',
request_terminate_timeout: '${REQUEST_TERMINATE_TIMEOUT}',
request_slowlog_timeout: '${REQUEST_SLOWLOG_TIMEOUT}',
}
end

it {
is_expected.to compile
}
end

case facts[:os]['name']
when 'Debian'
context 'plain config' do
Expand Down
1 change: 1 addition & 0 deletions types/envstring.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Php::EnvString = Pattern[/\$\{[\w]+\}/]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The square brackets look redundant and I think we should anchor the regexp:

Suggested change
type Php::EnvString = Pattern[/\$\{[\w]+\}/]
type Php::EnvString = Pattern[/\A\$\{\w+\}\z/]