Skip to content

Commit 27eb207

Browse files
baurmattekohl
authored andcommitted
Implement $server_max_open_files
This commit implements the $server_max_open_files parameter which allows the user to configure the max open file descriptor limit for Puppetserver. Fixes GH-670.
1 parent a541d70 commit 27eb207

File tree

9 files changed

+141
-0
lines changed

9 files changed

+141
-0
lines changed

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fixtures:
1313
inifile: 'https://github.com/puppetlabs/puppetlabs-inifile.git'
1414
puppetdb: 'https://github.com/puppetlabs/puppetlabs-puppetdb.git'
1515
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git'
16+
systemd: 'https://github.com/camptocamp/puppet-systemd.git'
1617
yumrepo_core:
1718
repo: 'https://github.com/puppetlabs/puppetlabs-yumrepo_core'
1819
puppet_version: '>= 6.0.0'

manifests/init.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@
511511
# $server_ca_enable_infra_crl:: Enable the separate CRL for Puppet infrastructure nodes
512512
# Defaults to false
513513
#
514+
# $server_max_open_files:: Increase the max open files limit for Puppetserver.
515+
# Defaults to undef
516+
#
514517
# === Usage:
515518
#
516519
# * Simple usage:
@@ -703,6 +706,7 @@
703706
Boolean $server_ca_allow_sans = $puppet::params::server_ca_allow_sans,
704707
Boolean $server_ca_allow_auth_extensions = $puppet::params::server_ca_allow_auth_extensions,
705708
Boolean $server_ca_enable_infra_crl = $puppet::params::server_ca_enable_infra_crl,
709+
Optional[Integer[1]] $server_max_open_files = $puppet::params::server_max_open_files,
706710
) inherits puppet::params {
707711
contain puppet::config
708712

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@
412412
$server_ca_allow_sans = false
413413
$server_ca_allow_auth_extensions = false
414414
$server_ca_enable_infra_crl = false
415+
$server_max_open_files = undef
415416

416417
$server_puppetserver_version = undef
417418

manifests/server.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@
442442
Boolean $ca_allow_sans = $::puppet::server_ca_allow_sans,
443443
Boolean $ca_allow_auth_extensions = $::puppet::server_ca_allow_auth_extensions,
444444
Boolean $ca_enable_infra_crl = $::puppet::server_ca_enable_infra_crl,
445+
Optional[Integer[1]] $max_open_files = $::puppet::server_max_open_files,
445446
) {
446447
if $ca {
447448
$ssl_ca_cert = "${ssl_dir}/ca/ca_crt.pem"

manifests/server/puppetserver.pp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
$ca_allow_sans = $::puppet::server::ca_allow_sans,
127127
$ca_allow_auth_extensions = $::puppet::server::ca_allow_auth_extensions,
128128
$ca_enable_infra_crl = $::puppet::server::ca_enable_infra_crl,
129+
$max_open_files = $::puppet::server::max_open_files,
129130
) {
130131
include ::puppet::server
131132

@@ -192,6 +193,26 @@
192193
changes => $jruby_jar_changes,
193194
}
194195
}
196+
197+
$ensure_max_open_files = $max_open_files ? {
198+
undef => 'absent',
199+
default => 'present',
200+
}
201+
if $facts['service_provider'] == 'systemd' {
202+
systemd::dropin_file { 'puppetserver.service-limits.conf':
203+
ensure => $ensure_max_open_files,
204+
filename => 'limits.conf',
205+
unit => 'puppetserver.service',
206+
content => "[Service]\nLimitNOFILE=${max_open_files}\n",
207+
}
208+
} else {
209+
file_line { 'puppet::server::puppetserver::max_open_files':
210+
ensure => $ensure_max_open_files,
211+
path => $config,
212+
line => "ulimit -n ${max_open_files}",
213+
match => '^ulimit\ -n',
214+
}
215+
}
195216
}
196217

