From 59760d6244ce6273355b5685609f2cc8cdb2c861 Mon Sep 17 00:00:00 2001 From: Goran Miskovic Date: Sun, 19 Mar 2017 13:48:57 +0100 Subject: [PATCH] Enable extension (#162) * Mix and match various proposals. * Parameters classes must be included. refs jippi/puppet-php#142 * Added doc blox and assert_private. refs jippi/puppet-php#148 --- manifests/extension.pp | 28 ++++++++++++- manifests/extension/disenable.pp | 72 ++++++++++++++++++++++++++++++++ manifests/sapi.pp | 65 ++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 manifests/extension/disenable.pp create mode 100644 manifests/sapi.pp diff --git a/manifests/extension.pp b/manifests/extension.pp index 53ca6603..7028e8ff 100644 --- a/manifests/extension.pp +++ b/manifests/extension.pp @@ -23,6 +23,15 @@ # [*source*] # The path to the deb package to install # +# [*sapis*] +# An array of PHP SAPIs for which extension should be installed. This +# parameters applies to PECL extensions only. +# @see http://php.net/manual/en/function.php-sapi-name.php +# +# [*priority*] +# Module loading priority. Default is 20. . +# @see http://www.brandonchecketts.com/archives/getting-ubuntu-14-04-php5enmod-to-understand-module-priority +# # === Variables # # [*php_ensure*] @@ -49,6 +58,14 @@ # source => "/path/to/libgearman8_1.1.7-1_amd64.deb"; # } # +# php::extension { 'gearman': +# ensure => "latest", +# package => "gearman", +# provider => "pecl", +# sapis => ['cli', 'fpm'], +# priority_=> 30 +# } +# # === Authors # # Christian "Jippi" Winther @@ -62,7 +79,9 @@ $package, $provider = undef, $pipe = undef, - $source = undef + $source = undef, + $sapis = ['cli', 'fpm', 'apache2'], + $priority = 20, ) { if $provider == 'pecl' { @@ -72,6 +91,13 @@ source => $source, pipe => $pipe; } + $uniqe_sapis = suffix($sapis, $package) + php::sapi { $uniqe_sapis: + extension => $package, + ensure => $ensure, + priority => $priority, + require => Package[$package], + } } elsif $provider == 'dpkg' { package { $package: ensure => $ensure, diff --git a/manifests/extension/disenable.pp b/manifests/extension/disenable.pp new file mode 100644 index 00000000..ce92d4c9 --- /dev/null +++ b/manifests/extension/disenable.pp @@ -0,0 +1,72 @@ +# == Type: php::extension::disenable +# +# Enables a PHP extension installed using PECL +# +# === Parameters +# +# [*extension*] +# The name of extension to enable or disenable +# +# [*ensure*] +# The ensure of the package to install +# Could be "latest", "installed", pinned version or "absent" +# +# [*priority*] +# Integer indicateing loading order +# +# === Variables +# +# No variables +# +# === Examples +# +# This is a private type and should not be used on its own. +# +# === Author +# +# Goran Miskovic +# +# === Copyright +# +# Copyright 2012-2016 Christian "Jippi" Winther, unless otherwise noted. +# +define php::extension::disenable ( + $extension, + $ensure = 'present', + $priority = 20, +) { + + assert_private("This is a privete type and should not be used on its own.") + + $sapi = delete($title, $extension) + + Exec { + # fact that php5-common does not guarantee that extension is installed + require => Package[$extension], + # default path minus games + path => '/bin:/usr/bin:/usr/local/bin: /sbin:/usr/sbin:/usr/local/sbin', + } + + validate_re($ensure, '^(latest|present|installed|absent)$') +# no need for qualified since path is defined + $command = $ensure ? { + 'absent' => 'php5dismod', + default => 'php5enmod' + } +# same as above + $unless = $ensure ? { + 'absent' => 'test ! -e', + default => 'test -e', + } +# regex is idempotent. no changes will be made if there is a space after semicolon already + exec { "priority_${sapi}_${extension}": + command => "sed -ie 's/^;priority/; priority/g' /etc/php5/mods-available/${extension}.ini", + onlyif => "test -e /etc/php5/mods-available/${extension}.ini", + } +# extension class should be responsible for service notification + exec { "${command} -s ${sapi} ${extension}": + unless => "${unless} /etc/php5/${sapi}/conf.d/${priority}-${extension}.ini", + require => Exec["priority_${sapi}_${extension}"] + } + +} diff --git a/manifests/sapi.pp b/manifests/sapi.pp new file mode 100644 index 00000000..1c279fb3 --- /dev/null +++ b/manifests/sapi.pp @@ -0,0 +1,65 @@ +# == Type: php::sapi +# +# Enables a PHP extension installed using PECL +# +# === Parameters +# +# [*extension*] +# The name of extension to enable or disenable +# +# [*ensure*] +# The ensure of the package to install +# Could be "latest", "installed", pinned version or "absent" +# +# [*priority*] +# Integer indicateing loading order +# +# === Variables +# +# No variables +# +# === Examples +# +# This is a private type and should not be used on its own. +# +# === Author +# +# Goran Miskovic +# +# === Copyright +# +# Copyright 2012-2016 Christian "Jippi" Winther, unless otherwise noted. +# +define php::sapi ( + $extension, + $ensure, + $priority, +) { + assert_private("This is a privete type and should not be used on its own.") + include php::apache::params + include php::fpm::params + case $title { + "fpm${extension}": { + if defined(Service[$php::fpm::params::service_name]) { + $disenable = $title + } + } + "apache2${extension}": { + if defined(Package[$php::apache::params::package]) { + $disenable = $title + } + } + "cli${extension}": { + $disenable = $title + } + default: {} + } + + unless empty($disenable) { + php::extension::disenable { $disenable: + extension => $extension, + ensure => $ensure, + priority => $priority, + } + } +}