configure

in chef/cookbooks/cpe_metricbeat/resources/cpe_metricbeat.rb [52:89]


  def configure
    
    if metricbeat_conf.empty? || metricbeat_conf.nil?
      Chef::Log.warn('config is not populated, skipping configuration')
      return
    end

    setup_macos_service if macos?
    setup_debian_service if debian?

    prefix = node['cpe_launchd']['prefix'] || 'com.uber.chef'
    service_info = value_for_platform_family(
      'mac_os_x' => { 'launchd' => "#{prefix}.metricbeat" },
      'debian' => { 'systemd_unit' => 'metricbeat.service' },
      'windows' => { 'windows_service' => 'metricbeat' },
      'default' => nil,
    )
    service_type, service_name = service_info.first
    
    if macos?
      launchd service_name do
        action :nothing
        only_if { ::File.exist?("/Library/LaunchDaemons/#{service_name}.plist") }
        subscribes :restart, 'cpe_remote_zip[metricbeat_zip]'
      end
    end
    config = ::File.join(metricbeat_dir, 'metricbeat.chef.yml')
    file config do
      owner root_owner
      group node['root_group']
      content YAML.dump(metricbeat_conf)
      notifies :restart, "#{service_type}[#{service_name}]"
    end
    
    
    setup_windows_service if windows?
  end