PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/php-fpm/recipes/configure.rb

https://github.com/easybiblabs/easybib-cookbooks
Ruby | 189 lines | 135 code | 19 blank | 35 comment | 6 complexity | 5e82582da4b983ebc530b3b7929e763e MD5 | raw file
  1. #
  2. # Cookbook Name:: php-fpm
  3. # Recipe:: configure
  4. #
  5. # Copyright 2010-2011, Till Klampaeckel
  6. #
  7. # All rights reserved.
  8. #
  9. # Redistribution and use in source and binary forms, with or without modification,
  10. # are permitted provided that the following conditions are met:
  11. #
  12. # * Redistributions of source code must retain the above copyright notice, this list
  13. # of conditions and the following disclaimer.
  14. # * Redistributions in binary form must reproduce the above copyright notice, this
  15. # list of conditions and the following disclaimer in the documentation and/or other
  16. # materials provided with the distribution.
  17. # * The names of its contributors may not be used to endorse or promote products
  18. # derived from this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  21. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. # POSSIBILITY OF SUCH DAMAGE.
  30. #
  31. include_recipe 'php-fpm::service'
  32. config = node['php-fpm']
  33. conf_cli = "#{config['prefix']}/#{config['cli_config']}"
  34. conf_fpm = "#{config['prefix']}/#{config['fpm_config']}"
  35. display_errors = if config['user'] == 'vagrant'
  36. 'On'
  37. else
  38. 'Off'
  39. end
  40. if config['mailsender'].nil?
  41. Chef::Log.info('Not adding any sendmail params')
  42. sendmail_params = nil
  43. else
  44. sendmail_params = "-f '#{config['mailsender']}'"
  45. Chef::Log.info("Adding to php sendmail stmt: #{sendmail_params}")
  46. end
  47. # this may or may not work
  48. php_version = node['php']['ppa']['package_prefix'].gsub('php', '')
  49. alternatives = []
  50. alternatives << '/usr/bin/update-alternatives'
  51. alternatives << '--install'
  52. alternatives << '/usr/sbin/php-fpm'
  53. alternatives << 'php-fpm'
  54. alternatives << "/usr/sbin/php-fpm#{php_version}"
  55. alternatives << '0'
  56. execute 'update-alternatives' do
  57. command alternatives.join(' ')
  58. action :nothing
  59. not_if do
  60. node['php']['ppa']['package_prefix'] == 'php5-easybib'
  61. end
  62. end
  63. #
  64. # An attempt to make sure that the php prefix given is the prefix
  65. # chosen for php-cli at the end of an install
  66. php_alternatives = []
  67. php_alternatives << '/usr/bin/update-alternatives'
  68. php_alternatives << '--set'
  69. php_alternatives << 'php'
  70. php_alternatives << "/usr/bin/php#{php_version}"
  71. execute 'update-cli-alternatives' do
  72. command php_alternatives.join(' ')
  73. action :nothing
  74. not_if do
  75. node['php']['ppa']['package_prefix'] == 'php5-easybib'
  76. end
  77. end
  78. template conf_fpm do
  79. mode '0755'
  80. source 'php.ini.erb'
  81. variables(
  82. :enable_dl => 'Off',
  83. :memory_limit => config['memorylimit'],
  84. :display_errors => display_errors,
  85. :max_execution_time => config['maxexecutiontime'],
  86. :max_input_vars => config['ini']['max-input-vars'],
  87. :error_log => 'syslog',
  88. :tmpdir => config['tmpdir'],
  89. :prefix => config['prefix'],
  90. :sendmail_params => sendmail_params
  91. )
  92. owner config['user']
  93. group config['group']
  94. notifies :reload, 'service[php-fpm]', :delayed
  95. notifies :run, 'execute[update-alternatives]', :immediately
  96. notifies :run, 'execute[update-cli-alternatives]', :immediately
  97. end
  98. template conf_cli do
  99. mode '0755'
  100. source 'php.ini.erb'
  101. variables(
  102. :enable_dl => 'On',
  103. :error_log => 'syslog',
  104. :memory_limit => '1024M',
  105. :display_errors => 'On',
  106. :max_execution_time => '-1',
  107. :max_input_vars => config['ini']['max-input-vars'],
  108. :tmpdir => config['tmpdir'],
  109. :prefix => config['prefix'],
  110. :sendmail_params => sendmail_params
  111. )
  112. owner config['user']
  113. group config['group']
  114. end
  115. etc_fpm_dir = File.dirname(conf_fpm)
  116. pool_dir = "#{config['prefix']}/#{config['pool_dir']}"
  117. template "#{etc_fpm_dir}/php-fpm.conf" do
  118. mode '0755'
  119. source 'php-fpm.conf.erb'
  120. owner config['user']
  121. group config['group']
  122. variables(
  123. :pool_dir => pool_dir
  124. )
  125. notifies :reload, 'service[php-fpm]', :delayed
  126. end
  127. directory pool_dir do
  128. owner config['user']
  129. group config['group']
  130. action :create
  131. recursive true
  132. end
  133. # default pool setup by PHP package
  134. file "#{pool_dir}/www.conf" do
  135. action :delete
  136. only_if do
  137. File.exist?("#{pool_dir}/www.conf") && !config['pools'].include?('www')
  138. end
  139. end
  140. config['pools'].each do |pool_name|
  141. template "#{pool_dir}/#{pool_name}.conf" do
  142. mode '0644'
  143. source 'pool.conf.erb'
  144. owner config['user']
  145. group config['group']
  146. variables(
  147. :pool_name => pool_name,
  148. :user => config['user'],
  149. :group => config['group'],
  150. :type => config['type'],
  151. :max_children => config['max_children'],
  152. :socket_dir => config['socketdir'],
  153. :slowlog_timeout => config['slowlog_timeout'],
  154. :slowlog => config['slowlog']
  155. )
  156. notifies :reload, 'service[php-fpm]', :delayed
  157. end
  158. end
  159. template '/etc/logrotate.d/php' do
  160. source 'logrotate.erb'
  161. variables(
  162. :logfile => config['logfile']
  163. )
  164. mode '0644'
  165. owner 'root'
  166. group 'root'
  167. notifies :enable, 'service[php-fpm]', :immediately
  168. notifies :start, 'service[php-fpm]', :immediately
  169. end
  170. include_recipe 'php-fpm::monit' if is_aws