Skip to content
This repository was archived by the owner on Oct 11, 2018. It is now read-only.

Commit 59760d6

Browse files
authored
Enable extension (#162)
* Mix and match various proposals. * Parameters classes must be included. refs #142 * Added doc blox and assert_private. refs #148
1 parent 8d088d1 commit 59760d6

File tree

3 files changed

+164
-1
lines changed

3 files changed

+164
-1
lines changed

manifests/extension.pp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
# [*source*]
2424
# The path to the deb package to install
2525
#
26+
# [*sapis*]
27+
# An array of PHP SAPIs for which extension should be installed. This
28+
# parameters applies to PECL extensions only.
29+
# @see http://php.net/manual/en/function.php-sapi-name.php
30+
#
31+
# [*priority*]
32+
# Module loading priority. Default is 20. .
33+
# @see http://www.brandonchecketts.com/archives/getting-ubuntu-14-04-php5enmod-to-understand-module-priority
34+
#
2635
# === Variables
2736
#
2837
# [*php_ensure*]
@@ -49,6 +58,14 @@
4958
# source => "/path/to/libgearman8_1.1.7-1_amd64.deb";
5059
# }
5160
#
61+
# php::extension { 'gearman':
62+
# ensure => "latest",
63+
# package => "gearman",
64+
# provider => "pecl",
65+
# sapis => ['cli', 'fpm'],
66+
# priority_=> 30
67+
# }
68+
#
5269
# === Authors
5370
#
5471
# Christian "Jippi" Winther <jippignu@gmail.com>
@@ -62,7 +79,9 @@
6279
$package,
6380
$provider = undef,
6481
$pipe = undef,
65-
$source = undef
82+
$source = undef,
83+
$sapis = ['cli', 'fpm', 'apache2'],
84+
$priority = 20,
6685
) {
6786

6887
if $provider == 'pecl' {
@@ -72,6 +91,13 @@
7291
source => $source,
7392
pipe => $pipe;
7493
}
94+
$uniqe_sapis = suffix($sapis, $package)
95+
php::sapi { $uniqe_sapis:
96+
extension => $package,
97+
ensure => $ensure,
98+
priority => $priority,
99+
require => Package[$package],
100+
}
75101
} elsif $provider == 'dpkg' {
76102
package { $package:
77103
ensure => $ensure,

manifests/extension/disenable.pp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# == Type: php::extension::disenable
2+
#
3+
# Enables a PHP extension installed using PECL
4+
#
5+
# === Parameters
6+
#
7+
# [*extension*]
8+
# The name of extension to enable or disenable
9+
#
10+
# [*ensure*]
11+
# The ensure of the package to install
12+
# Could be "latest", "installed", pinned version or "absent"
13+
#
14+
# [*priority*]
15+
# Integer indicateing loading order
16+
#
17+
# === Variables
18+
#
19+
# No variables
20+
#
21+
# === Examples
22+
#
23+
# This is a private type and should not be used on its own.
24+
#
25+
# === Author
26+
#
27+
# Goran Miskovic <schkovich@gmail.com>
28+
#
29+
# === Copyright
30+
#
31+
# Copyright 2012-2016 Christian "Jippi" Winther, unless otherwise noted.
32+
#
33+
define php::extension::disenable (
34+
$extension,
35+
$ensure = 'present',
36+
$priority = 20,
37+
) {
38+
39+
assert_private("This is a privete type and should not be used on its own.")
40+
41+
$sapi = delete($title, $extension)
42+
43+
Exec {
44+
# fact that php5-common does not guarantee that extension is installed
45+
require => Package[$extension],
46+
# default path minus games
47+
path => '/bin:/usr/bin:/usr/local/bin: /sbin:/usr/sbin:/usr/local/sbin',
48+
}
49+
50+
validate_re($ensure, '^(latest|present|installed|absent)$')
51+
# no need for qualified since path is defined
52+
$command = $ensure ? {
53+
'absent' => 'php5dismod',
54+
default => 'php5enmod'
55+
}
56+
# same as above
57+
$unless = $ensure ? {
58+
'absent' => 'test ! -e',
59+
default => 'test -e',
60+
}
61+
# regex is idempotent. no changes will be made if there is a space after semicolon already
62+
exec { "priority_${sapi}_${extension}":
63+
command => "sed -ie 's/^;priority/; priority/g' /etc/php5/mods-available/${extension}.ini",
64+
onlyif => "test -e /etc/php5/mods-available/${extension}.ini",
65+
}
66+
# extension class should be responsible for service notification
67+
exec { "${command} -s ${sapi} ${extension}":
68+
unless => "${unless} /etc/php5/${sapi}/conf.d/${priority}-${extension}.ini",
69+
require => Exec["priority_${sapi}_${extension}"]
70+
}
71+
72+
}

manifests/sapi.pp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# == Type: php::sapi
2+
#
3+
# Enables a PHP extension installed using PECL
4+
#
5+
# === Parameters
6+
#
7+
# [*extension*]
8+
# The name of extension to enable or disenable
9+
#
10+
# [*ensure*]
11+
# The ensure of the package to install
12+
# Could be "latest", "installed", pinned version or "absent"
13+
#
14+
# [*priority*]
15+
# Integer indicateing loading order
16+
#
17+
# === Variables
18+
#
19+
# No variables
20+
#
21+
# === Examples
22+
#
23+
# This is a private type and should not be used on its own.
24+
#
25+
# === Author
26+
#
27+
# Goran Miskovic <schkovich@gmail.com>
28+
#
29+
# === Copyright
30+
#
31+
# Copyright 2012-2016 Christian "Jippi" Winther, unless otherwise noted.
32+
#
33+
define php::sapi (
34+
$extension,
35+
$ensure,
36+
$priority,
37+
) {
38+
assert_private("This is a privete type and should not be used on its own.")
39+
include php::apache::params
40+
include php::fpm::params
41+
case $title {
42+
"fpm${extension}": {
43+
if defined(Service[$php::fpm::params::service_name]) {
44+
$disenable = $title
45+
}
46+
}
47+
"apache2${extension}": {
48+
if defined(Package[$php::apache::params::package]) {
49+
$disenable = $title
50+
}
51+
}
52+
"cli${extension}": {
53+
$disenable = $title
54+
}
55+
default: {}
56+
}
57+
58+
unless empty($disenable) {
59+
php::extension::disenable { $disenable:
60+
extension => $extension,
61+
ensure => $ensure,
62+
priority => $priority,
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)