PageRenderTime 59ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/vagrant-phalcon-rest/modules/php/manifests/init.pp

https://bitbucket.org/cmoore4/phalconrest
Puppet | 298 lines | 133 code | 19 blank | 146 comment | 12 complexity | 3859eb9fbca4d1579b857ef24266786b MD5 | raw file
  1. # = Class: php
  2. #
  3. # This is the main php class
  4. #
  5. #
  6. # == Parameters
  7. #
  8. # Module specific parameters
  9. # [*package_devel*]
  10. # Name of the php-devel package
  11. #
  12. # [*package_pear*]
  13. # Name of the php-pear package
  14. #
  15. # Standard class parameters
  16. # Define the general class behaviour and customizations
  17. #
  18. # [*my_class*]
  19. # Name of a custom class to autoload to manage module's customizations
  20. # If defined, php class will automatically "include $my_class"
  21. # Can be defined also by the (top scope) variable $php_myclass
  22. #
  23. # [*service*]
  24. # The service that runs the php interpreter. Defines what service gets
  25. # notified. Default: apache2|httpd.
  26. #
  27. # [*source*]
  28. # Sets the content of source parameter for main configuration file
  29. # If defined, php main config file will have the param: source => $source
  30. # Can be defined also by the (top scope) variable $php_source
  31. #
  32. # [*source_dir*]
  33. # If defined, the whole php configuration directory content is retrieved
  34. # recursively from the specified source
  35. # (source => $source_dir , recurse => true)
  36. # Can be defined also by the (top scope) variable $php_source_dir
  37. #
  38. # [*source_dir_purge*]
  39. # If set to true (default false) the existing configuration directory is
  40. # mirrored with the content retrieved from source_dir
  41. # (source => $source_dir , recurse => true , purge => true, force => true)
  42. # Can be defined also by the (top scope) variable $php_source_dir_purge
  43. #
  44. # [*template*]
  45. # Sets the path to the template to use as content for main configuration file
  46. # If defined, php main config file has: content => content("$template")
  47. # Note source and template parameters are mutually exclusive: don't use both
  48. # Can be defined also by the (top scope) variable $php_template
  49. #
  50. # [*augeas*]
  51. # If set to true (default false), the php.ini will be managed through
  52. # augeas. This will make php::pecl automatically add extensions to the
  53. # php.ini.
  54. # Can be defined also by the (top scope) variable $php_augeas
  55. #
  56. # [*options*]
  57. # An hash of custom options to be used in templates for arbitrary settings.
  58. # Can be defined also by the (top scope) variable $php_options
  59. #
  60. # [*version*]
  61. # The package version, used in the ensure parameter of package type.
  62. # Default: present. Can be 'latest' or a specific version number.
  63. # Note that if the argument absent (see below) is set to true, the
  64. # package is removed, whatever the value of version parameter.
  65. #
  66. # [*absent*]
  67. # Set to 'true' to remove package(s) installed by module
  68. # Can be defined also by the (top scope) variable $php_absent
  69. #
  70. # [*puppi*]
  71. # Set to 'true' to enable creation of module data files that are used by puppi
  72. # Can be defined also by the (top scope) variables $php_puppi and $puppi
  73. #
  74. # [*puppi_helper*]
  75. # Specify the helper to use for puppi commands. The default for this module
  76. # is specified in params.pp and is generally a good choice.
  77. # You can customize the output of puppi commands for this module using another
  78. # puppi helper. Use the define puppi::helper to create a new custom helper
  79. # Can be defined also by the (top scope) variables $php_puppi_helper
  80. # and $puppi_helper
  81. #
  82. # [*debug*]
  83. # Set to 'true' to enable modules debugging
  84. # Can be defined also by the (top scope) variables $php_debug and $debug
  85. #
  86. # [*audit_only*]
  87. # Set to 'true' if you don't intend to override existing configuration files
  88. # and want to audit the difference between existing files and the ones
  89. # managed by Puppet.
  90. # Can be defined also by the (top scope) variables $php_audit_only
  91. # and $audit_only
  92. #
  93. # Default class params - As defined in php::params.
  94. # Note that these variables are mostly defined and used in the module itself,
  95. # overriding the default values might not affected all the involved components.
  96. # Set and override them only if you know what you're doing.
  97. # Note also that you can't override/set them via top scope variables.
  98. #
  99. # [*package*]
  100. # The name of php package
  101. #
  102. # [*config_dir*]
  103. # Main configuration directory. Used by puppi
  104. #
  105. # [*config_file*]
  106. # Main configuration file path
  107. #
  108. # [*config_file_mode*]
  109. # Main configuration file path mode
  110. #
  111. # [*config_file_owner*]
  112. # Main configuration file path owner
  113. #
  114. # [*config_file_group*]
  115. # Main configuration file path group
  116. #
  117. # [*config_file_init*]
  118. # Path of configuration file sourced by init script
  119. #
  120. # [*pid_file*]
  121. # Path of pid file. Used by monitor
  122. #
  123. # [*data_dir*]
  124. # Path of application data directory. Used by puppi
  125. #
  126. # [*log_dir*]
  127. # Base logs directory. Used by puppi
  128. #
  129. # [*log_file*]
  130. # Log file(s). Used by puppi
  131. #
  132. # == Examples
  133. #
  134. # You can use this class in 2 ways:
  135. # - Set variables (at top scope level on in a ENC) and "include php"
  136. # - Call php as a parametrized class
  137. #
  138. # See README for details.
  139. #
  140. #
  141. class php (
  142. $package_devel = params_lookup( 'package_devel' ),
  143. $package_pear = params_lookup( 'package_pear' ),
  144. $my_class = params_lookup( 'my_class' ),
  145. $service = params_lookup( 'service' ),
  146. $service_autorestart = params_lookup( 'service_autorestart' ),
  147. $source = params_lookup( 'source' ),
  148. $source_dir = params_lookup( 'source_dir' ),
  149. $source_dir_purge = params_lookup( 'source_dir_purge' ),
  150. $template = params_lookup( 'template' ),
  151. $augeas = params_lookup( 'augeas' ),
  152. $options = params_lookup( 'options' ),
  153. $version = params_lookup( 'version' ),
  154. $absent = params_lookup( 'absent' ),
  155. $monitor = params_lookup( 'monitor' , 'global' ),
  156. $monitor_tool = params_lookup( 'monitor_tool' , 'global' ),
  157. $monitor_target = params_lookup( 'monitor_target' , 'global' ),
  158. $puppi = params_lookup( 'puppi' , 'global' ),
  159. $puppi_helper = params_lookup( 'puppi_helper' , 'global' ),
  160. $debug = params_lookup( 'debug' , 'global' ),
  161. $audit_only = params_lookup( 'audit_only' , 'global' ),
  162. $package = params_lookup( 'package' ),
  163. $module_prefix = params_lookup( 'module_prefix' ),
  164. $config_dir = params_lookup( 'config_dir' ),
  165. $config_file = params_lookup( 'config_file' ),
  166. $config_file_mode = params_lookup( 'config_file_mode' ),
  167. $config_file_owner = params_lookup( 'config_file_owner' ),
  168. $config_file_group = params_lookup( 'config_file_group' ),
  169. $config_file_init = params_lookup( 'config_file_init' ),
  170. $pid_file = params_lookup( 'pid_file' ),
  171. $data_dir = params_lookup( 'data_dir' ),
  172. $log_dir = params_lookup( 'log_dir' ),
  173. $log_file = params_lookup( 'log_file' ),
  174. $port = params_lookup( 'port' ),
  175. $protocol = params_lookup( 'protocol' )
  176. ) inherits php::params {
  177. $bool_service_autorestart=any2bool($service_autorestart)
  178. $bool_source_dir_purge=any2bool($source_dir_purge)
  179. $bool_augeas=any2bool($augeas)
  180. $bool_absent=any2bool($absent)
  181. $bool_monitor=any2bool($monitor)
  182. $bool_puppi=any2bool($puppi)
  183. $bool_debug=any2bool($debug)
  184. $bool_audit_only=any2bool($audit_only)
  185. ### Definition of some variables used in the module
  186. $manage_package = $php::bool_absent ? {
  187. true => 'absent',
  188. false => $php::version,
  189. }
  190. $manage_file = $php::bool_absent ? {
  191. true => 'absent',
  192. default => 'present',
  193. }
  194. if $php::bool_absent == true {
  195. $manage_monitor = false
  196. } else {
  197. $manage_monitor = true
  198. }
  199. $manage_audit = $php::bool_audit_only ? {
  200. true => 'all',
  201. false => undef,
  202. }
  203. $manage_file_replace = $php::bool_audit_only ? {
  204. true => false,
  205. false => true,
  206. }
  207. if ($php::source and $php::template) {
  208. fail ("PHP: cannot set both source and template")
  209. }
  210. if ($php::source and $php::bool_augeas) {
  211. fail ("PHP: cannot set both source and augeas")
  212. }
  213. if ($php::template and $php::bool_augeas) {
  214. fail ("PHP: cannot set both template and augeas")
  215. }
  216. $manage_file_source = $php::source ? {
  217. '' => undef,
  218. default => $php::source,
  219. }
  220. $manage_file_content = $php::template ? {
  221. '' => undef,
  222. default => template($php::template),
  223. }
  224. ### Managed resources
  225. package { 'php':
  226. ensure => $php::manage_package,
  227. name => $php::package,
  228. }
  229. file { 'php.conf':
  230. ensure => $php::manage_file,
  231. path => $php::config_file,
  232. mode => $php::config_file_mode,
  233. owner => $php::config_file_owner,
  234. group => $php::config_file_group,
  235. require => Package['php'],
  236. source => $php::manage_file_source,
  237. content => $php::manage_file_content,
  238. replace => $php::manage_file_replace,
  239. audit => $php::manage_audit,
  240. }
  241. # The whole php configuration directory can be recursively overriden
  242. if $php::source_dir {
  243. file { 'php.dir':
  244. ensure => directory,
  245. path => $php::config_dir,
  246. require => Package['php'],
  247. source => $php::source_dir,
  248. recurse => true,
  249. purge => $php::bool_source_dir_purge,
  250. force => $php::bool_source_dir_purge,
  251. replace => $php::manage_file_replace,
  252. audit => $php::manage_audit,
  253. }
  254. }
  255. ### Include custom class if $my_class is set
  256. if $php::my_class {
  257. include $php::my_class
  258. }
  259. ### Provide puppi data, if enabled ( puppi => true )
  260. if $php::bool_puppi == true {
  261. $classvars=get_class_args()
  262. puppi::ze { 'php':
  263. ensure => $php::manage_file,
  264. variables => $classvars,
  265. helper => $php::puppi_helper,
  266. }
  267. }
  268. ### Debugging, if enabled ( debug => true )
  269. if $php::bool_debug == true {
  270. file { 'debug_php':
  271. ensure => $php::manage_file,
  272. path => "${settings::vardir}/debug-php",
  273. mode => '0640',
  274. owner => 'root',
  275. group => 'root',
  276. content => inline_template('<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime.*|path|timestamp|free|.*password.*|.*psk.*|.*key)/ }.to_yaml %>'),
  277. }
  278. }
  279. }