Skip to content

Commit

Permalink
Merge pull request #210 from DataDog/olivielpeau/windows-support
Browse files Browse the repository at this point in the history
Windows agent installation support
  • Loading branch information
miketheman committed Oct 22, 2015
2 parents 77bcca8 + 6ced7e6 commit d653883
Show file tree
Hide file tree
Showing 34 changed files with 344 additions and 226 deletions.
26 changes: 26 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ platforms:
box: opscode_<%= platform_version %>_chef-provisionerless
box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_<%= platform_version %>_chef-provisionerless.box
require_chef_omnibus: <%= chef_version %>
<% end
windows_platform = 'windows-2012r2'
chef_versions.each do |chef_version|
%>

- name: <%= windows_platform %>-<%= chef_version %>
driver_config:
box: mwrock/Windows2012R2 # lightweight windows box
require_chef_omnibus: <%= chef_version %>
communicator: winrm
customize:
usb: "off" # USB is disabled on this box to make it more lightweight
vrde: "on" # enable RDP
transport:
name: winrm

<% end %>

suites:
Expand Down Expand Up @@ -83,6 +101,10 @@ suites:
- name: datadog_cacti
run_list:
- recipe[datadog::cacti]
excludes: &WINDOWS_PLATFORMS
<% chef_versions.each do |chef_version| %>
- <%= windows_platform %>-<%= chef_version %>
<% end %>
attributes:
datadog:
<<: *DATADOG
Expand Down Expand Up @@ -156,6 +178,7 @@ suites:
- name: datadog_docker
run_list:
- recipe[datadog::docker]
excludes: *WINDOWS_PLATFORMS
attributes:
datadog:
<<: *DATADOG
Expand Down Expand Up @@ -327,6 +350,7 @@ suites:
- name: datadog_kafka_consumer
run_list:
- recipe[datadog::kafka_consumer]
excludes: *WINDOWS_PLATFORMS
attributes:
datadog:
<<: *DATADOG
Expand All @@ -342,6 +366,7 @@ suites:
- name: datadog_mesos
run_list:
- recipe[datadog::mesos]
excludes: *WINDOWS_PLATFORMS
attributes:
datadog:
<<: *DATADOG
Expand Down Expand Up @@ -374,6 +399,7 @@ suites:
- name: datadog_process
run_list:
- recipe[datadog::process]
excludes: *WINDOWS_PLATFORMS
attributes:
datadog:
<<: *DATADOG
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ group :integration do
gem 'kitchen-vagrant', '~> 0.19.0'
gem 'test-kitchen', '~> 1.4.2'
gem 'travis-lint'
gem 'serverspec'
gem 'winrm-transport'
end
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Platforms
* RedHat
* Scientific Linux
* Ubuntu
* Windows (requires chef >= 12.0)

Cookbooks
---------
Expand All @@ -35,6 +36,7 @@ The following Opscode cookbooks are dependencies:

* `apt`
* `chef_handler`
* `windows`
* `yum`


Expand Down
17 changes: 15 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
default['datadog']['aptrepo'] = 'http://apt.datadoghq.com'
default['datadog']['aptrepo_dist'] = 'stable'
default['datadog']['yumrepo'] = "http://yum.datadoghq.com/rpm/#{architecture_map[node['kernel']['machine']]}/"
default['datadog']['windows_agent_url'] = 'https://s3.amazonaws.com/ddagent-windows-stable/'

# Values that differ on Windows
# The location of the config folder (containing conf.d)
# The name of the dd agent service
if node['platform_family'] == 'windows'
default['datadog']['config_dir'] = "#{ENV['ProgramData']}/Datadog"
default['datadog']['agent_name'] = 'DatadogAgent'
else
default['datadog']['config_dir'] = '/etc/dd-agent'
default['datadog']['agent_name'] = 'datadog-agent'
end

