<commit_before>#
# Cookbook Name:: td-agent
# Recipe:: default
#
# Copyright 2011, Treasure Data, Inc.
#

Chef::Recipe.send(:include, TdAgent::Version)
Chef::Provider.send(:include, TdAgent::Version)

group 'td-agent' do
  group_name 'td-agent'
  gid node["td_agent"]["gid"] if node["td_agent"]["gid"]
  system true
  action     [:create]
end

user 'td-agent' do
  comment  'td-agent'
  uid node["td_agent"]["uid"] if node["td_agent"]["uid"]
  system true
  group    'td-agent'
  home     '/var/run/td-agent'
  shell    '/bin/false'
  password nil
  supports :manage_home => true
  action   [:create, :manage]
end

directory '/var/run/td-agent/' do
  owner  'td-agent'
  group  'td-agent'
  mode   '0755'
  action :create
end

directory '/etc/td-agent/' do
  owner  'td-agent'
  group  'td-agent'
  mode   '0755'
  action :create
end

case node['platform_family']
when "debian"
  dist = node['lsb']['codename']
  platform = node["platform"]
  source =
    if major.nil? || major == '1'
      # version 1.x or no version
      if dist == 'precise'
        'http://packages.treasuredata.com/precise/'
      else
        'http://packages.treasuredata.com/debian/'
      end
    else
      # version 2.x or later
      "http://packages.treasuredata.com/#{major}/#{platform}/#{dist}/"
    end

  apt_repository "treasure-data" do
    uri source
    arch node["td_agent"]["apt_arch"]
    distribution dist
    components ["contrib"]
    key "https://packages.treasuredata.com/GPG-KEY-td-agent"
    action :add
  end
when "rhel"
  source =
    if major.nil? || major == '1'
      "http://packages.treasuredata.com/redhat/$basearch"
    else
      # version 2.x or later
      "http://packages.treasuredata.com/2/redhat/$releasever/$basearch"
    end

  yum_repository "treasure-data" do
    url source
    gpgkey "https://packages.treasuredata.com/GPG-KEY-td-agent"
    action :add
  end
end

reload_action = (reload_available?) ? :reload : :restart

template "/etc/td-agent/td-agent.conf" do
  mode "0644"
  cookbook node['td_agent']['template_cookbook']
  source "td-agent.conf.erb"
  notifies reload_action, "service[td-agent]"
end

directory "/etc/td-agent/conf.d" do
  mode "0755"
  only_if { node["td_agent"]["includes"] }
end

package "td-agent" do
  if node["td_agent"]["pinning_version"]
    action :install
    version node["td_agent"]["version"]
  else
    action :upgrade
  end
end

node["td_agent"]["plugins"].each do |plugin|
  if plugin.is_a?(Hash)
    plugin_name, plugin_attributes = plugin.first
    td_agent_gem plugin_name do
      plugin true
      %w{action version source options gem_binary}.each do |attr|
        send(attr, plugin_attributes[attr]) if plugin_attributes[attr]
      end
    end
  elsif plugin.is_a?(String)
    td_agent_gem plugin do
      plugin true
    end
  end
end

service "td-agent" do
  supports :restart => true, :reload => (reload_action == :reload), :status => true
  action [ :enable, :start ]
end
<commit_msg>Delay the reload in case a wrapper cookbook has other conf.d files to change<commit_after>#
# Cookbook Name:: td-agent
# Recipe:: default
#
# Copyright 2011, Treasure Data, Inc.
#

Chef::Recipe.send(:include, TdAgent::Version)
Chef::Provider.send(:include, TdAgent::Version)

group 'td-agent' do
  group_name 'td-agent'
  gid node["td_agent"]["gid"] if node["td_agent"]["gid"]
  system true
  action     [:create]
end

user 'td-agent' do
  comment  'td-agent'
  uid node["td_agent"]["uid"] if node["td_agent"]["uid"]
  system true
  group    'td-agent'
  home     '/var/run/td-agent'
  shell    '/bin/false'
  password <PASSWORD>
  supports :manage_home => true
  action   [:create, :manage]
end

directory '/var/run/td-agent/' do
  owner  'td-agent'
  group  'td-agent'
  mode   '0755'
  action :create
end

directory '/etc/td-agent/' do
  owner  'td-agent'
  group  'td-agent'
  mode   '0755'
  action :create
end

case node['platform_family']
when "debian"
  dist = node['lsb']['codename']
  platform = node["platform"]
  source =
    if major.nil? || major == '1'
      # version 1.x or no version
      if dist == 'precise'
        'http://packages.treasuredata.com/precise/'
      else
        'http://packages.treasuredata.com/debian/'
      end
    else
      # version 2.x or later
      "http://packages.treasuredata.com/#{major}/#{platform}/#{dist}/"
    end

  apt_repository "treasure-data" do
    uri source
    arch node["td_agent"]["apt_arch"]
    distribution dist
    components ["contrib"]
    key "https://packages.treasuredata.com/GPG-KEY-td-agent"
    action :add
  end
when "rhel"
  source =
    if major.nil? || major == '1'
      "http://packages.treasuredata.com/redhat/$basearch"
    else
      # version 2.x or later
      "http://packages.treasuredata.com/2/redhat/$releasever/$basearch"
    end

  yum_repository "treasure-data" do
    url source
    gpgkey "https://packages.treasuredata.com/GPG-KEY-td-agent"
    action :add
  end
end

reload_action = (reload_available?) ? :reload : :restart

template "/etc/td-agent/td-agent.conf" do
  mode "0644"
  cookbook node['td_agent']['template_cookbook']
  source "td-agent.conf.erb"
  notifies reload_action, "service[td-agent]", :delayed
end

directory "/etc/td-agent/conf.d" do
  mode "0755"
  only_if { node["td_agent"]["includes"] }
end

package "td-agent" do
  if node["td_agent"]["pinning_version"]
    action :install
    version node["td_agent"]["version"]
  else
    action :upgrade
  end
end

node["td_agent"]["plugins"].each do |plugin|
  if plugin.is_a?(Hash)
    plugin_name, plugin_attributes = plugin.first
    td_agent_gem plugin_name do
      plugin true
      %w{action version source options gem_binary}.each do |attr|
        send(attr, plugin_attributes[attr]) if plugin_attributes[attr]
      end
    end
  elsif plugin.is_a?(String)
    td_agent_gem plugin do
      plugin true
    end
  end
end

service "td-agent" do
  supports :restart => true, :reload => (reload_action == :reload), :status => true
  action [ :enable, :start ]
end

{'fraction_non_alphanumeric': 0.142022696929239, 'fraction_numerical': 0.008678237650200267, 'mean_word_length': 3.2383309759547383, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4182335', 'n_tokens_mistral': 2111, 'n_tokens_neox': 2098, 'n_words': 500}