Skip to content

Commit

Permalink
Add support for 'nice' argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
decibelhertz committed Sep 8, 2014
1 parent 0740f53 commit c513310
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
13 changes: 12 additions & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# $access_times - optional
# $log_type - optional
# $bind - optional
# $nice - optional
#
# Actions:
# setups up a xinetd service by creating a file in /etc/xinetd.d/
Expand All @@ -57,6 +58,7 @@
# cps => '100 2',
# flags => 'IPv4',
# per_source => '11',
# nice => '19',
# } # xinetd::service
#
define xinetd::service (
Expand Down Expand Up @@ -86,7 +88,8 @@
$no_access = undef,
$access_times = undef,
$log_type = undef,
$bind = undef
$bind = undef,
$nice = undef
) {

include xinetd
Expand All @@ -101,6 +104,13 @@
}
}

if $nice {
validate_re($nice,'^-?[0-9]+$')
if !is_numeric($nice) or $nice < -19 or $nice > 19 {
fail("Invalid value for nice, ${nice}")
}
}

# Template uses:
# - $port
# - $disable
Expand All @@ -126,6 +136,7 @@
# - $no_access
# - $access_types
# - $log_type
# - $nice
file { "${xinetd::confdir}/${title}":
ensure => $ensure,
owner => 'root',
Expand Down
21 changes: 21 additions & 0 deletions spec/defines/xinetd_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,25 @@
}
end

# nice values, good
['-19','9','19'].each do |i|
describe "with nice #{i}" do
let :params do
default_params.merge({ :nice => i })
end
it {
should contain_file('/etc/xinetd.d/httpd').with_content(
/nice\s*=\s*#{i}/)
}
end
end
# nice values, bad
['-20','90','foo'].each do |i|
describe "with nice #{i}" do
let :params do
default_params.merge({ :nice => i })
end
it { expect { should compile }.to raise_error(Puppet::Error) }
end
end
end
3 changes: 3 additions & 0 deletions templates/service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ service <%= @service_name %>
<% if @log_type -%>
log_type = <%= @log_type %>
<% end -%>
<% if @nice -%>
nice = <%= @nice %>
<% end -%>
}

0 comments on commit c513310

Please sign in to comment.