-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent_linux.rb
102 lines (88 loc) · 2.86 KB
/
agent_linux.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Installs and configures the New Relic Infrastructure agent on Linux
deb_version_to_codename = {
10 => 'buster',
9 => 'stretch',
8 => 'jessie',
7 => 'wheezy',
16 => 'xenial',
14 => 'trusty',
12 => 'precise'
}
case node['platform_family']
when 'debian'
# Add public GPG key
remote_file '/tmp/newrelic-infra.gpg' do
source 'https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg'
end
execute 'add apt key' do
command 'apt-key add /tmp/newrelic-infra.gpg'
end
# Create APT repo file
apt_repository 'newrelic-infra' do
uri 'https://download.newrelic.com/infrastructure_agent/linux/apt'
distribution deb_version_to_codename[node['platform_version'].to_i]
components ['main']
arch 'amd64'
end
# Update APT repo -- if you don't need this in your regular runs,
# please customize a private fork
execute 'apt-get update' do
command 'apt-get update'
end
when 'rhel'
# Add Yum repo
case node['platform']
when 'centos', 'oracle', 'redhat'
rhel_version = node['platform_version'].to_i
when 'amazon'
case node['platform_version'].to_i
when 2013, 2014, 2015, 2016, 2017
rhel_version = 6
end
end
yum_repository 'newrelic-infra' do
description "New Relic Infrastructure"
baseurl "https://download.newrelic.com/infrastructure_agent/linux/yum/el/#{rhel_version}/x86_64"
gpgkey 'https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg'
gpgcheck true
repo_gpgcheck true
end
# Update Yum repo
execute 'Update Infra Yum repo' do
command "yum -q makecache -y --disablerepo='*' --enablerepo='newrelic-infra'"
end
end
# Detect service provider
if node['platform_family'] == 'rhel' && node['platform_version'] =~ /^7/
service_provider = Chef::Provider::Service::Systemd
elsif node['platform'] == 'ubuntu' && node['platform_version'] == "16.04"
service_provider = Chef::Provider::Service::Systemd
else
service_provider = Chef::Provider::Service::Upstart
end
# Install the newrelic-infra agent
package 'newrelic-infra' do
action node['newrelic-infra']['agent_action']
version node['newrelic-infra']['agent_version'] unless node['newrelic-infra']['agent_version'].nil?
end
# Setup newrelic-infra service
service "newrelic-infra" do
provider service_provider
action [:enable, :start]
end
# Lay down newrelic-infra agent config
template '/etc/newrelic-infra.yml' do
source 'newrelic-infra.yml.erb'
owner 'root'
group 'root'
mode '00644'
variables(
'license_key' => node['newrelic-infra']['license_key'],
'display_name' => node['newrelic-infra']['display_name'],
'log_file' => node['newrelic-infra']['log_file'],
'verbose' => node['newrelic-infra']['verbose'],
'proxy' => node['newrelic-infra']['proxy'],
'custom_attributes' => node['newrelic-infra']['custom_attributes']
)
notifies :restart, 'service[newrelic-infra]', :delayed
end