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

Systemd on-demand socket-based activation #81

Open
wants to merge 19 commits 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
44 changes: 44 additions & 0 deletions manifests/fpm/systemd-daemon.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Class: php::fpm::systemd-daemon
#
# Install the PHP FPM daemon. See php::fpm::systemd-socket-conf for configuring its pools.
#
# Sample Usage:
# include php::fpm::systemd-daemon
#
class php::fpm::systemd-daemon (
$ensure = 'present',
$package_name = $::php::params::fpm_package_name,
$fpm_pool_dir = $::php::params::fpm_pool_dir,
$fpm_conf_dir = $::php::params::fpm_conf_dir,
$owner = 'apache',
$group = 'apache',
) inherits ::php::params {

# Hack-ish to default to user for group too
$group_final = $group ? {
false => $owner,
default => $group,
}

package { $package_name: ensure => $ensure }

if ( $ensure != 'absent' ) {
file { "/var/run/php-fpm":
ensure => 'directory',
owner => 'root',
group => 'root',
mode => '0775',
}

# Create "/var/run/php-fpm/php-systemd/" as group-writable because the daemon does not start as root
file { "/var/run/php-fpm/php-systemd/":
ensure => 'directory',
owner => $owner,
group => $group_final,
mode => '0775',
}

}

}

132 changes: 132 additions & 0 deletions manifests/fpm/systemd-socket-conf.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Define: php::fpm::systemd-socket-conf
#
# PHP FPM pool configuration definition. Note that the original php-fpm package
# includes a pre-configured one called 'www' so you should either use that name
# in order to override it, or "ensure => absent" it.
#
# Sample Usage:
# php::fpm::systemd-socket-conf { 'www': ensure => absent }
# php::fpm::systemd-socket-conf { 'customer1':
# listen => '/var/run/php-fpm/customer1.socket',
# listen_port => 9001,
# user => 'customer1',
# }
# php::fpm::systemd-socket-conf { 'customer2':
# listen => '/var/run/php-fpm/customer1.socket',
# listen_port => 9002,
# user => 'customer2',
# }
#
define php::fpm::systemd-socket-conf (
$ensure = 'present',
$package_name = undef,
$service_name = undef,
$user = 'apache',
$group = undef,
$listen = undef,
$listen_address = '127.0.0.1',
$listen_port = '9000',
# Puppet does not allow dots in variable names
$listen_backlog = '-1',
$listen_owner = undef,
$listen_group = undef,
$listen_mode = undef,
$listen_allowed_clients = '127.0.0.1',
$process_priority = undef,
$pm = 'dynamic',
$pm_max_children = '50',
$pm_start_servers = '5',
$pm_min_spare_servers = '5',
$pm_max_spare_servers = '35',
$pm_process_idle_timeout = undef,
$pm_max_requests = '0',
$pm_status_path = undef,
$ping_path = undef,
$ping_response = 'pong',
$slowlog = "/var/log/php-fpm/${name}-slow.log",
$request_slowlog_timeout = undef,
$request_terminate_timeout = undef,
$rlimit_files = undef,
$rlimit_core = undef,
$chroot = undef,
$chdir = undef,
$catch_workers_output = 'no',
$security_limit_extensions = undef,
$env = [],
$env_value = {},
$php_value = {},
$php_flag = {},
$php_admin_value = {},
$php_admin_flag = {},
$php_directives = [],
$error_log = true,
$systemd_service_path = $::php::params::systemd_service_path,
$fpm_binary = $::php::params::fpm_binary,
$fpm_pool_dir = $::php::params::fpm_pool_dir,
) {

include '::php::params'

$pool = $title

# Hack-ish to default to user for group too
$group_final = $group ? { undef => $user, default => $group }

# This is much easier from classes which inherit params...
$fpm_package_name = $package_name ? {
undef => $::php::params::fpm_package_name,
default => $package_name,
}

# Create systemd socket
file { "${systemd_service_path}/php-fpm-${pool}.socket":
ensure => $ensure,
content => template('php/fpm/pool.socket.erb'),
owner => 'root',
group => 'root',
mode => '0644',
require => Package[$fpm_package_name],
}

$socket_service_name = "php-fpm-${pool}.socket"

service { $socket_service_name:
ensure => running,
enable => true,
start => "systemctl start ${socket_service_name}",
stop => "systemctl stop ${socket_service_name}",
status => "systemctl status ${socket_service_name}",
subscribe => File["${systemd_service_path}/php-fpm-${pool}.socket"],
require => File["${systemd_service_path}/php-fpm-${pool}.service"],
}

# Create per-pool service
$systemd_service_name = "php-fpm-${pool}.service"
file { "${systemd_service_path}/php-fpm-${pool}.service":
ensure => $ensure,
content => template('php/fpm/pool.service.erb'),
owner => 'root',
group => 'root',
mode => '0644',
}

service { $systemd_service_name:
enable => true,
start => "systemctl start ${systemd_service_name}",
stop => "systemctl stop ${systemd_service_name}",
status => "systemctl status $systemd_service_name}",
subscribe => Service[$socket_service_name],
require => File["${systemd_service_path}/php-fpm-${pool}.service"],
}

file { "${fpm_pool_dir}/${pool}.conf":
ensure => $ensure,
content => template('php/fpm/pool-systemd.conf.erb'),
owner => 'root',
group => 'root',
mode => '0644',
notify => Service[$systemd_service_name],
}

}

4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
$httpd_package_name = 'apache2'
$httpd_service_name = 'apache2'
$httpd_conf_dir = '/etc/apache2/conf.d'
$systemd_service_path = '/lib/systemd/system'
$fpm_binary = '/usr/sbin/php5-fpm'
}
default: {
$php_package_name = 'php'
Expand All @@ -37,6 +39,8 @@
$httpd_package_name = 'httpd'
$httpd_service_name = 'httpd'
$httpd_conf_dir = '/etc/httpd/conf.d'
$systemd_service_path = '/usr/lib/systemd/system'
$fpm_binary = '/sbin/php-fpm'
}
}
}
Loading