NodeInitPackage

All Cookstyle Cops


The department is: Chef/Modernize

The full name of the cop is: Chef/Modernize/NodeInitPackage


Enabled by default Supports autocorrection Target Chef Version
Enabled Yes All Versions

Use node[‘init_package’] to check for systemd instead of reading the contents of ‘/proc/1/comm’

Examples

incorrect

::File.open('/proc/1/comm').gets.chomp == 'systemd'
::File.open('/proc/1/comm').chomp == 'systemd'
File.open('/proc/1/comm').gets.chomp == 'systemd'
File.open('/proc/1/comm').chomp == 'systemd'
IO.read('/proc/1/comm').chomp == 'systemd'
IO.read('/proc/1/comm').gets.chomp == 'systemd'
::IO.read('/proc/1/comm').chomp == 'systemd'
::IO.read('/proc/1/comm').gets.chomp == 'systemd'
File.exist?('/proc/1/comm') && File.open('/proc/1/comm').chomp == 'systemd'
only_if 'test -f /bin/systemctl && /bin/systemctl'

correct

node['init_package'] == 'systemd'
only_if { node['init_package'] == 'systemd' }

Configurable attributes

Name Default value Configurable values
Version Added 5.22.0 String
Exclude
  • **/metadata.rb
  • **/Berksfile
Array

© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/workstation/cookstyle/chef_modernize_nodeinitpackage/