]> git.openstreetmap.org Git - chef.git/blob - cookbooks/php/resources/fpm.rb
Add web_path to planetdump
[chef.git] / cookbooks / php / resources / fpm.rb
1 #
2 # Cookbook:: php
3 # Resource:: php_fpm
4 #
5 # Copyright:: 2020, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 default_action :create
21
22 property :pool, :kind_of => String, :name_property => true
23 property :port, :kind_of => Integer
24 property :user, :kind_of => String, :default => "www-data"
25 property :group, :kind_of => String, :default => "www-data"
26 property :pm, :kind_of => String, :default => "dynamic"
27 property :pm_max_children, :kind_of => Integer, :default => 5
28 property :pm_start_servers, :kind_of => Integer, :default => 2
29 property :pm_min_spare_servers, :kind_of => Integer, :default => 1
30 property :pm_max_spare_servers, :kind_of => Integer, :default => 3
31 property :pm_max_requests, :kind_of => Integer, :default => 500
32 property :request_terminate_timeout, :kind_of => Integer, :default => 0
33 property :environment, :kind_of => Hash, :default => {}
34 property :php_values, :kind_of => Hash, :default => {}
35 property :php_admin_values, :kind_of => Hash, :default => {}
36 property :php_flags, :kind_of => Hash, :default => {}
37 property :php_admin_flags, :kind_of => Hash, :default => {}
38 property :reload_fpm, :kind_of => [TrueClass, FalseClass], :default => true
39 property :prometheus_port, :kind_of => Integer
40
41 action :create do
42   template conf_file do
43     cookbook "php"
44     source "pool.conf.erb"
45     owner "root"
46     group "root"
47     mode "644"
48     variables new_resource.to_hash
49   end
50
51   if new_resource.prometheus_port
52     prometheus_exporter "phpfpm" do
53       port new_resource.prometheus_port
54       service service_name
55       command "server"
56       options "--phpfpm.scrape-uri=#{scrape_uri}"
57     end
58   else
59     prometheus_exporter "phpfpm" do
60       action :delete
61       service service_name
62     end
63   end
64 end
65
66 action :delete do
67   file conf_file do
68     action :delete
69   end
70
71   prometheus_exporter "phpfpm" do
72     action :delete
73     service service_name
74   end
75 end
76
77 action_class do
78   def php_version
79     node[:php][:version]
80   end
81
82   def conf_file
83     "/etc/php/#{php_version}/fpm/pool.d/#{new_resource.pool}.conf"
84   end
85
86   def service_name
87     "phpfpm-#{new_resource.pool}"
88   end
89
90   def scrape_uri
91     if new_resource.port
92       "tcp://127.0.0.1:#{new_resource.port}/status"
93     else
94       "unix:///run/php/#{new_resource.pool}.sock;/status"
95     end
96   end
97 end
98
99 def after_created
100   notifies :reload, "service[php#{node[:php][:version]}-fpm]" if reload_fpm
101 end