Make config_dir and service_name not configurable
There is no use case for that and can only break things if changed
MODIFY
attributes/default.rb
attributes/default.rb
@@ -167,23 +167,6 @@ default['datadog']['windows_agent_checksum'] = nil
# If you're already using version >= 5.12.0 of the Agent, leave this to false.
default['datadog']['windows_agent_use_exe'] = false
-# Values that differ on Windows
-# The location of the config folder (containing conf.d)
-# The name of the dd agent service
-# The log file directory (see logging section below)
-
-# Values that differ on Windows
-# The location of the config folder (containing conf.d)
-if node['platform_family'] == 'windows'
- default['datadog']['agent5_config_dir'] = "#{ENV['ProgramData']}/Datadog"
- default['datadog']['agent6_config_dir'] = "#{ENV['ProgramData']}/Datadog"
- default['datadog']['agent_name'] = 'DatadogAgent'
-else
- default['datadog']['agent5_config_dir'] = '/etc/dd-agent'
- default['datadog']['agent6_config_dir'] = '/etc/datadog-agent'
- default['datadog']['agent_name'] = 'datadog-agent'
-end
-
# Since 6.11.0, the Datadog Agent creates/uses a custom user to run on Windows.
# Set `windows_ddagentuser_name` using the format `<domain>\<user>` to provide a
# specific username and `windows_ddagentuser_password` to provide a specific password.

MODIFY
recipes/_agent6_config.rb
recipes/_agent6_config.rb
is_windows = node['platform_family'] == 'windows'
-agent_config_file = ::File.join(node['datadog']['agent6_config_dir'], 'datadog.yaml')
+agent_config_dir = is_windows ? "#{ENV['ProgramData']}/Datadog" : '/etc/datadog-agent'
+agent_config_file = ::File.join(agent_config_dir, 'datadog.yaml')
template agent_config_file do
def template_vars
# we need to always provide an URL value for additional endpoints.

MODIFY
recipes/dd-agent.rb
recipes/dd-agent.rb
@@ -52,7 +52,8 @@ if node['datadog']['agent_major_version'].to_i > 5
include_recipe 'datadog::_agent6_config'
else
# Make sure the config directory exists for Agent 5
- directory node['datadog']['agent5_config_dir'] do
+ agent_config_dir = is_windows ? "#{ENV['ProgramData']}/Datadog" : '/etc/dd-agent'
+ directory agent_config_dir do
if is_windows
owner 'Administrators'
rights :full_control, 'Administrators'
@@ -63,8 +64,7 @@ else
mode '755'
end
end
-
- agent_config_file = ::File.join(node['datadog']['agent5_config_dir'], 'datadog.conf')
+ agent_config_file = ::File.join(agent_config_dir, 'datadog.conf')
template agent_config_file do
def template_vars
# Default value of node['datadog']['url'] is now nil for an Agent 6
@@ -119,14 +119,16 @@ if node['datadog']['agent_major_version'].to_i > 5 &&
service_provider = Chef::Provider::Service::Upstart
end
+service_name = is_windows ? 'DatadogAgent' : 'datadog-agent'
+
service 'datadog-agent' do
- service_name node['datadog']['agent_name']
+ service_name service_name
action [agent_enable, agent_start]
provider service_provider unless service_provider.nil?
if is_windows
supports :restart => true, :start => true, :stop => true
- restart_command "powershell restart-service #{node['datadog']['agent_name']} -Force"
- stop_command "powershell stop-service #{node['datadog']['agent_name']} -Force"
+ restart_command "powershell restart-service #{service_name} -Force"
+ stop_command "powershell stop-service #{service_name} -Force"
else
supports :restart => true, :status => true, :start => true, :stop => true
end

MODIFY
resources/monitor.rb
resources/monitor.rb
@@ -52,9 +52,7 @@ action :remove do
end
def yaml_dir
- if node['datadog']['agent_major_version'].to_i > 5
- ::File.join(node['datadog']['agent6_config_dir'], 'conf.d')
- else
- ::File.join(node['datadog']['agent5_config_dir'], 'conf.d')
- end
+ is_agent5 = node['datadog']['agent_major_version'].to_i > 5
+ is_windows = node['platform_family'] == 'windows'
+ return is_windows ? "#{ENV['ProgramData']}/Datadog/conf.d" : (is_agent5 ? '/etc/dd-agent/conf.d' : '/etc/datadog-agent/conf.d')
end

Make config_dir and service_name not configurable

There is no use case for that and can only break things if changed