Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into tas50-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
tas50 authored May 17, 2017
2 parents a93c228 + 40d9483 commit aef1005
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ There are two main ways to interact with the cookbook. This is via chef [attribu
* `node['sysctl']['params']` - A namespace for setting sysctl parameters.
* `node['sysctl']['conf_dir']` - Specifies the sysctl.d directory to be used. Defaults to `/etc/sysctl.d` on the Debian and RHEL platform families, otherwise `nil`
* `node['sysctl']['allow_sysctl_conf']` - Defaults to false. Using `conf_dir` is highly recommended. On some platforms that is not supported. For those platforms, set this to `true` and the cookbook will rewrite the `/etc/sysctl.conf` file directly with the params provided. Be sure to save any local edits of `/etc/sysctl.conf` before enabling this to avoid losing them.
* `node['sysctl']['restart_procps']` - Defaults to true. Will allow the consumer of the cookbook to control whether or not to notify procps to restart sysctl to load the newly set values.

Note: if `node['sysctl']['conf_dir']` is set to nil and `node['sysctl']['allow_sysctl_conf']` is not set, no config will be written

Expand Down
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
default['sysctl']['allow_sysctl_conf'] = false
default['sysctl']['conf_file'] = '/etc/sysctl.conf'
default['sysctl']['conf_dir'] = nil
default['sysctl']['restart_procps'] = true

if platform_family?('freebsd')
default['sysctl']['allow_sysctl_conf'] = true
Expand Down
2 changes: 1 addition & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@
action :nothing
source 'sysctl.conf.erb'
mode '0644'
notifies :restart, 'service[procps]', :immediately
notifies :restart, 'service[procps]', :immediately if node['sysctl']['restart_procps']
end
end
41 changes: 41 additions & 0 deletions spec/restart_false_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'spec_helper'

# examples at https://github.com/sethvargo/chefspec/tree/master/examples

describe 'sysctl::default' do
platforms = {
'ubuntu' => ['14.04', '16.04'],
'debian' => ['7.11', '8.7'],
'fedora' => ['25'],
'redhat' => ['6.8', '7.3'],
'centos' => ['6.8', '7.3.1611'],
'freebsd' => ['10.3', '11.0'],
'suse' => ['12.2'],
}

# Test all generic stuff on all platforms
platforms.each do |platform, versions|
versions.each do |version|
context "on #{platform.capitalize} #{version}" do
let(:chef_run) do
ChefSpec::SoloRunner.new(platform: platform, version: version) do |node|
node.override['sysctl']['restart_procps'] = false
end.converge('sysctl::default')
end

let(:template) do
if platform == 'freebsd'
chef_run.template('/etc/sysctl.conf.local')
elsif platform == 'suse' && version.to_f < 12.0
chef_run.template('/etc/sysctl.conf')
else
chef_run.template('/etc/sysctl.d/99-chef-attributes.conf')
end
end
it 'should not restart procps if restart_procps is false' do
expect(template).to_not notify('service[procps]').immediately if expect(chef_run.node['sysctl']['restart_procps']).to be false
end
end
end
end
end

0 comments on commit aef1005

Please sign in to comment.