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

fpm: manage runtime- and log directory based on params #688

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
7 changes: 6 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,9 @@ Configure php-fpm service
[*error_log*]
Path to error log file. If it's set to "syslog", log is
sent to syslogd instead of being written in a local file.
The base directory will be managed if it is a directory
dedicated to PHP (i.e. has "php" in its name and is not
a shared location like /var/log)

[*log_level*]
The php-fpm log level
Expand Down Expand Up @@ -1160,7 +1163,9 @@ Configure php-fpm service
UNIX group of the root user

[*pid_file*]
Path to fpm pid file
Path to fpm pid file. The base directory will be managed if it is
a directory dedicated to PHP (i.e. has "php" in its name and is not
a shared location like /var/run)

[*manage_run_dir*]
Manage the run directory
Expand Down
20 changes: 14 additions & 6 deletions manifests/fpm/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
# [*error_log*]
# Path to error log file. If it's set to "syslog", log is
# sent to syslogd instead of being written in a local file.
# The base directory will be managed if it is a directory
# dedicated to PHP (i.e. has "php" in its name and is not
# a shared location like /var/log)
#
# [*log_level*]
# The php-fpm log level
Expand Down Expand Up @@ -68,7 +71,9 @@
# UNIX group of the root user
#
# [*pid_file*]
# Path to fpm pid file
# Path to fpm pid file. The base directory will be managed if it is
# a directory dedicated to PHP (i.e. has "php" in its name and is not
# a shared location like /var/run)
#
# [*manage_run_dir*]
# Manage the run directory
Expand Down Expand Up @@ -100,6 +105,9 @@
) inherits php::params {
assert_private()

$pid_dir = dirname($pid_file)
$log_dir = dirname($error_log)

file { $config_file:
ensure => file,
content => template('php/fpm/php-fpm.conf.erb'),
Expand All @@ -108,23 +116,23 @@
mode => '0644',
}

if $manage_run_dir {
file { '/var/run/php-fpm':
if $manage_run_dir and 'php' in $pid_dir {
file { $pid_dir:
ensure => directory,
owner => 'root',
group => $root_group,
mode => '0755',
}
}

ensure_resource('file', '/var/log/php-fpm/',
{
if $error_log != 'syslog' and 'php' in $log_dir {
file { $log_dir:
ensure => directory,
owner => 'root',
group => $root_group,
mode => $log_dir_mode,
}
)
}

file { $pool_base_dir:
ensure => directory,
Expand Down
64 changes: 64 additions & 0 deletions spec/classes/php_fpm_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,70 @@
)
end
end

describe 'manages a log directory' do
context 'with dedicated path' do
let(:params) do
{
error_log: '/var/log/php/fpm.log',
}
end

it do
is_expected.to contain_file('/var/log/php')
end
end

context 'without dedicated path' do
let(:params) do
{
error_log: '/var/log/php-fpm.log',
}
end

it do
is_expected.not_to contain_file('/var/log')
end
end

context 'without syslog logging' do
let(:params) do
{
error_log: 'syslog',
}
end

it do
is_expected.not_to contain_file('syslog')
end
end
end

describe 'manages a runtime directory' do
context 'with dedicated path' do
let(:params) do
{
pid_file: '/var/run/php/fpm.pid',
}
end

it do
is_expected.to contain_file('/var/run/php')
end
end

context 'without dedicated path' do
let(:params) do
{
pid_file: '/var/run/fpm.pid',
}
end

it do
is_expected.not_to contain_file('/var/run')
end
end
end
end
end
end
Loading