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

Adds control group limits to ServiceLimits #36

Merged
merged 4 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ end
if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
else
gem 'facter', :require => false
# There are no facts in place for beaker > 2.4 in rspec-puppet-facts yet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/beaker/facter/?

gem 'facter', '~> 2.4.0', :require => false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I like a note why it's pinned. I'm pretty sure that in this case it's because the facterdb has no facts for 2.5 yet, but when going over it you either want a note in git blame or a comment in the file.

end

if puppetversion = ENV['PUPPET_GEM_VERSION']
Expand Down
18 changes: 17 additions & 1 deletion spec/defines/service_limits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
'LimitDATA' => '10K',
'LimitNOFILE' => 20,
'LimitNICE' => '-10',
'LimitRTPRIO' => 50
'LimitRTPRIO' => 50,
'IODeviceWeight' => [
{'/dev/weight' => 10},
{'/dev/weight2' => 20}
],
'IOReadBandwidthMax' => [
{'/bw/max' => '10K'}
]
}
}}

Expand All @@ -40,6 +47,15 @@
it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
:content => /LimitRTPRIO=50/
) }
it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
:content => %r(IODeviceWeight=/dev/weight 10)
) }
it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
:content => %r(IODeviceWeight=/dev/weight2 20)
) }
it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
:content => %r(IOReadBandwidthMax=/bw/max 10K)
) }
it { is_expected.to create_exec("restart #{title} because limits").with(
:command => "systemctl restart #{title}",
:refreshonly => true
Expand Down
37 changes: 13 additions & 24 deletions templates/limits.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
# This file managed by Puppet - DO NOT EDIT
[Service]
<%
[
'LimitCPU',
'LimitFSIZE',
'LimitDATA',
'LimitSTACK',
'LimitCORE',
'LimitRSS',
'LimitNOFILE',
'LimitAS',
'LimitNPROC',
'LimitMEMLOCK',
'LimitLOCKS',
'LimitSIGPENDING',
'LimitMSGQUEUE',
'LimitNICE',
'LimitRTPRIO',
'LimitRTTIME',
'MemoryLimit',
].each do |d|
if @limits[d] -%>
<%= d %>=<%= @limits[d] %>
<%
end
end %>
@limits.keys.sort.each do |k|

# Handles the Path and Option entries
if @limits[k].is_a?(Array)
output = @limits[k].map{|x|
x = %(#{k}=#{x.to_a.flatten.join(' ')})
}.join("\n")
else
output = %(#{k}=#{@limits[k]})
end
-%>
<%= output %>
<% end -%>
55 changes: 39 additions & 16 deletions types/servicelimits.pp
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
# Matches Systemd Service Limit Struct
type Systemd::ServiceLimits = Struct[
{
Optional['LimitCPU'] => Pattern['^\d+(s|m|h|d|w|M|y)?(:\d+(s|m|h|d|w|M|y)?)?$'],
Optional['LimitFSIZE'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitDATA'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitSTACK'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitCORE'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitRSS'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitNOFILE'] => Integer[0],
Optional['LimitAS'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitNPROC'] => Integer[1],
Optional['LimitMEMLOCK'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitLOCKS'] => Integer[1],
Optional['LimitSIGPENDING'] => Integer[1],
Optional['LimitMSGQUEUE'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitNICE'] => Variant[Integer[0,40], Pattern['^(-\+([0-1]?[0-9]|20))|([0-3]?[0-9]|40)$']],
Optional['LimitRTPRIO'] => Integer[0],
Optional['LimitRTTIME'] => Pattern['^\d+(ms|s|m|h|d|w|M|y)?(:\d+(ms|s|m|h|d|w|M|y)?)?$']
Optional['LimitCPU'] => Pattern['^\d+(s|m|h|d|w|M|y)?(:\d+(s|m|h|d|w|M|y)?)?$'],
Optional['LimitFSIZE'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitDATA'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitSTACK'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitCORE'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitRSS'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitNOFILE'] => Integer[0],
Optional['LimitAS'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitNPROC'] => Integer[1],
Optional['LimitMEMLOCK'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitLOCKS'] => Integer[1],
Optional['LimitSIGPENDING'] => Integer[1],
Optional['LimitMSGQUEUE'] => Pattern['^(infinity|((\d+(K|M|G|T|P|E)(:\d+(K|M|G|T|P|E))?)))$'],
Optional['LimitNICE'] => Variant[Integer[0,40], Pattern['^(-\+([0-1]?[0-9]|20))|([0-3]?[0-9]|40)$']],
Optional['LimitRTPRIO'] => Integer[0],
Optional['LimitRTTIME'] => Pattern['^\d+(ms|s|m|h|d|w|M|y)?(:\d+(ms|s|m|h|d|w|M|y)?)?$'],
Optional['CPUAccounting'] => Boolean,
Optional['CPUShares'] => Integer[2,262144],
Optional['StartupCPUShares'] => Integer[2,262144],
Optional['CPUQuota'] => Pattern['^([1-9][0-9]?$|^100)%$'],
Optional['MemoryAccounting'] => Boolean,
Optional['MemoryLow'] => Pattern['^(\d+(K|M|G|T)?)$'],
Optional['MemoryHigh'] => Pattern['^(\d+(K|M|G|T)?)$'],
Optional['MemoryMax'] => Pattern['^(\d+(K|M|G|T)?)$'],
Optional['MemoryLimit'] => Pattern['^(\d+(K|M|G|T)?)$'],
Optional['TasksAccounting'] => Boolean,
Optional['TasksMax'] => Variant[Integer[1],Pattern['^(infinity|([1-9][0-9]?$|^100)%)$']],
Optional['IOAccounting'] => Boolean,
Optional['IOWeight'] => Integer[1,10000],
Optional['StartupIOWeight'] => Integer[1,10000],
Optional['IODeviceWeight'] => Array[Hash[Stdlib::Absolutepath, Integer[1,10000], 1, 1]],
Optional['IOReadBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
Optional['IOWriteBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
Optional['IOReadIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
Optional['IOWriteIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
Optional['DeviceAllow'] => String[1],
Optional['DevicePolicy'] => Enum['auto','closed','strict'],
Optional['Slice'] => String[1],
Optional['Delegate'] => Boolean
}
]