<commit_before># Cookbook Name:: rs_utils
# Recipe:: install_utils
#
# Copyright (c) 2009 RightScale Inc
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#TODO: this compat package should no longer be necessary, chef service resource does not
# require this and it was only used for legacy templates afaik.
#install rs_utils command for ubuntu
#package "sysvconfig" do
#  only_if { @node[:platform] == "ubuntu" }
#end

#setup timezone
link "/usr/share/zoneinfo/#{@node[:rs_utils][:timezone]}" do 
  to "/etc/localtime"
end

#configure syslog
if "#{@node[:rightscale][:servers][:lumberjack][:hostname]}" != ""
  package "syslog-ng" 

  execute "ensure_dev_null" do 
    creates "/dev/null.syslog-ng"
    command "mknod /dev/null.syslog-ng c 1 3"
  end

  service "syslog-ng" do
    supports :start => true, :stop => true, :restart => true
    action [ :enable ]
  end

  template "/etc/syslog-ng/syslog-ng.conf" do
    source "syslog.erb"
    notifies :restart, resources(:service => "syslog-ng")
  end

  bash "configure_logrotate_for_syslog" do 
    code <<-EOH
      perl -p -i -e 's/weekly/daily/; s/rotate\s+\d+/rotate 7/' /etc/logrotate.conf
      [ -z "$(grep -lir "missingok" #{@node[:rs_utils][:logrotate_config]}_file)" ] && sed -i '/sharedscripts/ a\    missingok' #{@node[:rs_utils][:logrotate_config]}
      [ -z "$(grep -lir "notifempty" #{@node[:rs_utils][:logrotate_config]}_file)" ] && sed -i '/sharedscripts/ a\    notifempty' #{@node[:rs_utils][:logrotate_config]}
    EOH
  end
end

directory "/var/spool/oldmail" do 
  recursive true 
  mode "775"
  owner "root"
  group "mail"
end

remote_file "/etc/logrotate.d/mail" do 
  source "mail"
end

#configure collectd
package "collectd" 

# use collectdmon
if node[:platform] == 'centos'
  remote_file "/etc/init.d/collectd" do
    source "collectd-init-centos-with-monitor"
    mode 0755
  end
end

service "collectd" do 
  action :enable
end

# create collectd types.db file unless it already exists
if node.platform == "ubuntu"
  log "Perform Ubuntu Specific collectd install..."
  package "liboping0" 

  if node.platform_version != "8.04"
    remote_file ::File.join(node[:rs_utils][:collectd_lib], 'types.db') do 
      not_if { ::File.exists?(::File.join(node[:rs_utils][:collectd_lib], 'types.db')) }
      source "karmic_types.db"
    end

    log "Adding symlink to collectd types.db"
    execute "ln -s /usr/share/collectd/types.db /usr/lib/collectd/types.db"     
  end  
end

directory @node[:rs_utils][:collectd_plugin_dir] do
  recursive true
end

template @node[:rs_utils][:collectd_config] do <commit_msg>rs_util: using link resource<commit_after># Cookbook Name:: rs_utils
# Recipe:: install_utils
#
# Copyright (c) 2009 RightScale Inc
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#TODO: this compat package should no longer be necessary, chef service resource does not
# require this and it was only used for legacy templates afaik.
#install rs_utils command for ubuntu
#package "sysvconfig" do
#  only_if { @node[:platform] == "ubuntu" }
#end

#setup timezone
link "/usr/share/zoneinfo/#{@node[:rs_utils][:timezone]}" do 
  to "/etc/localtime"
end

#configure syslog
if "#{@node[:rightscale][:servers][:lumberjack][:hostname]}" != ""
  package "syslog-ng" 

  execute "ensure_dev_null" do 
    creates "/dev/null.syslog-ng"
    command "mknod /dev/null.syslog-ng c 1 3"
  end

  service "syslog-ng" do
    supports :start => true, :stop => true, :restart => true
    action [ :enable ]
  end

  template "/etc/syslog-ng/syslog-ng.conf" do
    source "syslog.erb"
    notifies :restart, resources(:service => "syslog-ng")
  end

  bash "configure_logrotate_for_syslog" do 
    code <<-EOH
      perl -p -i -e 's/weekly/daily/; s/rotate\s+\d+/rotate 7/' /etc/logrotate.conf
      [ -z "$(grep -lir "missingok" #{@node[:rs_utils][:logrotate_config]}_file)" ] && sed -i '/sharedscripts/ a\    missingok' #{@node[:rs_utils][:logrotate_config]}
      [ -z "$(grep -lir "notifempty" #{@node[:rs_utils][:logrotate_config]}_file)" ] && sed -i '/sharedscripts/ a\    notifempty' #{@node[:rs_utils][:logrotate_config]}
    EOH
  end
end

directory "/var/spool/oldmail" do 
  recursive true 
  mode "775"
  owner "root"
  group "mail"
end

remote_file "/etc/logrotate.d/mail" do 
  source "mail"
end

#configure collectd
package "collectd" 

# use collectdmon
if node[:platform] == 'centos'
  remote_file "/etc/init.d/collectd" do
    source "collectd-init-centos-with-monitor"
    mode 0755
  end
end

service "collectd" do 
  action :enable
end

# create collectd types.db file unless it already exists
if node.platform == "ubuntu"
  log "Perform Ubuntu Specific collectd install..."
  package "liboping0" 

  if node.platform_version != "8.04"
    remote_file ::File.join(node[:rs_utils][:collectd_lib], 'types.db') do 
      not_if { ::File.exists?(::File.join(node[:rs_utils][:collectd_lib], 'types.db')) }
      source "karmic_types.db"
    end

    link "/usr/lib/collectd/types.db"  do
      to "/usr/share/collectd/types.db"
    end   
  end  
end

directory @node[:rs_utils][:collectd_plugin_dir] do
  recursive true
end

template @node[:rs_utils][:collectd_config] do 
{'fraction_non_alphanumeric': 0.11770441565677671, 'fraction_numerical': 0.005014625992478061, 'mean_word_length': 4.042134831460674, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '813702', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2273, 'n_words': 784}