forked from bigcommerce/puppet-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.pp
215 lines (195 loc) · 6.04 KB
/
extension.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# Install a PHP extension package
#
# === Parameters
#
# [*ensure*]
# The ensure of the package to install
# Could be "latest", "installed" or a pinned version
#
# [*package_prefix*]
# Prefix to prepend to the package name for the package provider
#
# [*provider*]
# The provider used to install the package
# Could be "pecl", "apt", "dpkg" or any other OS package provider
# If set to "none", no package will be installed
#
# [*source*]
# The source to install the extension from. Possible values
# depend on the *provider* used
#
# [*pecl_source*]
# The pecl source channel to install pecl package from
# Superseded by *source*
#
# [*so_name*]
# The DSO name of the package (e.g. opcache for zendopcache)
#
# [*php_api_version*]
# This parameter is used to build the full path to the extension
# directory for zend_extension in PHP < 5.5 (e.g. 20100525)
#
# [*header_packages*]
# System packages dependencies to install for extensions (e.g. for
# memcached libmemcached-dev on Debian)
#
# [*compiler_packages*]
# System packages dependencies to install for compiling extensions
# (e.g. build-essential on Debian)
#
# [*zend*]
# Boolean parameter, whether to load extension as zend_extension.
# Defaults to false.
#
# [*settings*]
# Nested hash of global config parameters for php.ini
#
# [*settings_prefix*]
# Boolean/String parameter, whether to prefix all setting keys with
# the extension name or specified name. Defaults to false.
#
# [*sapi*]
# String parameter, whether to specify ALL sapi or a specific sapi.
# Defaults to ALL.
#
# [*responsefile*]
# File containing answers for interactive extension setup. Supported
# *providers*: pear, pecl.
#
define php::extension (
$ensure = 'installed',
$provider = undef,
$source = undef,
$pecl_source = undef,
$so_name = $name,
$php_api_version = undef,
$package_prefix = $::php::package_prefix,
$header_packages = [],
$compiler_packages = $::php::params::compiler_packages,
$zend = false,
$settings = {},
$settings_prefix = false,
$sapi = 'ALL',
$responsefile = undef,
) {
if ! defined(Class['php']) {
warning('php::extension is private')
}
validate_string($ensure)
validate_string($package_prefix)
validate_string($so_name)
validate_string($php_api_version)
validate_string($sapi)
validate_array($header_packages)
validate_bool($zend)
if $source and $pecl_source {
fail('Only one of $source and $pecl_source can be specified.')
}
if $source {
$real_source = $source
}
else {
$real_source = $pecl_source
}
if $provider != 'none' {
case $provider {
'pecl': { $real_package = $title }
'pear': { $real_package = $title }
default: { $real_package = "${package_prefix}${title}" }
}
unless empty($header_packages) {
ensure_resource('package', $header_packages)
Package[$header_packages] -> Package[$real_package]
}
if $provider == 'pecl' or $provider == 'pear' {
ensure_packages( [ $real_package ], {
ensure => $ensure,
provider => $provider,
source => $real_source,
responsefile => $responsefile,
require => [
Class['::php::pear'],
Class['::php::dev'],
],
})
unless empty($compiler_packages) {
ensure_resource('package', $compiler_packages)
Package[$compiler_packages] -> Package[$real_package]
}
}
else {
if $responsefile != undef {
warning("responsefile param is not supported by php::extension provider ${provider}")
}
ensure_packages( [ $real_package ], {
ensure => $ensure,
provider => $provider,
source => $real_source,
})
}
$package_depends = "Package[${real_package}]"
} else {
$package_depends = undef
}
if $zend == true {
$extension_key = 'zend_extension'
if $php_api_version != undef {
$module_path = "/usr/lib/php5/${php_api_version}/"
}
else {
$module_path = undef
}
}
else {
$extension_key = 'extension'
$module_path = undef
}
if $so_name != $name {
$lowercase_title = $so_name
}
else {
$lowercase_title = downcase($title)
}
# Ensure "<extension>." prefix is present in setting keys if requested
if $settings_prefix {
if is_string($settings_prefix) {
$full_settings_prefix = $settings_prefix
} else {
$full_settings_prefix = $lowercase_title
}
$full_settings = ensure_prefix($settings, "${full_settings_prefix}.")
} else {
$full_settings = $settings
}
$final_settings = deep_merge(
{"${extension_key}" => "${module_path}${so_name}.so"},
$full_settings
)
$config_root_ini = pick_default($::php::config_root_ini, $::php::params::config_root_ini)
::php::config { $title:
file => "${config_root_ini}/${lowercase_title}.ini",
config => $final_settings,
require => $package_depends,
}
# Ubuntu/Debian systems use the mods-available folder. We need to enable
# settings files ourselves with php5enmod command.
$ext_tool_enable = pick_default($::php::ext_tool_enable, $::php::params::ext_tool_enable)
$ext_tool_query = pick_default($::php::ext_tool_query, $::php::params::ext_tool_query)
$ext_tool_enabled = pick_default($::php::ext_tool_enabled, $::php::params::ext_tool_enabled)
if $::osfamily == 'Debian' and $ext_tool_enabled {
$cmd = "${ext_tool_enable} -s ${sapi} ${lowercase_title}"
# If enabling for all SAPIs, use phpquery to generate a list of installed SAPIs
# Which is then iterated using xargs to check if the module is enabled for that SAPI
$sapi_list_cmd = $sapi ? {
'ALL' => "${ext_tool_query} -S",
default => "${ext_tool_query} -s ${sapi}",
}
exec { $cmd:
onlyif => "${sapi_list_cmd} | xargs -d'\\n' -n1 ${ext_tool_query} -m ${so_name} -s | /bin/grep 'No module matches ${so_name}'",
require => ::Php::Config[$title],
}
if $::php::fpm {
Package[$::php::fpm::package] ~> Exec[$cmd]
}
}
}