lib/facter/security_baseline/common/check_service_enabled.rb
def check_service_is_enabled(service, os = '', release = '')
  if os.casecmp('redhat').zero? && (release != '') && (release.to_i <= 6)
    srv = Facter::Core::Execution.exec("chkconfig --list #{service} | grep ':on'")
    if srv.nil? || srv.empty?
      'disabled'
    else
      'enabled'
    end
  else
    srv = Facter::Core::Execution.exec("systemctl is-enabled #{service}")
    if srv.nil? || srv.empty? || (srv =~ %r{^Failed}) || srv =~ %r{Failed to get unit file state}
      'disabled'
    else
      srv
    end
  end
end
# check if a systemd service is enabled
check if a systemd service is enabled
check if a systemd service is enabled
def check_service_is_enabled(service, os = '', release = '')
  if os.casecmp('redhat').zero? && (release != '') && (release.to_i <= 6)
    srv = Facter::Core::Execution.exec("chkconfig --list #{service} | grep ':on'")
    if srv.nil? || srv.empty?
      'disabled'
    else
      'enabled'
    end
  else
    srv = Facter::Core::Execution.exec("systemctl is-enabled #{service}")
    if srv.nil? || srv.empty? || (srv =~ %r{^Failed}) || srv =~ %r{Failed to get unit file state}
      'disabled'
    else
      srv
    end
  end
end
def check_service_is_enabled ( service , os = '' , release = '' ) if os . casecmp ( 'redhat' ) . zero? && ( release != '' ) && ( release . to_i <= 6 ) srv = Facter :: Core :: Execution . exec ( "chkconfig --list #{service} | grep ':on'" ) if srv . nil? || srv . empty? 'disabled' else 'enabled' end else srv = Facter :: Core :: Execution . exec ( "systemctl is-enabled #{service}" ) if srv . nil? || srv . empty? || ( srv =~ %r{ ^Failed } ) || srv =~ %r{ Failed to get unit file state } 'disabled' else srv end end end
check if a systemd service is enabled
check if a systemd service is enabled
service
os
release