Class: RuboCop::Cop::Chef::Correctness::ServiceResource
- Defined in:
- lib/rubocop/cop/chef/correctness/service_resource.rb
Overview
Use a service resource to start and stop services
Constant Summary collapse
- MSG =
'Use a service resource to start and stop services'
- RESTRICT_ON_SEND =
[:command].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_send(node) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rubocop/cop/chef/correctness/service_resource.rb', line 37 def on_send(node) execute_command?(node) do |command| if starts_service?(command) add_offense(command, severity: :refactor) end end end |
#starts_service?(cmd) ⇒ Boolean
45 46 47 48 49 50 51 |
# File 'lib/rubocop/cop/chef/correctness/service_resource.rb', line 45 def starts_service?(cmd) cmd_str = cmd.to_s (cmd_str.include?('/etc/init.d') || ['service ', '/sbin/service ', 'start ', 'stop ', 'invoke-rc.d '].any? do |service_cmd| cmd_str.start_with?(service_cmd) end) && %w(start stop restart reload).any? { |a| cmd_str.include?(a) } end |