# DEPRECATED, will be removed after the release of datadog-agent 6.0
# Set to true to always install datadog-agent-base (usually only installed on
Expand All @@ -66,16 +78,17 @@
begin
default['datadog']['install_base'] = Gem::Version.new(node['languages']['python']['version'].gsub(/(\d\.\d\.\d).+/, '\\1')) < Gem::Version.new('2.6.0')
rescue NoMethodError # nodes['languages']['python'] == nil
Chef::Log.warn 'no version of python found, please install Agent version 5.x or higher.'
Chef::Log.warn 'no version of python found, please install Agent version 5.x or higher.' unless platform_family?('windows')
rescue ArgumentError
Chef::Log.warn "could not parse python version string: #{node['languages']['python']['version']}"
end

# Agent Version
# Default of `nil` will install latest version. On Windows, this will also upgrade to latest
default['datadog']['agent_version'] = nil

# Agent package action
# Allow override with `upgrade` to get latest
# Allow override with `upgrade` to get latest (Linux only)
default['datadog']['agent_package_action'] = 'install'

# Chef handler version
Expand Down
1 change: 1 addition & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

depends 'apt' # We recommend '>= 2.1.0'. See CHANGELOG.md for details
depends 'chef_handler', '~> 1.1.0'
depends 'windows'
depends 'yum'

suggests 'sudo'
Expand Down
25 changes: 18 additions & 7 deletions providers/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ def whyrun_supported?

