class RuboCop::Cop::Chef::Correctness::ServiceResource
Use a service resource to start and stop services
@example when command starts a service
### incorrect command "/etc/init.d/mysql start" command "/sbin/service/memcached start"
Constants
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
Source
# 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
Source
# 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