├── .circleci
└── config.yml
├── .delivery
└── project.toml
├── .editorconfig
├── .github
├── CODEOWNERS
├── ISSUE_TEMPLATE.md
├── PULL_REQUEST_TEMPLATE.md
└── lock.yml
├── .gitignore
├── .gitmodules
├── .kitchen.dokken.yml
├── .kitchen.yml
├── .rubocop.yml
├── Berksfile
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Dangerfile
├── Guardfile
├── LICENSE
├── README.md
├── TESTING.md
├── chefignore
├── files
└── plugins
│ └── sys.rb
├── metadata.rb
├── recipes
├── default.rb
└── ohai_plugin.rb
├── resources
├── param.rb
└── reload.rb
├── spec
├── spec_helper.rb
└── sysctl_test
│ └── default_spec.rb
└── test
├── cookbooks
└── test
│ ├── metadata.rb
│ └── recipes
│ └── default.rb
└── integration
└── default
└── inspec
└── default_spec.rb
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 |
3 | orbs:
4 | kitchen: sous-chefs/kitchen@1.0.0
5 |
6 | workflows:
7 | kitchen:
8 | jobs:
9 | - kitchen/danger:
10 | name: danger
11 | context: Danger
12 | # - kitchen/lint:
13 | # name: lint
14 | # - kitchen/dokken:
15 | # name: default
16 | # suite: default
17 | # requires: [ danger, lint ]
18 |
--------------------------------------------------------------------------------
/.delivery/project.toml:
--------------------------------------------------------------------------------
1 | remote_file = "https://raw.githubusercontent.com/chef-cookbooks/community_cookbook_tools/master/delivery/project.toml"
2 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration file.
2 | # @link http://editorconfig.org/
3 |
4 | # This is the top-level .editorconfig file.
5 | root = true
6 |
7 | # Settings for all files.
8 | [*]
9 | end_of_line = LF
10 | indent_style = space
11 | indent_size = 2
12 | charset = utf-8
13 | trim_trailing_whitespace = true
14 | insert_final_newline = true
15 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * sous-chefs/sysctl
2 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Cookbook version
2 | [Version of the cookbook where you are encountering the issue]
3 |
4 | ### Chef-client version
5 | [Version of chef-client in your environment]
6 |
7 | ### Platform Details
8 | [Operating system distribution and release version. Cloud provider if running in the cloud]
9 |
10 | ### Scenario:
11 | [What you are trying to achieve and you can't?]
12 |
13 | ### Steps to Reproduce:
14 | [If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this cookbook or any resources it includes?]
15 |
16 | ### Expected Result:
17 | [What are you expecting to happen as the consequence of above reproduction steps?]
18 |
19 | ### Actual Result:
20 | [What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.]
21 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Description
2 |
3 | [Describe what this change achieves]
4 |
5 | ### Issues Resolved
6 |
7 | [List any existing issues this PR resolves]
8 |
9 | ### Check List
10 | - [ ] All tests pass. See https://github.com/chef-brigade/sysctl/blob/master/TESTING.md
11 | - [ ] New functionality includes testing.
12 | - [ ] New functionality has been documented in the README if applicable
13 |
--------------------------------------------------------------------------------
/.github/lock.yml:
--------------------------------------------------------------------------------
1 | # Configuration for lock-threads - https://github.com/dessant/lock-threads
2 |
3 | # Number of days of inactivity before a closed issue or pull request is locked
4 | daysUntilLock: 365
5 |
6 | # Issues and pull requests with these labels will not be locked. Set to `[]` to disable
7 | exemptLabels: []
8 |
9 | # Label to add before locking, such as `outdated`. Set to `false` to disable
10 | lockLabel: false
11 |
12 | # Comment to post before locking. Set to `false` to disable
13 | lockComment: >
14 | This thread has been automatically locked since there has not been
15 | any recent activity after it was closed. Please open a new issue for
16 | related bugs.
17 |
18 | # Limit to only `issues` or `pulls`
19 | # only: issues
20 |
21 | # Optionally, specify configuration settings just for `issues` or `pulls`
22 | # issues:
23 | # exemptLabels:
24 | # - help-wanted
25 | # lockLabel: outdated
26 |
27 | # pulls:
28 | # daysUntilLock: 30
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | foodcritic/
2 | *.rbc
3 | .config
4 | coverage
5 | InstalledFiles
6 | lib/bundler/man
7 | pkg
8 | rdoc
9 | spec/reports
10 | test/tmp
11 | test/version_tmp
12 | tmp
13 | _Store
14 | *~
15 | *#
16 | .#*
17 | \#*#
18 | .*.sw[a-z]
19 | *.un~
20 | *.tmp
21 | *.bk
22 | *.bkup
23 |
24 | # ruby/bundler files
25 | .ruby-version
26 | .ruby-gemset
27 | .rvmrc
28 | Gemfile.lock
29 | .bundle
30 | *.gem
31 |
32 | # YARD artifacts
33 | .yardoc
34 | _yardoc
35 | doc/
36 | .idea
37 |
38 | # chef stuff
39 | Berksfile.lock
40 | .kitchen
41 | .kitchen.local.yml
42 | vendor/
43 | .coverage/
44 | .zero-knife.rb
45 | Policyfile.lock.json
46 |
47 | # vagrant stuff
48 | .vagrant/
49 | .vagrant.d/
50 | .kitchen/
51 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "foodcritic/sc"]
2 | path = foodcritic/sc
3 | url = https://github.com/sous-chefs/sc-foodcritic-rules.git
4 |
--------------------------------------------------------------------------------
/.kitchen.dokken.yml:
--------------------------------------------------------------------------------
1 | driver:
2 | name: dokken
3 | privileged: true # because Docker and SystemD/Upstart
4 | chef_version: <%= ENV['CHEF_VERSION'] || 'current' %>
5 |
6 | transport:
7 | name: dokken
8 |
9 | provisioner:
10 | name: dokken
11 | deprecations_as_errors: true
12 |
13 | verifier:
14 | name: inspec
15 |
16 | platforms:
17 | - name: amazonlinux
18 | driver:
19 | image: dokken/amazonlinux
20 | pid_one_command: /sbin/init
21 |
22 | - name: amazonlinux-2
23 | driver:
24 | image: dokken/amazonlinux-2
25 | pid_one_command: /usr/lib/systemd/systemd
26 |
27 | - name: debian-8
28 | driver:
29 | image: dokken/debian-8
30 | pid_one_command: /bin/systemd
31 | intermediate_instructions:
32 | - RUN /usr/bin/apt-get update
33 |
34 | - name: debian-9
35 | driver:
36 | image: dokken/debian-9
37 | pid_one_command: /bin/systemd
38 | intermediate_instructions:
39 | - RUN /usr/bin/apt-get update
40 |
41 | - name: centos-6
42 | driver:
43 | image: dokken/centos-6
44 | pid_one_command: /sbin/init
45 |
46 | - name: centos-7
47 | driver:
48 | image: dokken/centos-7
49 | pid_one_command: /usr/lib/systemd/systemd
50 |
51 | - name: fedora-latest
52 | driver:
53 | image: dokken/fedora-latest
54 | pid_one_command: /usr/lib/systemd/systemd
55 |
56 | - name: ubuntu-14.04
57 | driver:
58 | image: dokken/ubuntu-14.04
59 | pid_one_command: /sbin/init
60 | intermediate_instructions:
61 | - RUN /usr/bin/apt-get update
62 |
63 | - name: ubuntu-16.04
64 | driver:
65 | image: dokken/ubuntu-16.04
66 | pid_one_command: /bin/systemd
67 | intermediate_instructions:
68 | - RUN /usr/bin/apt-get update
69 |
70 | - name: ubuntu-18.04
71 | driver:
72 | image: dokken/ubuntu-18.04
73 | pid_one_command: /bin/systemd
74 | intermediate_instructions:
75 | - RUN /usr/bin/apt-get update
76 |
77 | - name: opensuse-leap
78 | driver:
79 | image: dokken/opensuse-leap
80 | pid_one_command: /bin/systemd
81 |
--------------------------------------------------------------------------------
/.kitchen.yml:
--------------------------------------------------------------------------------
1 | driver:
2 | name: vagrant
3 |
4 | provisioner:
5 | name: chef_zero
6 | deprecations_as_errors: true
7 | product_name: chef
8 | product_version: 13.6
9 |
10 | verifier:
11 | name: inspec
12 |
13 | platforms:
14 | - name: amazonlinux
15 | driver:
16 | box: mvbcoding/awslinux
17 | - name: centos-6
18 | - name: centos-7
19 | - name: debian-8
20 | - name: debian-9
21 | - name: fedora-27
22 | - name: opensuse-leap-42
23 | - name: sles-12-sp1
24 | driver:
25 | box: chef/sles-12-sp1-x86_64 # private box
26 | - name: ubuntu-14.04
27 | - name: ubuntu-16.04
28 |
29 | suites:
30 | - name: default
31 | run_list:
32 | - recipe[test::default]
33 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | AllCops:
2 | Exclude:
3 | - 'Dangerfile'
4 |
--------------------------------------------------------------------------------
/Berksfile:
--------------------------------------------------------------------------------
1 | source 'https://supermarket.chef.io'
2 |
3 | metadata
4 |
5 | group :integration do
6 | cookbook 'test', path: 'test/cookbooks/test'
7 | end
8 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Sysctl
2 |
3 | ## v1.1.0 (2019-11-07)
4 |
5 | - exposed the `sysctl_param` resource as `sysctl` as well to make upgrades less painful
6 |
7 | ## v1.0.5 (2018-04-27)
8 |
9 | - Remove the last remains of the parameter backup functionality in the param resource
10 | - Use more friendly resource names when reloading the sysctl values
11 | - Fixed ignore_error to actually work and set it to not show up in reporting
12 | - Simplified how we load the current value
13 |
14 | ## v1.0.4 (2018-04-07)
15 |
16 | - The param resource from this cookbook is now shipping as part of Chef 14\. With the inclusion of this resource into Chef itself we are now deprecating this cookbook. It will continue to function for Chef 13 users, but will not be updated.
17 |
18 | ## v1.0.3 (2018-03-14)
19 |
20 | - Refactor sysctl helpers into the correct files
21 | - Hard fail on FreeBSD/SLEZ < 12 [#125](https://github.com/sous-chefs/sysctl/pull/125)
22 |
23 | ## v1.0.2 (2018-02-28)
24 |
25 | - Removed sysctl collection in ohai for non-Linux hosts. This cookbook doesn't support it so we shouldn't increase ohai runtimes by collecting this data
26 | - Removed the mention of attributes in the readme and put a large warning for users upgrading to 1.0
27 | - Remove a debug statement that was left in the param resource
28 | - Fixed the :remove action in the param resource to not converge when there isn't a entry to remove
29 | - Increased the required Chef version to 12.7 since we're using action_class in the resource which had several bugs in 12.5/12.6
30 |
31 | ## v1.0.1 (2018-02-19)
32 |
33 | - Add back systctl::default recipe, but log a warning that the recipe should be removed from cookbooks / runlists. Please update your cookbooks to require systctl 1 or later and remove this recipe.
34 |
35 | ## v1.0.0 (2018-02-17)
36 |
37 | - Remove mentions of attributes
38 | - `sysctl_param` now doesn't use attributes
39 | - update ohai to 5+ to remove `compat_resource` dependency
40 | - Move all helpers into helpers.rb
41 | - Remove unused methods in the helpers
42 | - Turn `template` into `cookbook_file`
43 |
44 | ### Behaviour Change
45 |
46 | - Always ignore error when getting a key, that way the error is vomited back into the Chef run if there is one.
47 | - Now use sysctl -p to set attributes This mean we can set/unset sysctl_param in one run.
48 | - Fix reload resource for systemd
49 | - No longer require `recipes:default` to be added to persist a parameter
50 |
51 | ## v0.10.2 (2017-09-17)
52 |
53 | - Add attribute to handle with sysctl -e flag (#99)
54 |
55 | ## v0.10.1 (2017-08-07)
56 |
57 | - Fix a typo in the helper that caused the cookbook to fail
58 |
59 | ## v0.10.0 (2017-07-31)
60 |
61 | - Added support for Amazon Linux, Oracle Linux, and openSUSE
62 | - Removed support for Ubuntu 14.10, Ubuntu <= 9.10, and Fedora < 18
63 | - Resolved CHEF-19 Deprecation warnings that will impact Chef 14 runs
64 | - Expanded Travis testing to more platforms and releases
65 | - Removed problematic cdrom autoeject test that didn't work on all platforms
66 | - Reenabled testing of FoodCritic rules FC059 and FC085
67 | - Enabled testing of Chef deprecation warnings
68 |
69 | ## v0.9.0 (2017-05-18)
70 |
71 | - This cookbook is now maintained by Sous-Chefs. See
72 | - Fixed 'ImmutableAttributeModification' error in remove_sysctl_param
73 | - Added a new attribute `node['sysctl']['restart_procps']` to control restarting post change
74 | - Removed deprecated "conflicts" metadata
75 | - Updated the metadata license string to be a SPDX standard license string
76 | - Removed Chef 11 compatibility in the metadata.rb file
77 | - Switched testing to ChefDK instead of test gems in the Gemfile
78 | - Converted ServerSpec tests to InSpec
79 | - Updated ChefSpecs to test against the latest platform releases
80 | - Added testing with Foodcritic and a .foodcritic file to ignore certain failures
81 |
82 | ## v0.8.1 (2016-10-29)
83 |
84 | - [GH-64] Relax ohai cookbook dependency to >= 4
85 | - Specify ohai version needs to be >= 8
86 | - [GH-65] Use systemd-sysctl service for ubuntu > 15+
87 |
88 | ## v0.8.0 (2016-06-30)
89 |
90 | - [GH-55] Update README with FreeBSD 10.3 support
91 | - [GH-59] Update to ohai cookbook 4
92 |
93 | This cookbook indirectly now requires Chef 12+. If you require Chef 11 support you'll need to pin to version 0.7.5 in your environment.
94 |
95 | ## v0.7.5 (2016-04-12)
96 |
97 | - [GH-51] revert FC059: declare use_inline_resources
98 |
99 | ## v0.7.4 (2016-04-11)
100 |
101 | - FC059: declare use_inline_resources
102 |
103 | ## v0.7.3 (2016-04-11)
104 |
105 | - Added suse to metadata.rb
106 | - Update gem and berkshelf cookbook dependencies
107 |
108 | ## v0.7.2 (2016-03-24)
109 |
110 | - [GH-33] Addd initial Suse 11 & 12 support
111 | - [GH-48] version pin 3.0 of the Ohai cookbook
112 | - [GH-47] Rename key_path local var to key_path_tokens for clarity
113 | - [GH-50] Resolves Rubocop complaint about nested ifs.
114 | - [GH-46] Use fail instead of raise
115 | - Update gem and berkshelf cookbook dependencies
116 |
117 | ## v0.7.0 (2015-12-03)
118 |
119 | - Update gem and berkshelf cookbook dependencies
120 | - Update documentation to suggest using chefdk for development
121 | - Travis now uses ruby 2.1+
122 | - [GH-8] Update README.md mentioning Archlinux and Exherbo
123 | - [GH-38] Update to ServerSpec2
124 | - [GH-36] ArchLinux fixes
125 | - [GH-41] RHEL 7 Systemd support updates
126 | - [GH-18] Added note on support for /etc/sysctl.d/ and using it on RHEL 6.2 or later.
127 | - [GH-30] Add support for Ubuntu Vivid (15.04)
128 | - [GH-16] Support ubuntu 14.10
129 | - [GH-31] Adjust sysctl::apply to use :restart instead of :start for better systemd support
130 |
131 | ## v0.6.2 (2014-12-06)
132 |
133 | - Fix rubocop error and packaging error
134 |
135 | ## v0.6.1 (2014-12-06)
136 |
137 | - [GH-14] Update to chefspec 4.1 , rubocop 27, foodcritic 4
138 |
139 | ```
140 | Update matchers.rb for deprecated chefspec method.
141 | ```
142 |
143 | - [GH-13] OneHealth was acquired by Viverae, update Gitter
144 |
145 | - [GH-12] Update documentation to reflect inclusion of default recipe for LWRP
146 |
147 | - Added initial FreeBSD support
148 |
149 | - [GH-7] Added systemd based distros support
150 |
151 | ## v0.6.0 (2014-05-19)
152 |
153 | - Rename `sysctl::persist` to `sysctl::apply` to more clearly reflect usage
154 | - [GH-5] Improve immediate setting of attribute parameters during `sysctl::apply` run
155 |
156 | ## v0.5.6 (2014-05-16)
157 |
158 | - Uploaded development version.
159 |
160 | ## v0.5.4 (2014-05-16)
161 |
162 | - Manual upload
163 |
164 | ## v0.5.3 (2014-05-16)
165 |
166 | - upload timed out to community cookbook for 0.5.2
167 |
168 | ## v0.5.2 (2014-05-16)
169 |
170 | - Failed upload to community site
171 |
172 | ## v0.5.1 (2014-05-16)
173 |
174 | - Now managed by [Stove](https://github.com/sethvargo/stove)
175 |
176 | ## v0.5.0 (2014-05-16)
177 |
178 | - BREAKING CHANGE: For parameters to persist on reboot that are set via attributes, you now need to include `sysctl::persist` instead of `sysctl::default`. This allows LWRP users to use the cookbook without needing to load `sysctl::default` in their run list.
179 | - Standardize on using Stove for community site management
180 | - Updated Ubuntu tests to no longer test Lucid and focus on Precise and Trusty
181 | - [GH-3] Improve idempotency with respect to sysctl config file when using lwrps (Michael S. Fischer)
182 | - Added Ohai 7 plugin which exposes sysctl parameters via node['sys'] (Sander van Zoest, Guilhem Lettron)
183 | - Fully switch to serverspec tests, added separate suites for attributes and lwrp invocation
184 |
185 | ## v0.4.0 (2014-04-04)
186 |
187 | - [GH-24] On RHEL Adjust Init file to follow chkconfig standards (Alex Farhadi)
188 | - [GH-22] lwrp parameters are written to the sysctl config file (Sander van Zoest, Guilhem Lettron)
189 | - Entries in the sysctl config file are now sorted
190 | - Removed Thor development dependency
191 | - Added LWRP Matcher for use with ChefSpec by wrapper cookbooks
192 | - Added ChefSpec 3 unit tests
193 | - Ported bats tests to ServerSpec integration tests
194 | - Use platform_family? in attributes (requires Ohai 0.6.12)
195 | - Renamed ruby_block[sysctl config notifier] to ruby_block[save-sysctl-params] for clarity
196 | - [GH-19] Make sysctl template logic idempotent (Roy Tewalt)
197 |
198 | ## v0.3.5 (2013-12-10)
199 |
200 | - Scientific Linux 6 support confirmed
201 | - [GH-16] Document and test lwrp action :nothing
202 | - Update to test kitchen 1.1
203 | - Update to vagrant 1.4
204 | - Added CentOS 5.10 and 6.5 test boxes
205 |
206 | ## v0.3.4 (2013-11-04)
207 |
208 | - [GH-9] Make changes available immediately (Warren Vosper)
209 | - [GH-8] Added PLD Linux support (not regularily tested) (Elan Ruusam?e)
210 | - Switch to rubocop over tailor
211 | - Modernize Gemfile dependencies and add Guard for development
212 | - Fix FC048: Prefer Mixlib::ShellOut
213 |
214 | ## v0.3.3 (2013-06-14)
215 |
216 | - More explicitly define conflicting cookbooks and operating systems in metadata.rb
217 | - [GH-6] Fixed any params with spaces throw errors (Mike Pavlenko)
218 |
219 | ## v0.3.2 (2013-05-24)
220 |
221 | - [GH-5] Fixed ImmutableAttributeModification (Mark Pimentel)
222 | - Added LWRP integration tests for test kitchen
223 | - LWRP now sets attributes on the node via node.default, not node.set allowing easier overrides by other cookbooks
224 |
225 | ## v0.3.1 (2013-04-26)
226 |
227 | - Added attribute integration tests for test kitchen
228 | - Added alpha RHEL/CentOS support
229 | - Added Travis CI Builds
230 | - Cleaned up foodcritic and tailor complaints
231 |
232 | ## v0.3.0 (2013-04-23)
233 |
234 | There is a lot of talk about making one sysctl cookbook. Let's make it happen.
235 |
236 | - BREAKING CHANGE: use sysctl.params instead of sysctl.attributes to match LWRP and sysctl standard naming
237 | - [GH-1] Remove 69-chef-static.conf
238 | - New Maintainer: Sander van Zoest, OneHealth
239 | - Update Development environment with Berkshelf, Vagrant, Test-Kitchen
240 |
241 | ## v0.2.0:
242 |
243 | - [FB-3] - Notify procps start immediately
244 | - [FB-4] - Dynamic configuration file. Add LWRP.
245 | - [FB-5] - Allow Bignums as values
246 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Community Guidelines
2 |
3 | This project follows the Chef Community Guidelines
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | ## Branches
4 |
5 | ### `master` branch
6 |
7 | The master branch is the current committed changes. These changes may not yet be released although we try to release often.
8 |
9 | ## Tags
10 |
11 | All releases are tagged in git. To see the releases available to you see the changelog or the tags directly.
12 |
13 | ## Pull requests
14 |
15 | -
16 |
17 | ## Issues
18 |
19 | Need to report an issue? Use the github issues:
20 |
21 | -
22 |
--------------------------------------------------------------------------------
/Dangerfile:
--------------------------------------------------------------------------------
1 | # Reference: http://danger.systems/reference.html
2 |
3 | # A pull request summary is required. Add a description of the pull request purpose.
4 | # Add labels to the pull request in github to identify the type of change. https://help.github.com/articles/applying-labels-to-issues-and-pull-requests/
5 | # Changelog must be updated for each pull request.
6 | # Warnings will be issued for:
7 | # Pull request with more than 400 lines of code changed
8 | # Pull reqest that change more than 5 lines without test changes
9 |
10 | def code_changes?
11 | code = %w(libraries attributes recipes resources)
12 | code.each do |location|
13 | return true unless git.modified_files.grep(/#{location}/).empty?
14 | end
15 | false
16 | end
17 |
18 | def test_changes?
19 | tests = %w(spec test .kitchen.yml .kitchen.dokken.yml)
20 | tests.each do |location|
21 | return true unless git.modified_files.grep(/#{location}/).empty?
22 | end
23 | false
24 | end
25 |
26 | fail 'Please provide a summary of your Pull Request.' if github.pr_body.length < 10
27 |
28 | warn 'This is a big Pull Request.' if git.lines_of_code > 400
29 |
30 | # Require a CHANGELOG entry for non-test changes.
31 | if !git.modified_files.include?('CHANGELOG.md') && code_changes?
32 | fail 'Please include a [CHANGELOG](https://github.com/sous-chefs/line-cookbook/blob/master/CHANGELOG.md) entry.'
33 | end
34 |
35 | # A sanity check for tests.
36 | if git.lines_of_code > 5 && code_changes? && !test_changes?
37 | warn 'This Pull Request is probably missing tests.'
38 | end
39 |
--------------------------------------------------------------------------------
/Guardfile:
--------------------------------------------------------------------------------
1 | # More info at https://github.com/guard/guard#readme
2 | scope group: :unit
3 |
4 | group :unit do
5 | guard :rubocop do
6 | watch(/{.+\.rb$/)
7 | watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
8 | end
9 |
10 | guard :foodcritic, cli: '--epic-fail any --tags ~FC007 --tags ~FC015 --tags ~FC023', cookbook_paths: '.', all_on_start: false do
11 | watch(%r{attributes/.+\.rb$})
12 | watch(%r{providers/.+\.rb$})
13 | watch(%r{recipes/.+\.rb$})
14 | watch(%r{resources/.+\.rb$})
15 | watch(%r{definitions/.+\.rb$})
16 | end
17 |
18 | guard :rspec, cmd: 'bundle exec rspec --color --fail-fast', all_on_start: false do
19 | watch(%r{^libraries/(.+)\.rb$})
20 | watch(%r{^spec/(.+)_spec\.rb$})
21 | watch(%r{^(recipes)/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
22 | watch('spec/spec_helper.rb') { 'spec' }
23 | end
24 | end
25 |
26 | group :integration do
27 | guard :kitchen do
28 | watch(%r{test/.+})
29 | watch(%r{^recipes/(.+)\.rb$})
30 | watch(%r{^attributes/(.+)\.rb$})
31 | watch(%r{^files/(.+)})
32 | watch(%r{^templates/(.+)})
33 | watch(%r{^providers/(.+)\.rb})
34 | watch(%r{^resources/(.+)\.rb})
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | The sysctl resource from this cookbook is now shipping as part of Chef 14\. With the inclusion of this resource into Chef itself we are now deprecating this cookbook. It will continue to function for Chef 13 users, but will not be updated.
2 |
3 | # sysctl cookbook
4 |
5 | [](https://supermarket.chef.io/cookbooks/sysctl) [](https://circleci.com/gh/sous-chefs/sysctl) [](https://www.apache.org/licenses/LICENSE-2.0)
6 |
7 | # Warning: Depreciated Cookbook
8 |
9 | This cookbook is now a core resource in Chef 14.
10 |
11 | ## summary:
12 |
13 | Use the sysctl_param resource to set kernel parameters using the [sysctl](http://en.wikipedia.org/wiki/Sysctl) command line tool and configuration files in the system's sysctl.d directory. Configuration files managed by this resource are named 99-chef-KEYNAME.conf. If an existing value was already set for the value it will be backed up to the node and restored if the :remove action is used later.
14 |
15 | **Please read the changelog when upgrading from the v0.x series to the v1.x series**
16 |
17 | ## Requirements
18 |
19 | ### Platforms
20 |
21 | - Amazon Linux (Integration tested)
22 | - Debian/Ubuntu (Integration tested)
23 | - RHEL/CentOS (Integration tested)
24 | - openSUSE (Integration tested)
25 | - PLD Linux
26 | - Exherbo
27 | - Arch Linux
28 | - SLES 12+
29 |
30 | ### Chef
31 |
32 | - 12.7+
33 |
34 | ### sysctl_param
35 |
36 | #### Actions
37 |
38 | - `:apply` (default)
39 | - `:remove`
40 |
41 | #### Properties
42 |
43 | `property` | `type` | `description`
44 | -------------- | ----------------------------- | ------------------------------------------------------------------------------------------------
45 | `key` | String | the path to the kernel parameter
46 | `value` | String, Integer, Float, Array | the value to set for the kernel parameter
47 | `ignore_error` | True / False | Should the resource fail if setting the parameter via the `sysctl` command line was unsuccessful
48 |
49 | #### Examples
50 |
51 | Set vm.swappiness to 20 via sysctl_param resource
52 |
53 | Include `sysctl` in your metadata.rb
54 |
55 | ```ruby
56 | # metadata.rb
57 |
58 | name 'my_app'
59 | version '0.1.0'
60 | depends 'sysctl'
61 | ```
62 |
63 | Use the resource
64 |
65 | ```ruby
66 | # recipes/default.rb
67 | sysctl_param 'vm.swappiness' do
68 | value 20
69 | end
70 | ```
71 |
72 | Remove sysctl parameter and set net.ipv4.tcp_fin_timeout back to default
73 |
74 | ```ruby
75 | sysctl_param 'net.ipv4.tcp_fin_timeout' do
76 | value 30
77 | action :remove
78 | end
79 | ```
80 |
81 | Add sysctl parameter but ignore errors if they arise
82 |
83 | ```ruby
84 | sysctl_param 'kernel.randomize_va_space' do
85 | value 0
86 | ignore_error true
87 | end
88 | ```
89 |
90 | ### Ohai Plugin
91 |
92 | The cookbook also includes an Ohai plugin that can be installed by adding `sysctl::ohai_plugin` to your run_list. This will populate `node['sys']` with automatic attributes that mirror the layout of `/proc/sys`.
93 |
94 | To see Ohai plugin output manually, you can run `ohai -d /etc/chef/ohai/plugins sys` on the command line.
95 |
96 | ## Additional Reading
97 |
98 | There are a lot of different documents that talk about system control parameters, the hope here is to point to some of the most useful ones to provide more guidance as to what the possible kernel parameters are and what they mean.
99 |
100 | - [Chef OS Hardening Cookbook](https://github.com/dev-sec/chef-os-hardening)
101 | - [Linux Kernel Sysctl](https://www.kernel.org/doc/Documentation/sysctl/)
102 | - [Linux Kernel IP Sysctl](http://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt)
103 | - [Linux Performance links](http://www.brendangregg.com/linuxperf.html) by Brendan Gregg
104 | - [RHEL 7 Performance Tuning Guide](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/pdf/Performance_Tuning_Guide/Red_Hat_Enterprise_Linux-7-Performance_Tuning_Guide-en-US.pdf) by Laura Bailey and Charlie Boyle
105 | - [Performance analysis & tuning of Red Hat Enterprise Linux at Red Hat Summit 2015 (video)](https://www.youtube.com/watch?v=ckarvGJE8Qc) slides [part 1](http://videos.cdn.redhat.com/summit2015/presentations/15284_performance-analysis-tuning-of-red-hat-enterprise-linux.pdf) by Jeremy Eder, D. John Shakshober, Larry Woodman and Bill Gray
106 | - [Performance Tuning Linux Instances on EC2 (Nov 2014)](http://www.brendangregg.com/blog/2015-03-03/performance-tuning-linux-instances-on-ec2.html) by Brendan Gregg
107 | - [Part 1: Lessons learned tuning TCP and Nginx in EC2 (Jan 2014)](http://engineering.chartbeat.com/2014/01/02/part-1-lessons-learned-tuning-tcp-and-nginx-in-ec2/)
108 | - [Tuning TCP For The Web at Velocity 2013 (video)](http://vimeo.com/70369211), [slides](http://cdn.oreillystatic.com/en/assets/1/event/94/Tuning%20TCP%20For%20The%20Web%20Presentation.pdf) by Jason Cook
109 | - [THE /proc FILESYSTEM (Jun 2009)](http://www.kernel.org/doc/Documentation/filesystems/proc.txt)
110 |
111 | ## Development
112 |
113 | We have written unit tests using [chefspec](http://code.sethvargo.com/chefspec/) and integration tests in [InSpec](https://www.inspec.io//) executed via [test-kitchen](https://kitchen.ci/). Much of the tooling around this cookbook is exposed via guard and test kitchen, so it is highly recommended to learn more about those tools. The easiest way to get started is to install the [Chef Development Kit](https://downloads.chef.io/chefdk)
114 |
115 | ### Running tests
116 |
117 | Install ChefDK from chefdk.io
118 |
119 | ```bash
120 | # Run the unit & lint tests
121 | chef exec delivery local all
122 |
123 | # Run the integration suites
124 | kitchen test
125 | ```
126 |
--------------------------------------------------------------------------------
/TESTING.md:
--------------------------------------------------------------------------------
1 | Please refer to
2 | https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/TESTING.MD
3 |
--------------------------------------------------------------------------------
/chefignore:
--------------------------------------------------------------------------------
1 | # Put files/directories that should be ignored in this file when uploading
2 | # to a chef-server or supermarket.
3 | # Lines that start with '# ' are comments.
4 |
5 | # OS generated files #
6 | ######################
7 | .DS_Store
8 | Icon?
9 | nohup.out
10 | ehthumbs.db
11 | Thumbs.db
12 |
13 | # SASS #
14 | ########
15 | .sass-cache
16 |
17 | # EDITORS #
18 | ###########
19 | \#*
20 | .#*
21 | *~
22 | *.sw[a-z]
23 | *.bak
24 | REVISION
25 | TAGS*
26 | tmtags
27 | *_flymake.*
28 | *_flymake
29 | *.tmproj
30 | .project
31 | .settings
32 | mkmf.log
33 |
34 | ## COMPILED ##
35 | ##############
36 | a.out
37 | *.o
38 | *.pyc
39 | *.so
40 | *.com
41 | *.class
42 | *.dll
43 | *.exe
44 | */rdoc/
45 |
46 | # Testing #
47 | ###########
48 | .watchr
49 | .rspec
50 | spec/*
51 | spec/fixtures/*
52 | test/*
53 | features/*
54 | examples/*
55 | Guardfile
56 | Procfile
57 | .kitchen*
58 | .rubocop.yml
59 | spec/*
60 | Rakefile
61 | .travis.yml
62 | .foodcritic
63 | .codeclimate.yml
64 |
65 | # SCM #
66 | #######
67 | .git
68 | */.git
69 | .gitignore
70 | .gitmodules
71 | .gitconfig
72 | .gitattributes
73 | .svn
74 | */.bzr/*
75 | */.hg/*
76 | */.svn/*
77 | .github
78 |
79 | # Berkshelf #
80 | #############
81 | Berksfile
82 | Berksfile.lock
83 | cookbooks/*
84 | tmp
85 |
86 | # Cookbooks #
87 | #############
88 | CONTRIBUTING*
89 | CHANGELOG*
90 | TESTING*
91 | MAINTAINERS.toml
92 |
93 | # Strainer #
94 | ############
95 | Colanderfile
96 | Strainerfile
97 | .colander
98 | .strainer
99 |
100 | # Vagrant #
101 | ###########
102 | .vagrant
103 | Vagrantfile
104 |
--------------------------------------------------------------------------------
/files/plugins/sys.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Sander van Zoest ()
3 | # Copyright:: Copyright (c) 2014 OneHealth Solutions, Inc.
4 | # Copyright:: Copyright (c) 2014 Viverae, Inc.
5 | # License:: Apache License, Version 2.0
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16 | # implied.
17 | # See the License for the specific language governing permissions and
18 | # limitations under the License.
19 |
20 | Ohai.plugin(:Sysctl) do
21 | provides 'sys'
22 |
23 | def get_sysctls(cmd = 'sysctl -A')
24 | begin
25 | require 'chef/mixin/deep_merge'
26 | rescue LoadError => e
27 | Ohai::Log.warn("Cannot load gem: #{e}.")
28 | end
29 |
30 | Ohai::Log.debug("get_sysctl: running #{cmd}")
31 | so = shell_out(cmd)
32 | lines_attrs = Mash.new
33 | if so.exitstatus == 0
34 | so.stdout.lines do |line|
35 | k, v = line.split(/[=:]/)
36 | next if k.nil? || v.nil?
37 | k = k.strip
38 | v = v.strip
39 | key_path = k.split('.')
40 | attrs = Mash.new
41 | location = key_path.slice(0, key_path.size - 1).reduce(attrs) do |m, o|
42 | m[o] ||= {}
43 | m[o]
44 | end
45 | location[key_path.last] = v
46 | lines_attrs = Chef::Mixin::DeepMerge.merge(lines_attrs, attrs)
47 | end
48 | end
49 | sys.update lines_attrs
50 | end
51 |
52 | collect_data(:linux) do
53 | sys Mash.new
54 | get_sysctls
55 | end
56 | end
57 |
--------------------------------------------------------------------------------
/metadata.rb:
--------------------------------------------------------------------------------
1 | name 'sysctl'
2 | maintainer 'Sous Chefs'
3 | maintainer_email 'help@sous-chefs.org'
4 | issues_url 'https://github.com/sous-chefs/sysctl/issues'
5 | source_url 'https://github.com/sous-chefs/sysctl'
6 | license 'Apache-2.0'
7 | description 'Configures sysctl parameters'
8 | version '1.1.0'
9 | chef_version '>= 12.7' if respond_to?(:chef_version)
10 |
11 | supports 'amazon'
12 | supports 'ubuntu', '>= 14.04'
13 | supports 'debian', '>= 8.0'
14 | supports 'centos', '>= 6.0'
15 | supports 'scientific', '>= 6.4'
16 | supports 'suse', '>= 11.0'
17 | supports 'opensuseleap'
18 | supports 'redhat'
19 | supports 'pld'
20 |
21 | depends 'ohai', '>= 5.0'
22 |
--------------------------------------------------------------------------------
/recipes/default.rb:
--------------------------------------------------------------------------------
1 | Chef::Log.warn('The sysctl::default recipe has been deprecated as of version 1.0 of the sysctl cookbook. This recipe is no longer necessary to use the systctl resource. Please update your cookbooks or remove the sysctl::default recipe from your runlist.')
2 |
--------------------------------------------------------------------------------
/recipes/ohai_plugin.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: sysctl
3 | # Recipe:: ohai_plugin
4 | #
5 | # Copyright 2014, OneHealth Solutions, Inc.
6 | # Copyright 2016, Alexander van Zoest
7 | #
8 | # Licensed under the Apache License, Version 2.0 (the "License");
9 | # you may not use this file except in compliance with the License.
10 | # You may obtain a copy of the License at
11 | #
12 | # http://www.apache.org/licenses/LICENSE-2.0
13 | #
14 | # Unless required by applicable law or agreed to in writing, software
15 | # distributed under the License is distributed on an "AS IS" BASIS,
16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | # See the License for the specific language governing permissions and
18 | # limitations under the License.
19 | #
20 |
21 | ohai_plugin 'sys' do
22 | source_file 'plugins/sys.rb'
23 | end
24 |
--------------------------------------------------------------------------------
/resources/param.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: sysctl
3 | # Resource:: param
4 | #
5 | # Copyright:: 2018, Webb Agile Solutions Ltd.
6 | # Copyright:: 2018, Chef Software Inc.
7 | #
8 | # Licensed under the Apache License, Version 2.0 (the "License");
9 | # you may not use this file except in compliance with the License.
10 | # You may obtain a copy of the License at
11 | #
12 | # http://www.apache.org/licenses/LICENSE-2.0
13 | #
14 | # Unless required by applicable law or agreed to in writing, software
15 | # distributed under the License is distributed on an "AS IS" BASIS,
16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | # See the License for the specific language governing permissions and
18 | # limitations under the License.
19 | #
20 | property :key, String, name_property: true
21 | property :ignore_error, [true, false], default: false, desired_state: false
22 | property :value, [Array, String, Integer, Float], coerce: proc { |v| coerce_value(v) }, required: true
23 | property :conf_dir, String, default: '/etc/sysctl.d'
24 |
25 | resource_name :sysctl_param
26 | provides :sysctl_param
27 | provides :sysctl
28 |
29 |
30 | def after_created
31 | raise 'The systctl_param resource requires Linux as it needs sysctl and the systctl.d directory functionality.' unless node['os'] == 'linux'
32 | raise 'The systctl_param resource does not support SLES releases less than 12 as it requires a systctl.d directory' if platform_family?('suse') && node['platform_version'].to_i < 12
33 | end
34 |
35 | def coerce_value(v)
36 | case v
37 | when Array
38 | v.join(' ')
39 | else
40 | v.to_s
41 | end
42 | end
43 |
44 | # shellout to systctl to get the current value
45 | # ignore missing keys by using '-e'
46 | # convert tabs to spaces since systctl tab deliminates multivalue parameters
47 | # strip the newline off the end of the output as well
48 | load_current_value do
49 | value shell_out!("sysctl -n -e #{key}").stdout.tr("\t", ' ').strip
50 | end
51 |
52 | action :apply do
53 | converge_if_changed do
54 | # set it temporarily
55 | set_sysctl_param(new_resource.key, new_resource.value)
56 |
57 | directory new_resource.conf_dir
58 |
59 | file "#{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf" do
60 | content "#{new_resource.key} = #{new_resource.value}"
61 | end
62 |
63 | execute 'Load sysctl values' do
64 | command "sysctl #{'-e ' if new_resource.ignore_error}-p"
65 | action :run
66 | end
67 | end
68 | end
69 |
70 | action :remove do
71 | # only converge the resource if the file actually exists to delete
72 | if ::File.exist?("#{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf")
73 | converge_by "removing systctl config at #{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf" do
74 | file "#{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf" do
75 | action :delete
76 | end
77 |
78 | execute 'Load sysctl values' do
79 | command 'sysctl -p'
80 | action :run
81 | end
82 | end
83 | end
84 | end
85 |
86 | action_class do
87 | def set_sysctl_param(key, value)
88 | shell_out!("sysctl #{'-e ' if new_resource.ignore_error}-w \"#{key}=#{value}\"")
89 | end
90 | end
91 |
--------------------------------------------------------------------------------
/resources/reload.rb:
--------------------------------------------------------------------------------
1 | action :reload do
2 | Chef::Log.warn('The sysctl_reload resource has been deprecated as it is no longer necessary to set sysctl values.')
3 | end
4 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'chefspec'
2 | require 'chefspec/berkshelf'
3 |
4 | RSpec.configure do |config|
5 | config.formatter = :documentation
6 | config.color = true
7 | config.filter_run focus: true
8 | config.run_all_when_everything_filtered = true
9 | end
10 |
--------------------------------------------------------------------------------
/spec/sysctl_test/default_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'test::default' do
4 | cached(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) }
5 |
6 | context 'testing apply action' do
7 | it 'apply sysctl_param[vm.swappiness]' do
8 | expect(chef_run).to apply_sysctl_param('vm.swappiness').with(
9 | value: '19'
10 | )
11 | end
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/test/cookbooks/test/metadata.rb:
--------------------------------------------------------------------------------
1 | name 'test'
2 | version '0.1.0'
3 | depends 'sysctl'
4 |
--------------------------------------------------------------------------------
/test/cookbooks/test/recipes/default.rb:
--------------------------------------------------------------------------------
1 | sysctl_param 'net.ipv4.ip_forward' do
2 | value 0
3 | end
4 |
5 | sysctl_param 'bogus.param' do
6 | value 100000000
7 | ignore_error true
8 | end
9 |
10 | sysctl 'vm.swappiness' do
11 | value 18
12 | ignore_error true
13 | end
14 |
15 |
16 | # Amazon Linux does not support vm.swappiness
17 | sysctl_param 'vm.swappiness' do
18 | value 19
19 | ignore_error true
20 | end
21 |
22 | sysctl_param 'kernel.msgmax' do
23 | value 9000
24 | not_if { platform_family?('amazon') } # Amazon Linux does not handle undefined values
25 | end
26 |
27 | sysctl_param 'kernel.msgmax' do
28 | value 9000
29 | action :remove
30 | end
31 |
32 | sysctl_param 'bogus.sysctl_val' do
33 | value 9000
34 | action :remove
35 | end
36 |
37 | sysctl_param 'bogus.sysctl_val2' do
38 | value 1234
39 | ignore_error true
40 | end
41 |
--------------------------------------------------------------------------------
/test/integration/default/inspec/default_spec.rb:
--------------------------------------------------------------------------------
1 | if (os[:family] == 'redhat' && os[:release].start_with?('6')) || os[:name] == 'amazon'
2 |
3 | describe kernel_parameter('kernel.msgmax') do
4 | its('value') { should eq 65536 }
5 | end
6 |
7 | else
8 |
9 | describe kernel_parameter('kernel.msgmax') do
10 | its('value') { should eq 8192 }
11 | end
12 |
13 | end
14 |
15 | describe file('/etc/sysctl.d/99-chef-kernel.msgmax.conf') do
16 | it { should_not be_file }
17 | end
18 |
19 | describe kernel_parameter('vm.swappiness') do
20 | its('value') { should eq 19 }
21 | end
22 |
23 | describe file('/etc/sysctl.d/99-chef-bogus.sysctl_val2.conf') do
24 | its('content') { should eq 'bogus.sysctl_val2 = 1234' }
25 | end
26 |
--------------------------------------------------------------------------------