Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have php_fpm listen on a UNIX socket rather than a TCP port #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ Installs and configures Zabbix agent and server with PostgreSQL/MySQL and Nginx.
* `node['zabbix']['server']['config']['java_gateway']` - Defaults to `{ ... }`.
* `node['zabbix']['server']['config']['alerts']` - Defaults to `{ ... }`.
* `node['zabbix']['server']['web']['server_name']` - Defaults to `localhost`.
* `node['zabbix']['server']['web']['listen']` - Defaults to `127.0.0.1`.
* `node['zabbix']['server']['web']['port']` - Defaults to `9200`.
* `node['zabbix']['server']['web']['listen']` - Defaults to `/var/run/php-fpm-zabbix.sock`.
* `node['zabbix']['server']['web']['max_requests']` - Defaults to `500`.
* `node['zabbix']['server']['web']['max_children']` - Defaults to `5`.
* `node['zabbix']['server']['web']['min_spare_servers']` - Defaults to `1`.
Expand Down
3 changes: 1 addition & 2 deletions attributes/web.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
default['zabbix']['server']['web']['server_name'] = 'localhost'
default['zabbix']['server']['web']['listen'] = '127.0.0.1'
default['zabbix']['server']['web']['port'] = '9200'
default['zabbix']['server']['web']['listen'] = node['php-fpm']['listen'].gsub(/%{pool_name}/, 'zabbix')

default['zabbix']['server']['web']['max_requests'] = 500
default['zabbix']['server']['web']['max_children'] = 5
Expand Down
9 changes: 6 additions & 3 deletions recipes/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
db_user = db_user_data.keys.first
db_pass = db_user_data[db_user]['options']['password']

fastcgi_listen = node['zabbix']['server']['web']['listen']
fastcgi_listen = "unix:#{fastcgi_listen}" if fastcgi_listen[0] == '/'

chef_nginx_site node['zabbix']['server']['web']['server_name'] do
action :enable
template 'zabbix-site.conf.erb'
variables(
server_name: node['zabbix']['server']['web']['server_name'],
fastcgi_listen: node['zabbix']['server']['web']['listen'],
fastcgi_port: node['zabbix']['server']['web']['port']
fastcgi_listen: fastcgi_listen
)
end

Expand Down Expand Up @@ -113,7 +115,8 @@
end

php_fpm_pool 'zabbix' do
listen "#{node['zabbix']['server']['web']['listen']}:#{node['zabbix']['server']['web']['port']}"
listen_group node['nginx']['group']
listen node['zabbix']['server']['web']['listen']
max_children node['zabbix']['server']['web']['max_children']
max_requests node['zabbix']['server']['web']['max_requests']
min_spare_servers node['zabbix']['server']['web']['min_spare_servers']
Expand Down
2 changes: 1 addition & 1 deletion templates/default/zabbix-site.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ server {

location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass <%= @fastcgi_listen %>:<%= @fastcgi_port %>;
fastcgi_pass <%= @fastcgi_listen %>;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
when 'rhel'
include_recipe 'selinux_policy::install'

# Allow phpfpm to bind to port, by giving it the http_port_t context
selinux_policy_port node['zabbix']['server']['web']['port'] do
protocol 'tcp'
secontext 'http_port_t'
end
selinux_policy_boolean 'httpd_can_network_connect' do
value true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
when 'rhel'
include_recipe 'selinux_policy::install'

# Allow phpfpm to bind to port, by giving it the http_port_t context
selinux_policy_port node['zabbix']['server']['web']['port'] do
protocol 'tcp'
secontext 'http_port_t'
end
selinux_policy_boolean 'httpd_can_network_connect' do
value true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
when 'rhel'
include_recipe 'selinux_policy::install'

# Allow phpfpm to bind to port, by giving it the http_port_t context
selinux_policy_port node['zabbix']['server']['web']['port'] do
protocol 'tcp'
secontext 'http_port_t'
end
selinux_policy_boolean 'httpd_can_network_connect' do
value true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
when 'rhel'
include_recipe 'selinux_policy::install'

# Allow phpfpm to bind to port, by giving it the http_port_t context
selinux_policy_port node['zabbix']['server']['web']['port'] do
protocol 'tcp'
secontext 'http_port_t'
end
selinux_policy_boolean 'httpd_can_network_connect' do
value true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
when 'rhel'
include_recipe 'selinux_policy::install'

# Allow phpfpm to bind to port, by giving it the http_port_t context
selinux_policy_port node['zabbix']['server']['web']['port'] do
protocol 'tcp'
secontext 'http_port_t'
end
selinux_policy_boolean 'httpd_can_network_connect' do
value true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
when 'rhel'
include_recipe 'selinux_policy::install'

# Allow phpfpm to bind to port, by giving it the http_port_t context
selinux_policy_port node['zabbix']['server']['web']['port'] do
protocol 'tcp'
secontext 'http_port_t'
end
selinux_policy_boolean 'httpd_can_network_connect' do
value true
end
Expand Down
8 changes: 4 additions & 4 deletions test/integration/inspec/controls/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@

describe file(php_zabbix_pool_file) do
it { should be_file }
its('content') { should include 'listen = 127.0.0.1:9200' }
its('content') { should include 'listen = /var/run/php-fpm-zabbix.sock' }
end

describe port(9200) do
it { should be_listening }
describe file('/var/run/php-fpm-zabbix.sock') do
it { should be_socket }
end

describe file('/etc/zabbix/web/zabbix.conf.php') do
Expand All @@ -152,7 +152,7 @@
it { should be_file }
its('content') { should include 'listen 80' }
its('content') { should include 'server_name localhost' }
its('content') { should include 'fastcgi_pass 127.0.0.1:9200' }
its('content') { should include 'fastcgi_pass unix:/var/run/php-fpm-zabbix.sock' }
end

describe port(80) do
Expand Down