197218
$servicesd = "${server_puppetserver_dir}/services.d"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'Puppetserver config options', unless: ENV['BEAKER_PUPPET_COLLECTION'] == 'pc1' && fact('lsbdistcodename') == 'stretch' do
4+
before(:context) do
5+
if fact('lsbdistcodename') == 'jessie' && ENV['BEAKER_PUPPET_COLLECTION'] != 'pc1'
6+
on default, "echo 'deb http://deb.debian.org/debian jessie-backports main' >/etc/apt/sources.list.d/backports.list"
7+
on default, 'apt update'
8+
on default, 'apt -y -t jessie-backports install openjdk-8-jdk-headless'
9+
end
10+
if check_for_package(default, 'puppetserver')
11+
on default, puppet('resource package puppetserver ensure=purged')
12+
on default, 'rm -rf /etc/sysconfig/puppetserver /etc/puppetlabs/puppetserver'
13+
on default, 'find /etc/puppetlabs/puppet/ssl/ -type f -delete'
14+
end
15+
16+
# puppetserver won't start with lower than 2GB memory
17+
memoryfree_mb = fact('memoryfree_mb').to_i
18+
raise 'At least 2048MB free memory required' if memoryfree_mb < 256
19+
end
20+
21+
describe 'server_max_open_files' do
22+
let(:pp) do
23+
<<-MANIFEST
24+
class { '::puppet':
25+
server => true,
26+
server_foreman => false,
27+
server_reports => 'store',
28+
server_external_nodes => '',
29+
# only for install test - don't think to use this in production!
30+
# https://docs.puppet.com/puppetserver/latest/tuning_guide.html
31+
server_jvm_max_heap_size => '256m',
32+
server_jvm_min_heap_size => '256m',
33+
server_max_open_files => 32143,
34+
}
35+
MANIFEST
36+
end
37+
38+
it_behaves_like 'a idempotent resource'
39+
40+
# pgrep -f java.*puppetserver would be better. But i cannot get it to work. Shellwords.escape() seems to break something
41+
describe command("grep '^Max open files' /proc/`cat /var/run/puppetlabs/puppetserver/puppetserver.pid`/limits"), :sudo => true do
42+
its(:exit_status) { is_expected.to eq 0 }
43+
its(:stdout) { is_expected.to match %r{^Max open files\s+32143\s+32143\s+files\s*$} }
44+
end
45+
end
46+
end

spec/classes/puppet_server_puppetserver_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,40 @@
404404
end
405405
end
406406

407+
describe 'server_max_open_files', unless: facts[:osfamily] == 'FreeBSD' do
408+
context 'when server_max_open_files => undef' do
409+
it do
410+
if facts['service_provider'] == 'systemd'
411+
should contain_systemd__dropin_file('puppetserver.service-limits.conf')
412+
.with_ensure('absent')
413+
else
414+
should contain_file_line('puppet::server::puppetserver::max_open_files')
415+
.with_ensure('absent')
416+
end
417+
end
418+
end
419+
420+
context 'when server_max_open_files => 32143' do
421+
let(:params) { super().merge(server_max_open_files: 32143) }
422+
423+
it do
424+
if facts['service_provider'] == 'systemd'
425+
should contain_systemd__dropin_file('puppetserver.service-limits.conf')
426+
.with_ensure('present')
427+
.with_filename('limits.conf')
428+
.with_unit('puppetserver.service')
429+
.with_content("[Service]\nLimitNOFILE=32143\n")
430+
else
431+
should contain_file_line('puppet::server::puppetserver::max_open_files')
432+
.with_ensure('present')
433+
.with_path('/etc/default/puppetserver')
434+
.with_line('ulimit -n 32143')
435+
.with_match('^ulimit\ -n')
436+
end
437+
end
438+
end
439+
end
440+
407441
describe 'with extra_args parameter' do
408442
let(:params) { super().merge(server_jvm_extra_args: ['-XX:foo=bar', '-XX:bar=foo']) }
409443
if facts[:osfamily] == 'FreeBSD'

spec/spec_helper.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,38 @@
1313
# Original fact sources:
1414
add_custom_fact :puppet_environmentpath, '/etc/puppetlabs/code/environments' # puppetlabs-stdlib
1515
add_custom_fact :root_home, '/root' # puppetlabs-stdlib
16+
# Rough conversion of grepping in the puppet source:
17+
# grep defaultfor lib/puppet/provider/service/*.rb
18+
add_custom_fact :service_provider, ->(os, facts) do
19+
case facts[:osfamily].downcase
20+
when 'archlinux'
21+
'systemd'
22+
when 'darwin'
23+
'launchd'
24+
when 'debian'
25+
if facts[:operatingsystem] == 'Ubuntu'
26+
facts[:operatingsystemmajrelease].to_i >= 15 ? 'systemd' : 'upstart'
27+
elsif facts[:operatingsystem] == 'Debian' && facts[:operatingsystemmajrelease].to_i >= 8
28+
'systemd'
29+
else
30+
'debian'
31+
end
32+
when 'freebsd'
33+
'freebsd'
34+
when 'gentoo'
35+
'openrc'
36+
when 'openbsd'
37+
'openbsd'
38+
when 'redhat'
39+
facts[:operatingsystemrelease].to_i >= 7 ? 'systemd' : 'redhat'
40+
when 'suse'
41+
facts[:operatingsystemmajrelease].to_i >= 12 ? 'systemd' : 'redhat'
42+
when 'windows'
43+
'windows'
44+
else
45+
'init'
46+
end
47+
end
1648

1749
# Workaround for no method in rspec-puppet to pass undef through :params
1850
class Undef

spec/spec_helper_acceptance.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no'
1414
install_module_on(hosts)
1515
install_module_dependencies_on(hosts)
16+
install_module_from_forge('camptocamp-systemd', '>= 2.0.0 < 3.0.0')
1617

1718
RSpec.configure do |c|
1819
# Readable test descriptions

0 commit comments

Comments
 (0)