|
| 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 | +} |
0 commit comments