action :add do
Chef::Log.debug "Adding monitoring for #{new_resource.name}"
template "/etc/dd-agent/conf.d/#{new_resource.name}.yaml" do
owner 'dd-agent'
mode 00600
template ::File.join(node['datadog']['config_dir'], 'conf.d', "#{new_resource.name}.yaml") do
if node['platform_family'] == 'windows'
owner 'Administrators'
rights :full_control, 'Administrators'
inherits false
else
owner 'dd-agent'
mode 00600
end
variables(
:init_config => new_resource.init_config,
:instances => new_resource.instances
Expand All @@ -20,15 +26,20 @@ def whyrun_supported?
notifies :restart, 'service[datadog-agent]', :delayed if node['datadog']['agent_start']
end

service 'datadog-agent'
service 'datadog-agent' do
service_name node['datadog']['agent_name']
end
end

action :remove do
Chef::Log.debug "Removing #{new_resource.name} from /etc/dd-agent/conf.d/"
file "/etc/dd-agent/conf.d/#{new_resource.name}.yaml" do
confd_dir = ::File.join(node['datadog']['config_dir'], 'conf.d')
Chef::Log.debug "Removing #{new_resource.name} from #{confd_dir}"
file ::File.join(confd_dir, "#{new_resource.name}.yaml") do
action :delete
notifies :restart, 'service[datadog-agent]', :delayed if node['datadog']['agent_start']
end

service 'datadog-agent'
service 'datadog-agent' do
service_name node['datadog']['agent_name']
end
end
44 changes: 44 additions & 0 deletions recipes/_install-linux.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# Cookbook Name:: datadog
# Recipe:: _install-linux
#
# Copyright 2011-2015, Datadog
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Install the Apt/Yum repository if enabled
include_recipe 'datadog::repository' if node['datadog']['installrepo']

dd_agent_version = node['datadog']['agent_version']

# If version specified and lower than 5.x
if !dd_agent_version.nil? && dd_agent_version.split('.')[0].to_i < 5
Chef::Log.warn 'Support for Agent pre 5.x will be removed in datadog cookbook version 3.0'
# Select correct package name based on attribute
dd_pkg_name = node['datadog']['install_base'] ? 'datadog-agent-base' : 'datadog-agent'

package dd_pkg_name do
version dd_agent_version
end
else
# default behavior, remove the `base` package as it is no longer needed
package 'datadog-agent-base' do
action :remove
end
# Install the regular package
package 'datadog-agent' do
version dd_agent_version
action node['datadog']['agent_package_action'] # default is :install
end
end
40 changes: 40 additions & 0 deletions recipes/_install-windows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Cookbook Name:: datadog
# Recipe:: _install-windows
#
# Copyright 2011-2015, Datadog
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

dd_agent_version = node['datadog']['agent_version']

# If no version is specified, select the latest package
dd_agent_msi = dd_agent_version ? "ddagent-cli-#{dd_agent_version}.msi" : 'ddagent-cli.msi'
temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')

# Download the installer to a temp location
remote_file 'MSI installer' do
path temp_file
source node['datadog']['windows_agent_url'] + dd_agent_msi
# As of v1.37, the windows cookbook doesn't upgrade the package if a newer version is downloaded
# As a workaround uninstall the package first if a new MSI is downloaded
notifies :remove, 'windows_package[Datadog Agent]', :immediately
end

# Install the package
windows_package 'Datadog Agent' do
source temp_file
options %(APIKEY="#{node['datadog']['api_key']}" HOSTNAME="#{node['hostname']}" TAGS="#{node['tags'].join(',')}")
action :install
end
65 changes: 33 additions & 32 deletions recipes/dd-agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,29 @@
# limitations under the License.
#

# Install the Apt/Yum repository if enabled
include_recipe 'datadog::repository' if node['datadog']['installrepo']

dd_agent_version = node['datadog']['agent_version']

# If version specified and lower than 5.x
if !dd_agent_version.nil? && dd_agent_version.split('.')[0].to_i < 5
# Select correct package name based on attribute
dd_pkg_name = node['datadog']['install_base'] ? 'datadog-agent-base' : 'datadog-agent'

package dd_pkg_name do
version dd_agent_version
end
# Install the agent
if node['platform_family'] == 'windows'
include_recipe 'datadog::_install-windows'
else
# default behavior, remove the `base` package as it is no longer needed
package 'datadog-agent-base' do
action :remove
end
# Install the regular package
package 'datadog-agent' do
version dd_agent_version
action node['datadog']['agent_package_action'] # default is :install
end
include_recipe 'datadog::_install-linux'
end

# Set the correct Agent startup action
agent_action = node['datadog']['agent_start'] ? :start : :stop
# Set the correct config file
agent_config_file = ::File.join(node['datadog']['config_dir'], 'datadog.conf')

# Make sure the config directory exists
directory '/etc/dd-agent' do
owner 'dd-agent'
group 'root'
mode 0755
directory node['datadog']['config_dir'] do
if node['platform_family'] == 'windows'
owner 'Administrators'
rights :full_control, 'Administrators'
inherits false
else
owner 'dd-agent'
group 'root'
mode 0755
end
end

#
Expand All @@ -59,10 +49,16 @@
#
raise "Add a ['datadog']['api_key'] attribute to configure this node's Datadog Agent." if node['datadog'] && node['datadog']['api_key'].nil?

template '/etc/dd-agent/datadog.conf' do
owner 'dd-agent'
group 'root'
mode 0640
template agent_config_file do
if node['platform_family'] == 'windows'
owner 'Administrators'
rights :full_control, 'Administrators'
inherits false
else
owner 'dd-agent'
group 'root'
mode 0640
end
variables(
:api_key => node['datadog']['api_key'],
:dd_url => node['datadog']['url']
Expand All @@ -71,7 +67,12 @@

# Common configuration
service 'datadog-agent' do
service_name node['datadog']['agent_name']
action [:enable, agent_action]
supports :restart => true, :status => true, :start => true, :stop => true
subscribes :restart, 'template[/etc/dd-agent/datadog.conf]', :delayed unless node['datadog']['agent_start'] == false
if node['platform_family'] == 'windows'
supports :restart => true, :start => true, :stop => true
else
supports :restart => true, :status => true, :start => true, :stop => true
end
subscribes :restart, "template[#{agent_config_file}]", :delayed unless node['datadog']['agent_start'] == false
end
Loading

0 comments on commit d653883

Please sign in to comment.