Downgrade mysql cookbook for now
It doesn't play well with our current dev server setup
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#
|
||||
# Author:: Kendrick Martin (kendrick.martin@webtrends.com>)
|
||||
# Cookbook:: iis
|
||||
# Resource:: app
|
||||
#
|
||||
# Copyright:: 2011-2016, Webtrends Inc.
|
||||
# Copyright:: 2011-2017, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -18,15 +17,130 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :add, :delete, :config
|
||||
require 'rexml/document'
|
||||
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
|
||||
property :site_name, String, name_property: true
|
||||
property :path, String, default: '/'
|
||||
property :application_pool, String
|
||||
property :physical_path, String
|
||||
property :enabled_protocols, String
|
||||
|
||||
default_action :add
|
||||
|
||||
attribute :site_name, kind_of: String, name_attribute: true
|
||||
attribute :path, kind_of: String, default: '/'
|
||||
attribute :application_pool, kind_of: String
|
||||
attribute :physical_path, kind_of: String
|
||||
attribute :enabled_protocols, kind_of: String
|
||||
attribute :default_documents, kind_of: Array, default: []
|
||||
attribute :mime_maps, kind_of: Array, default: []
|
||||
load_current_value do |desired|
|
||||
site_name desired.site_name
|
||||
# Sanitize physical path
|
||||
desired.physical_path = windows_cleanpath(desired.physical_path) if desired.physical_path
|
||||
cmd = shell_out("#{appcmd(node)} list app \"#{desired.site_name}#{desired.path}\"")
|
||||
Chef::Log.debug("#{appcmd(node)} list app command output: #{cmd.stdout}")
|
||||
if cmd.stderr.empty?
|
||||
Chef::Log.debug('Running regex')
|
||||
regex = /^APP\s\"#{desired.site_name}#{desired.path}\"/
|
||||
result = cmd.stdout.match(regex)
|
||||
Chef::Log.debug("#{desired} current_resource match output: #{result}")
|
||||
if !result.nil?
|
||||
cmd_current_values = "#{appcmd(node)} list app \"#{desired.site_name}#{desired.path}\" /config:* /xml"
|
||||
Chef::Log.debug(cmd_current_values)
|
||||
cmd_current_values = shell_out(cmd_current_values)
|
||||
if cmd_current_values.stderr.empty?
|
||||
xml = cmd_current_values.stdout
|
||||
doc = Document.new(xml)
|
||||
path value doc.root, 'APP/application/@path'
|
||||
application_pool value doc.root, 'APP/application/@applicationPool'
|
||||
enabled_protocols value doc.root, 'APP/application/@enabledProtocols'
|
||||
physical_path windows_cleanpath(value(doc.root, 'APP/application/virtualDirectory/@physicalPath'))
|
||||
end
|
||||
else
|
||||
path ''
|
||||
end
|
||||
else
|
||||
Chef::Log.warn "Failed to run iis_app action :load_current_resource, #{cmd_current_values.stderr}"
|
||||
end
|
||||
end
|
||||
|
||||
attr_accessor :exists, :running
|
||||
action :add do
|
||||
if exists
|
||||
Chef::Log.debug("#{new_resource.inspect} app already exists - nothing to do")
|
||||
else
|
||||
converge_by "Creating the Application - \"#{new_resource}\"" do
|
||||
cmd = "#{appcmd(node)} add app /site.name:\"#{new_resource.site_name}\""
|
||||
cmd << " /path:\"#{new_resource.path}\""
|
||||
cmd << " /applicationPool:\"#{new_resource.application_pool}\"" if new_resource.application_pool
|
||||
cmd << " /physicalPath:\"#{new_resource.physical_path}\"" if new_resource.physical_path
|
||||
cmd << " /enabledProtocols:\"#{new_resource.enabled_protocols}\"" if new_resource.enabled_protocols
|
||||
cmd << ' /commit:\"MACHINE/WEBROOT/APPHOST\"'
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :config do
|
||||
if exists
|
||||
# only get the beginning of the command if there is something that changes
|
||||
cmd = cmd_set_app
|
||||
converge_if_changed :path do
|
||||
# adds path to the cmd
|
||||
cmd << " /path:\"#{new_resource.path}\"" if new_resource.path
|
||||
end
|
||||
converge_if_changed :application_pool do
|
||||
# adds applicationPool to the cmd
|
||||
cmd << " /applicationPool:\"#{new_resource.application_pool}\"" if new_resource.application_pool
|
||||
end
|
||||
converge_if_changed :enabled_protocols do
|
||||
# adds enabledProtocols to the cmd
|
||||
cmd << " /enabledProtocols:\"#{new_resource.enabled_protocols}\"" if new_resource.enabled_protocols
|
||||
end
|
||||
Chef::Log.debug(cmd)
|
||||
|
||||
if cmd == cmd_set_app
|
||||
Chef::Log.debug("#{new_resource.inspect} application - nothing to do")
|
||||
else
|
||||
converge_by "Updating the Application - \"#{new_resource}\"" do
|
||||
shell_out!(cmd)
|
||||
end
|
||||
end
|
||||
|
||||
converge_if_changed :physical_path do
|
||||
cmd = "#{appcmd(node)} set vdir /vdir.name:\"#{vdir_identifier}\""
|
||||
cmd << " /physicalPath:\"#{new_resource.physical_path}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource.inspect} app needs to be added - cannot configure non-existent items")
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if exists
|
||||
converge_by "Deleting the Application - \"#{new_resource}\"" do
|
||||
shell_out!("#{appcmd(node)} delete app \"#{site_identifier}\"")
|
||||
Chef::Log.info("#{new_resource} deleted")
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource.inspect} app does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action_class.class_eval do
|
||||
def exists
|
||||
!current_resource.path.empty?
|
||||
end
|
||||
|
||||
def cmd_set_app
|
||||
"#{appcmd(node)} set app \"#{site_identifier}\""
|
||||
end
|
||||
|
||||
def site_identifier
|
||||
"#{new_resource.site_name}#{new_resource.path}"
|
||||
end
|
||||
|
||||
# Ensure VDIR identifier has a trailing slash
|
||||
def vdir_identifier
|
||||
site_identifier.end_with?('/') ? site_identifier : site_identifier + '/'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#
|
||||
# Author:: Kendrick Martin (kendrick.martin@webtrends.com)
|
||||
# Cookbook:: iis
|
||||
# Resource:: config
|
||||
#
|
||||
# Copyright:: 2011-2016, Webtrends Inc.
|
||||
# Copyright:: 2017, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +17,28 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :config, :clear, :set
|
||||
include Opscode::IIS::Helper
|
||||
include Opscode::IIS::Processors
|
||||
|
||||
property :cfg_cmd, String, name_attribute: true
|
||||
property :returns, [Integer, Array], default: 0
|
||||
|
||||
default_action :set
|
||||
|
||||
attribute :cfg_cmd, kind_of: String, name_attribute: true
|
||||
attribute :returns, kind_of: [Integer, Array], default: 0
|
||||
action :set do
|
||||
config
|
||||
end
|
||||
|
||||
action :clear do
|
||||
config(:clear)
|
||||
end
|
||||
|
||||
action_class.class_eval do
|
||||
def config(action = :set)
|
||||
converge_by "Executing IIS Config #{action}" do
|
||||
cmd = "#{appcmd(node)} #{action} config #{new_resource.cfg_cmd}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd, returns: new_resource.returns)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#
|
||||
# Author:: Jon DeCamp (<jon.decamp@nordstrom.com>)
|
||||
# Cookbook:: iis
|
||||
# Resource:: module
|
||||
#
|
||||
# Copyright:: 2012-2016, Nordstrom, Inc.
|
||||
# Copyright:: 2017, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -18,14 +17,119 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :add, :delete, :install, :uninstall
|
||||
include Opscode::IIS::Helper
|
||||
include Opscode::IIS::Processors
|
||||
include Opscode::IIS::SectionHelper
|
||||
|
||||
property :module_name, String, name_property: true
|
||||
property :type, String
|
||||
property :add, [true, false], default: false
|
||||
property :image, String
|
||||
property :precondition, String
|
||||
property :application, String
|
||||
property :previous_lock, String
|
||||
|
||||
default_action :add
|
||||
|
||||
attribute :module_name, kind_of: String, name_attribute: true
|
||||
attribute :type, kind_of: String, default: nil
|
||||
attribute :add, kind_of: [FalseClass, TrueClass], default: nil
|
||||
attribute :image, kind_of: String, default: nil
|
||||
attribute :precondition, kind_of: String, default: nil
|
||||
attribute :application, kind_of: String, default: nil
|
||||
load_current_value do |desired|
|
||||
module_name desired.module_name
|
||||
application desired.application if desired.application
|
||||
# Sanitize Image Path (file system path)
|
||||
desired.image = windows_cleanpath(desired.image) if desired.image
|
||||
cmd = "#{appcmd(node)} list module /module.name:\"#{desired.module_name}\""
|
||||
cmd << " /app.name:\"#{desired.application}\"" if desired.application
|
||||
|
||||
attr_accessor :exists
|
||||
cmd_result = shell_out cmd
|
||||
# 'MODULE "Module Name" ( type:module.type, preCondition:condition )'
|
||||
# 'MODULE "Module Name" ( native, preCondition:condition )'
|
||||
|
||||
Chef::Log.debug("#{desired.name} list module command output: #{cmd_result.stdout}")
|
||||
unless cmd_result.stdout.empty?
|
||||
previous_lock get_current_lock(node, 'system.webServer/modules', desired.application)
|
||||
cmd = "#{appcmd(node)} list module /module.name:\"#{desired.module_name}\""
|
||||
cmd << " /app.name:\"#{desired.application}\"" if desired.application
|
||||
cmd << ' /config:* /xml'
|
||||
cmd_result = shell_out cmd
|
||||
if cmd_result.stderr.empty?
|
||||
xml = cmd_result.stdout
|
||||
doc = Document.new(xml)
|
||||
type value doc.root, 'MODULE/@type'
|
||||
precondition value doc.root, 'MODULE/@preCondition'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# appcmd syntax for adding modules
|
||||
# appcmd add module /name:string /type:string /preCondition:string
|
||||
action :add do
|
||||
if exists
|
||||
Chef::Log.debug("#{new_resource} module already exists - nothing to do")
|
||||
else
|
||||
converge_by("add IIS module #{new_resource.module_name}") do
|
||||
unlock(node, 'system.webServer/modules', new_resource.application)
|
||||
cmd = "#{appcmd(node)} add module /module.name:\"#{new_resource.module_name}\""
|
||||
cmd << " /app.name:\"#{new_resource.application}\"" if new_resource.application
|
||||
cmd << " /type:\"#{new_resource.type}\"" if new_resource.type
|
||||
cmd << " /preCondition:\"#{new_resource.precondition}\"" if new_resource.precondition
|
||||
|
||||
shell_out!(cmd, returns: [0, 42])
|
||||
override_mode(node, current_resource.previous_lock, 'system.webServer/modules', new_resource.application)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if exists
|
||||
converge_by("delete IIS module #{new_resource.module_name}") do
|
||||
unlock(node, 'system.webServer/modules', new_resource.application)
|
||||
cmd = "#{appcmd(node)} delete module /module.name:\"#{new_resource.module_name}\""
|
||||
cmd << " /app.name:\"#{new_resource.application}\"" if new_resource.application
|
||||
|
||||
shell_out!(cmd, returns: [0, 42])
|
||||
override_mode(node, current_resource.previous_lock, 'system.webServer/modules', new_resource.application)
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} module does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
# appcmd syntax for installing native modules
|
||||
# appcmd install module /name:string /add:string(true|false) /image:string
|
||||
action :install do
|
||||
if exists
|
||||
Chef::Log.debug("#{new_resource} module already exists - nothing to do")
|
||||
else
|
||||
converge_by("install IIS module #{new_resource.module_name}") do
|
||||
unlock(node, 'system.webServer/modules', new_resource.application)
|
||||
cmd = "#{appcmd(node)} install module /name:\"#{new_resource.module_name}\""
|
||||
cmd << " /add:\"#{new_resource.add}\"" unless new_resource.add.nil?
|
||||
cmd << " /image:\"#{new_resource.image}\"" if new_resource.image
|
||||
cmd << " /preCondition:\"#{new_resource.precondition}\"" if new_resource.precondition
|
||||
|
||||
shell_out!(cmd, returns: [0, 42])
|
||||
override_mode(node, current_resource.previous_lock, 'system.webServer/modules', new_resource.application)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# appcmd syntax for uninstalling native modules
|
||||
# appcmd uninstall module <name>
|
||||
action :uninstall do
|
||||
if exists
|
||||
converge_by("uninstall IIS module #{new_resource.module_name}") do
|
||||
unlock(node, 'system.webServer/modules', new_resource.application)
|
||||
cmd = "#{appcmd(node)} uninstall module \"#{new_resource.module_name}\""
|
||||
|
||||
shell_out!(cmd, returns: [0, 42])
|
||||
override_mode(node, current_resource.previous_lock, 'system.webServer/modules', new_resource.application)
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} module does not exists - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action_class.class_eval do
|
||||
def exists
|
||||
current_resource.type ? true : false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#
|
||||
# Author:: Kendrick Martin (kendrick.martin@webtrends.com>)
|
||||
# Contributor:: David Dvorak (david.dvorak@webtrends.com)
|
||||
# Cookbook:: iis
|
||||
# Resource:: pool
|
||||
#
|
||||
# Copyright:: 2011-2016, Webtrends Inc.
|
||||
# Copyright:: 2017, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -19,64 +17,435 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :add, :config, :delete, :start, :stop, :restart, :recycle
|
||||
default_action :add
|
||||
require 'rexml/document'
|
||||
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
include Opscode::IIS::Processors
|
||||
|
||||
# root
|
||||
attribute :pool_name, kind_of: String, name_attribute: true
|
||||
attribute :no_managed_code, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :pipeline_mode, kind_of: Symbol, equal_to: [:Integrated, :Classic]
|
||||
attribute :runtime_version, kind_of: String
|
||||
property :name, String, name_property: true
|
||||
property :no_managed_code, [true, false], default: false
|
||||
property :pipeline_mode, [Symbol, String], equal_to: [:Integrated, :Classic], coerce: proc { |v| v.to_sym }
|
||||
property :runtime_version, String
|
||||
|
||||
# add items
|
||||
attribute :start_mode, kind_of: Symbol, equal_to: [:AlwaysRunning, :OnDemand], default: :OnDemand
|
||||
attribute :auto_start, kind_of: [TrueClass, FalseClass], default: true
|
||||
attribute :queue_length, kind_of: Integer, default: 1000
|
||||
attribute :thirty_two_bit, kind_of: [TrueClass, FalseClass], default: false
|
||||
property :start_mode, [Symbol, String], equal_to: [:AlwaysRunning, :OnDemand], default: :OnDemand, coerce: proc { |v| v.to_sym }
|
||||
property :auto_start, [true, false], default: true
|
||||
property :queue_length, Integer, default: 1000, coerce: proc { |v| v.to_i }
|
||||
property :thirty_two_bit, [true, false], default: false
|
||||
|
||||
# processModel items
|
||||
attribute :max_proc, kind_of: Integer
|
||||
attribute :load_user_profile, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :pool_identity, kind_of: Symbol, equal_to: [:SpecificUser, :NetworkService, :LocalService, :LocalSystem, :ApplicationPoolIdentity], default: :ApplicationPoolIdentity
|
||||
attribute :pool_username, kind_of: String
|
||||
attribute :pool_password, kind_of: String
|
||||
attribute :logon_type, kind_of: Symbol, equal_to: [:LogonBatch, :LogonService], default: :LogonBatch
|
||||
attribute :manual_group_membership, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :idle_timeout, kind_of: String, default: '00:20:00'
|
||||
attribute :idle_timeout_action, kind_of: Symbol, equal_to: [:Terminate, :Suspend], default: :Terminate
|
||||
attribute :shutdown_time_limit, kind_of: String, default: '00:01:30'
|
||||
attribute :startup_time_limit, kind_of: String, default: '00:01:30'
|
||||
attribute :pinging_enabled, kind_of: [TrueClass, FalseClass], default: true
|
||||
attribute :ping_interval, kind_of: String, default: '00:00:30'
|
||||
attribute :ping_response_time, kind_of: String, default: '00:01:30'
|
||||
property :max_processes, Integer, coerce: proc { |v| v.to_i }
|
||||
property :load_user_profile, [true, false], default: false
|
||||
property :identity_type, [Symbol, String], equal_to: [:SpecificUser, :NetworkService, :LocalService, :LocalSystem, :ApplicationPoolIdentity], default: :ApplicationPoolIdentity, coerce: proc { |v| v.to_sym }
|
||||
property :username, String
|
||||
property :password, String
|
||||
property :logon_type, [Symbol, String], equal_to: [:LogonBatch, :LogonService], default: :LogonBatch, coerce: proc { |v| v.to_sym }
|
||||
property :manual_group_membership, [true, false], default: false
|
||||
property :idle_timeout, String, default: '00:20:00'
|
||||
property :idle_timeout_action, [Symbol, String], equal_to: [:Terminate, :Suspend], default: :Terminate, coerce: proc { |v| v.to_sym }
|
||||
property :shutdown_time_limit, String, default: '00:01:30'
|
||||
property :startup_time_limit, String, default: '00:01:30'
|
||||
property :pinging_enabled, [true, false], default: true
|
||||
property :ping_interval, String, default: '00:00:30'
|
||||
property :ping_response_time, String, default: '00:01:30'
|
||||
|
||||
# recycling items
|
||||
attribute :disallow_rotation_on_config_change, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :disallow_overlapping_rotation, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :recycle_schedule_clear, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :log_event_on_recycle, kind_of: String, default: node['iis']['recycle']['log_events']
|
||||
attribute :recycle_after_time, kind_of: String
|
||||
attribute :recycle_at_time, kind_of: String
|
||||
attribute :private_mem, kind_of: Integer
|
||||
attribute :virtual_mem, kind_of: Integer
|
||||
property :disallow_rotation_on_config_change, [true, false], default: false
|
||||
property :disallow_overlapping_rotation, [true, false], default: false
|
||||
property :recycle_schedule_clear, [true, false], default: false
|
||||
property :log_event_on_recycle, String, default: node['iis']['recycle']['log_events']
|
||||
property :recycle_after_time, String
|
||||
property :recycle_at_time, String
|
||||
property :private_memory, Integer, coerce: proc { |v| v.to_i }
|
||||
property :virtual_memory, Integer, coerce: proc { |v| v.to_i }
|
||||
|
||||
# failure items
|
||||
attribute :load_balancer_capabilities, kind_of: Symbol, equal_to: [:HttpLevel, :TcpLevel], default: :HttpLevel
|
||||
attribute :orphan_worker_process, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :orphan_action_exe, kind_of: String
|
||||
attribute :orphan_action_params, kind_of: String
|
||||
attribute :rapid_fail_protection, kind_of: [TrueClass, FalseClass], default: true
|
||||
attribute :rapid_fail_protection_interval, kind_of: String, default: '00:05:00'
|
||||
attribute :rapid_fail_protection_max_crashes, kind_of: Integer, default: 5
|
||||
attribute :auto_shutdown_exe, kind_of: String
|
||||
attribute :auto_shutdown_params, kind_of: String
|
||||
property :load_balancer_capabilities, [Symbol, String], equal_to: [:HttpLevel, :TcpLevel], default: :HttpLevel, coerce: proc { |v| v.to_sym }
|
||||
property :orphan_worker_process, [true, false], default: false
|
||||
property :orphan_action_exe, String
|
||||
property :orphan_action_params, String
|
||||
property :rapid_fail_protection, [true, false], default: true
|
||||
property :rapid_fail_protection_interval, String, default: '00:05:00'
|
||||
property :rapid_fail_protection_max_crashes, Integer, default: 5, coerce: proc { |v| v.to_i }
|
||||
property :auto_shutdown_exe, String
|
||||
property :auto_shutdown_params, String
|
||||
|
||||
# cpu items
|
||||
attribute :cpu_action, kind_of: Symbol, equal_to: [:NoAction, :KillW3wp, :Throttle, :ThrottleUnderLoad], default: :NoAction
|
||||
attribute :cpu_limit, kind_of: Integer, default: 0
|
||||
attribute :cpu_reset_interval, kind_of: String, default: '00:05:00'
|
||||
attribute :cpu_smp_affinitized, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :smp_processor_affinity_mask, kind_of: Float, default: 4_294_967_295.0
|
||||
attribute :smp_processor_affinity_mask_2, kind_of: Float, default: 4_294_967_295.0
|
||||
property :cpu_action, [Symbol, String], equal_to: [:NoAction, :KillW3wp, :Throttle, :ThrottleUnderLoad], default: :NoAction, coerce: proc { |v| v.to_sym }
|
||||
property :cpu_limit, Integer, default: 0, coerce: proc { |v| v.to_i }
|
||||
property :cpu_reset_interval, String, default: '00:05:00'
|
||||
property :cpu_smp_affinitized, [true, false], default: false
|
||||
property :smp_processor_affinity_mask, Float, default: 4_294_967_295.0, coerce: proc { |v| v.to_f }
|
||||
property :smp_processor_affinity_mask_2, Float, default: 4_294_967_295.0, coerce: proc { |v| v.to_f }
|
||||
|
||||
attr_accessor :exists, :running
|
||||
# internally used for the state of the pool [Starting, Started, Stopping, Stopped, Unknown, Undefined value]
|
||||
property :running, [true, false], desired_state: true
|
||||
|
||||
default_action :add
|
||||
|
||||
load_current_value do |desired|
|
||||
name desired.name
|
||||
cmd = shell_out("#{appcmd(node)} list apppool \"#{desired.name}\"")
|
||||
# APPPOOL "DefaultAppPool" (MgdVersion:v2.0,MgdMode:Integrated,state:Started)
|
||||
Chef::Log.debug("#{desired} list apppool command output: #{cmd.stdout}")
|
||||
unless cmd.stderr.empty?
|
||||
Chef::Log.warn "Failed to run iis_pool action :load_current_resource, #{cmd.stderr}"
|
||||
return
|
||||
end
|
||||
|
||||
result = cmd.stdout.gsub(/\r\n?/, "\n") # ensure we have no carriage returns
|
||||
result = result.match(/^APPPOOL\s\"(#{desired.name})\"\s\(MgdVersion:(.*),MgdMode:(.*),state:(.*)\)$/i)
|
||||
Chef::Log.debug("#{desired} current_resource match output: #{result}")
|
||||
unless result
|
||||
running false
|
||||
return
|
||||
end
|
||||
|
||||
running result[4] =~ /Started/ ? true : false
|
||||
cmd_current_values = "#{appcmd(node)} list apppool \"#{desired.name}\" /config:* /xml"
|
||||
Chef::Log.debug(cmd_current_values)
|
||||
cmd_current_values = shell_out(cmd_current_values)
|
||||
if cmd_current_values.stderr.empty?
|
||||
xml = cmd_current_values.stdout
|
||||
doc = Document.new(xml)
|
||||
|
||||
# root items
|
||||
runtime_version value(doc.root, 'APPPOOL/@RuntimeVersion').gsub(/^v/, '')
|
||||
pipeline_mode value(doc.root, 'APPPOOL/@PipelineMode').to_sym
|
||||
|
||||
# add items
|
||||
auto_start bool(value(doc.root, 'APPPOOL/add/@autoStart')) if iis_version >= 7.0
|
||||
start_mode value(doc.root, 'APPPOOL/add/@startMode').to_sym if iis_version > 7.0
|
||||
queue_length value(doc.root, 'APPPOOL/add/@queueLength').to_i
|
||||
thirty_two_bit bool(value(doc.root, 'APPPOOL/add/@enable32BitAppOnWin64'))
|
||||
|
||||
# processModel items
|
||||
max_processes value(doc.root, 'APPPOOL/add/processModel/@maxProcesses').to_i
|
||||
load_user_profile bool(value(doc.root, 'APPPOOL/add/processModel/@loadUserProfile'))
|
||||
identity_type value(doc.root, 'APPPOOL/add/processModel/@identityType').to_sym if iis_version > 7.0
|
||||
username value doc.root, 'APPPOOL/add/processModel/@userName'
|
||||
unless username.nil? || desired.username.nil?
|
||||
Chef::Log.info('username: ' + username + ' -> ' + desired.username)
|
||||
end
|
||||
password value doc.root, 'APPPOOL/add/processModel/@password'
|
||||
logon_type value(doc.root, 'APPPOOL/add/processModel/@logonType').to_sym if iis_version > 7.0
|
||||
manual_group_membership bool(value(doc.root, 'APPPOOL/add/processModel/@manualGroupMembership'))
|
||||
idle_timeout value doc.root, 'APPPOOL/add/processModel/@idleTimeout'
|
||||
idle_timeout_action value(doc.root, 'APPPOOL/add/processModel/@idleTimeoutAction').to_sym if iis_version >= 8.5
|
||||
shutdown_time_limit value doc.root, 'APPPOOL/add/processModel/@shutdownTimeLimit'
|
||||
startup_time_limit value doc.root, 'APPPOOL/add/processModel/@startupTimeLimit'
|
||||
pinging_enabled bool(value(doc.root, 'APPPOOL/add/processModel/@pingingEnabled'))
|
||||
ping_interval value doc.root, 'APPPOOL/add/processModel/@pingInterval'
|
||||
ping_response_time value doc.root, 'APPPOOL/add/processModel/@pingResponseTime'
|
||||
|
||||
# recycling items
|
||||
disallow_overlapping_rotation bool(value(doc.root, 'APPPOOL/add/recycling/@disallowOverlappingRotation'))
|
||||
disallow_rotation_on_config_change bool(value(doc.root, 'APPPOOL/add/recycling/@disallowRotationOnConfigChange'))
|
||||
recycle_after_time value doc.root, 'APPPOOL/add/recycling/periodicRestart/@time'
|
||||
recycle_at_time value doc.root, "APPPOOL/add/recycling/periodicRestart/schedule/add[@value='#{desired.recycle_at_time}']/@value"
|
||||
private_memory value(doc.root, 'APPPOOL/add/recycling/periodicRestart/@privateMemory').to_i
|
||||
virtual_memory value(doc.root, 'APPPOOL/add/recycling/periodicRestart/@memory').to_i
|
||||
log_event_on_recycle value doc.root, 'APPPOOL/add/recycling/@logEventOnRecycle'
|
||||
|
||||
# failure items
|
||||
load_balancer_capabilities value(doc.root, 'APPPOOL/add/failure/@loadBalancerCapabilities').to_sym
|
||||
orphan_worker_process bool(value(doc.root, 'APPPOOL/add/failure/@orphanWorkerProcess'))
|
||||
orphan_action_exe value doc.root, 'APPPOOL/add/failure/@orphanActionExe'
|
||||
orphan_action_params value doc.root, 'APPPOOL/add/failure/@orphanActionParams'
|
||||
rapid_fail_protection bool(value(doc.root, 'APPPOOL/add/failure/@rapidFailProtection'))
|
||||
rapid_fail_protection_interval value doc.root, 'APPPOOL/add/failure/@rapidFailProtectionInterval'
|
||||
rapid_fail_protection_max_crashes value(doc.root, 'APPPOOL/add/failure/@rapidFailProtectionMaxCrashes').to_i
|
||||
auto_shutdown_exe value doc.root, 'APPPOOL/add/failure/@autoShutdownExe'
|
||||
auto_shutdown_params value doc.root, 'APPPOOL/add/failure/@autoShutdownParams'
|
||||
|
||||
# cpu items
|
||||
cpu_action value(doc.root, 'APPPOOL/add/cpu/@action').to_sym
|
||||
cpu_limit value(doc.root, 'APPPOOL/add/cpu/@limit').to_i
|
||||
cpu_smp_affinitized bool(value(doc.root, 'APPPOOL/add/cpu/@smpAffinitized'))
|
||||
cpu_reset_interval value doc.root, 'APPPOOL/add/cpu/@resetInterval'
|
||||
smp_processor_affinity_mask value(doc.root, 'APPPOOL/add/cpu/@smpProcessorAffinityMask').to_f
|
||||
smp_processor_affinity_mask_2 value(doc.root, 'APPPOOL/add/cpu/@smpProcessorAffinityMask2').to_f
|
||||
|
||||
@node_array = XPath.match(doc.root, 'APPPOOL/add/recycling/periodicRestart/schedule/add')
|
||||
end
|
||||
end
|
||||
|
||||
action :add do
|
||||
if exists
|
||||
Chef::Log.debug("#{new_resource} pool already exists - nothing to do")
|
||||
else
|
||||
converge_by "Created Application Pool \"#{new_resource}\"" do
|
||||
cmd = "#{appcmd(node)} add apppool /name:\"#{new_resource.name}\""
|
||||
if new_resource.no_managed_code
|
||||
cmd << ' /managedRuntimeVersion:'
|
||||
elsif new_resource.runtime_version
|
||||
cmd << " /managedRuntimeVersion:v#{new_resource.runtime_version}"
|
||||
end
|
||||
cmd << " /managedPipelineMode:#{new_resource.pipeline_mode.capitalize}" if new_resource.pipeline_mode
|
||||
cmd << ' /commit:\"MACHINE/WEBROOT/APPHOST\"'
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
configure
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :config do
|
||||
configure if exists
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if exists
|
||||
converge_by "Deleted Application Pool \"#{new_resource}\"" do
|
||||
shell_out!("#{appcmd(node)} delete apppool \"#{new_resource.name}\"")
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} pool does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
if exists && !current_resource.running
|
||||
converge_by "Started Application Pool \"#{new_resource}\"" do
|
||||
shell_out!("#{appcmd(node)} start apppool \"#{new_resource.name}\"")
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already running - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
if exists && current_resource.running
|
||||
converge_by "Stopped Application Pool \"#{new_resource}\"" do
|
||||
shell_out!("#{appcmd(node)} stop apppool \"#{new_resource.name}\"")
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already stopped - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
if exists
|
||||
converge_by "Restarted Application Pool \"#{new_resource}\"" do
|
||||
shell_out!("#{appcmd(node)} stop APPPOOL \"#{new_resource.name}\"") if current_resource.running
|
||||
sleep 2
|
||||
shell_out!("#{appcmd(node)} start APPPOOL \"#{new_resource.name}\"")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :recycle do
|
||||
if exists
|
||||
converge_by "Recycled Application Pool \"#{new_resource}\"" do
|
||||
shell_out!("#{appcmd(node)} recycle APPPOOL \"#{new_resource.name}\"") if current_resource.running
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action_class.class_eval do
|
||||
def exists
|
||||
current_resource.runtime_version ? true : false
|
||||
end
|
||||
|
||||
def configure
|
||||
# Application Pool Config
|
||||
cmd = "#{appcmd(node)} set config /section:applicationPools"
|
||||
|
||||
# root items
|
||||
if iis_version >= 7.0
|
||||
converge_if_changed :auto_start do
|
||||
cmd << configure_application_pool("autoStart:#{new_resource.auto_start}")
|
||||
end
|
||||
end
|
||||
|
||||
if iis_version >= 7.5
|
||||
converge_if_changed :start_mode do
|
||||
cmd << configure_application_pool("startMode:#{new_resource.start_mode}")
|
||||
end
|
||||
end
|
||||
|
||||
if new_resource.no_managed_code
|
||||
converge_if_changed :runtime_version do
|
||||
cmd << configure_application_pool('managedRuntimeVersion:')
|
||||
end
|
||||
else
|
||||
converge_if_changed :runtime_version do
|
||||
cmd << configure_application_pool("managedRuntimeVersion:v#{new_resource.runtime_version}")
|
||||
end
|
||||
end
|
||||
|
||||
converge_if_changed :pipeline_mode do
|
||||
cmd << configure_application_pool("managedPipelineMode:#{new_resource.pipeline_mode}")
|
||||
end
|
||||
converge_if_changed :thirty_two_bit do
|
||||
cmd << configure_application_pool("enable32BitAppOnWin64:#{new_resource.thirty_two_bit}")
|
||||
end
|
||||
converge_if_changed :queue_length do
|
||||
cmd << configure_application_pool("queueLength:#{new_resource.queue_length}")
|
||||
end
|
||||
|
||||
# processModel items
|
||||
converge_if_changed :max_processes do
|
||||
cmd << configure_application_pool("processModel.maxProcesses:#{new_resource.max_processes}")
|
||||
end
|
||||
converge_if_changed :load_user_profile do
|
||||
cmd << configure_application_pool("processModel.loadUserProfile:#{new_resource.load_user_profile}")
|
||||
end
|
||||
converge_if_changed :logon_type do
|
||||
cmd << configure_application_pool("processModel.logonType:#{new_resource.logon_type}")
|
||||
end
|
||||
converge_if_changed :manual_group_membership do
|
||||
cmd << configure_application_pool("processModel.manualGroupMembership:#{new_resource.manual_group_membership}")
|
||||
end
|
||||
converge_if_changed :idle_timeout do
|
||||
cmd << configure_application_pool("processModel.idleTimeout:#{new_resource.idle_timeout}")
|
||||
end
|
||||
if iis_version >= 8.5
|
||||
converge_if_changed :idle_timeout_action do
|
||||
cmd << configure_application_pool("processModel.idleTimeoutAction:#{new_resource.idle_timeout_action}")
|
||||
end
|
||||
end
|
||||
converge_if_changed :shutdown_time_limit do
|
||||
cmd << configure_application_pool("processModel.shutdownTimeLimit:#{new_resource.shutdown_time_limit}")
|
||||
end
|
||||
converge_if_changed :startup_time_limit do
|
||||
cmd << configure_application_pool("processModel.startupTimeLimit:#{new_resource.startup_time_limit}")
|
||||
end
|
||||
converge_if_changed :pinging_enabled do
|
||||
cmd << configure_application_pool("processModel.pingingEnabled:#{new_resource.pinging_enabled}")
|
||||
end
|
||||
converge_if_changed :ping_interval do
|
||||
cmd << configure_application_pool("processModel.pingInterval:#{new_resource.ping_interval}")
|
||||
end
|
||||
converge_if_changed :ping_response_time do
|
||||
cmd << configure_application_pool("processModel.pingResponseTime:#{new_resource.ping_response_time}")
|
||||
end
|
||||
|
||||
should_clear_apppool_schedules = ((new_resource.recycle_at_time != current_resource.recycle_at_time) && !@node_array.nil? && !@node_array.empty?) || (new_resource.recycle_schedule_clear && !@node_array.nil? && !@node_array.empty?)
|
||||
|
||||
# recycling items
|
||||
## Special case this collection removal for now.
|
||||
# TODO: test if this is needed
|
||||
# is_new_recycle_at_time = true
|
||||
if !current_resource.runtime_version && should_clear_apppool_schedules
|
||||
converge_by "Cleared Periodic Restart Schedule #{new_resource} - #{should_clear_apppool_schedules}" do
|
||||
clear_pool_schedule_cmd = "#{appcmd(node)} set config /section:applicationPools \"/-[name='#{new_resource.name}'].recycling.periodicRestart.schedule\""
|
||||
Chef::Log.debug(clear_pool_schedule_cmd)
|
||||
shell_out!(clear_pool_schedule_cmd)
|
||||
end
|
||||
end
|
||||
|
||||
converge_if_changed :recycle_after_time do
|
||||
cmd << configure_application_pool("recycling.periodicRestart.time:#{new_resource.recycle_after_time}")
|
||||
end
|
||||
converge_if_changed :recycle_at_time do
|
||||
cmd << configure_application_pool("recycling.periodicRestart.schedule.[value='#{new_resource.recycle_at_time}']", '+')
|
||||
end
|
||||
converge_if_changed :log_event_on_recycle do
|
||||
cmd << configure_application_pool("recycling.logEventOnRecycle:#{new_resource.log_event_on_recycle}")
|
||||
end
|
||||
converge_if_changed :private_memory do
|
||||
cmd << configure_application_pool("recycling.periodicRestart.privateMemory:#{new_resource.private_memory}")
|
||||
end
|
||||
converge_if_changed :virtual_memory do
|
||||
cmd << configure_application_pool("recycling.periodicRestart.memory:#{new_resource.virtual_memory}")
|
||||
end
|
||||
converge_if_changed :disallow_rotation_on_config_change do
|
||||
cmd << configure_application_pool("recycling.disallowRotationOnConfigChange:#{new_resource.disallow_rotation_on_config_change}")
|
||||
end
|
||||
converge_if_changed :disallow_overlapping_rotation do
|
||||
cmd << configure_application_pool("recycling.disallowOverlappingRotation:#{new_resource.disallow_overlapping_rotation}")
|
||||
end
|
||||
|
||||
# failure items
|
||||
converge_if_changed :load_balancer_capabilities do
|
||||
cmd << configure_application_pool("failure.loadBalancerCapabilities:#{new_resource.load_balancer_capabilities}")
|
||||
end
|
||||
converge_if_changed :orphan_worker_process do
|
||||
cmd << configure_application_pool("failure.orphanWorkerProcess:#{new_resource.orphan_worker_process}")
|
||||
end
|
||||
converge_if_changed :orphan_action_exe do
|
||||
cmd << configure_application_pool("failure.orphanActionExe:#{new_resource.orphan_action_exe}")
|
||||
end
|
||||
converge_if_changed :orphan_action_params do
|
||||
cmd << configure_application_pool("failure.orphanActionParams:#{new_resource.orphan_action_params}")
|
||||
end
|
||||
converge_if_changed :rapid_fail_protection do
|
||||
cmd << configure_application_pool("failure.rapidFailProtection:#{new_resource.rapid_fail_protection}")
|
||||
end
|
||||
converge_if_changed :rapid_fail_protection_interval do
|
||||
cmd << configure_application_pool("failure.rapidFailProtectionInterval:#{new_resource.rapid_fail_protection_interval}")
|
||||
end
|
||||
converge_if_changed :rapid_fail_protection_max_crashes do
|
||||
cmd << configure_application_pool("failure.rapidFailProtectionMaxCrashes:#{new_resource.rapid_fail_protection_max_crashes}")
|
||||
end
|
||||
converge_if_changed :auto_shutdown_exe do
|
||||
cmd << configure_application_pool("failure.autoShutdownExe:#{new_resource.auto_shutdown_exe}")
|
||||
end
|
||||
converge_if_changed :auto_shutdown_params do
|
||||
cmd << configure_application_pool("failure.autoShutdownParams:#{new_resource.auto_shutdown_params}")
|
||||
end
|
||||
|
||||
# cpu items
|
||||
converge_if_changed :cpu_action do
|
||||
cmd << configure_application_pool("cpu.action:#{new_resource.cpu_action}")
|
||||
end
|
||||
converge_if_changed :cpu_limit do
|
||||
cmd << configure_application_pool("cpu.limit:#{new_resource.cpu_limit}")
|
||||
end
|
||||
converge_if_changed :cpu_reset_interval do
|
||||
cmd << configure_application_pool("cpu.resetInterval:#{new_resource.cpu_reset_interval}")
|
||||
end
|
||||
converge_if_changed :cpu_smp_affinitized do
|
||||
cmd << configure_application_pool("cpu.smpAffinitized:#{new_resource.cpu_smp_affinitized}")
|
||||
end
|
||||
converge_if_changed :smp_processor_affinity_mask do
|
||||
cmd << configure_application_pool("cpu.smpProcessorAffinityMask:#{new_resource.smp_processor_affinity_mask.floor}")
|
||||
end
|
||||
converge_if_changed :smp_processor_affinity_mask_2 do
|
||||
cmd << configure_application_pool("cpu.smpProcessorAffinityMask2:#{new_resource.smp_processor_affinity_mask_2.floor}")
|
||||
end
|
||||
|
||||
unless current_resource.runtime_version && cmd == "#{appcmd(node)} set config /section:applicationPools"
|
||||
converge_by "Configured Application Pool \"#{new_resource}\"" do
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
end
|
||||
|
||||
# Application Pool Identity Settings
|
||||
if new_resource.username && new_resource.username != ''
|
||||
cmd = default_app_pool_user
|
||||
converge_if_changed :username do
|
||||
cmd << " \"/[name='#{new_resource.name}'].processModel.userName:#{new_resource.username}\""
|
||||
end
|
||||
converge_if_changed :password do
|
||||
cmd << " \"/[name='#{new_resource.name}'].processModel.password:#{new_resource.password}\""
|
||||
end
|
||||
if cmd != default_app_pool_user
|
||||
converge_by "Configured Application Pool Identity Settings \"#{new_resource}\"" do
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
end
|
||||
elsif new_resource.identity_type != 'SpecificUser'
|
||||
converge_if_changed :identity_type do
|
||||
cmd = "#{appcmd(node)} set config /section:applicationPools"
|
||||
cmd << " \"/[name='#{new_resource.name}'].processModel.identityType:#{new_resource.identity_type}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def default_app_pool_user
|
||||
cmd_default = "#{appcmd(node)} set config /section:applicationPools"
|
||||
cmd_default << " \"/[name='#{new_resource.name}'].processModel.identityType:SpecificUser\""
|
||||
end
|
||||
|
||||
def configure_application_pool(config, add_remove = '')
|
||||
" \"/#{add_remove}[name='#{new_resource.name}'].#{config}\""
|
||||
end
|
||||
end
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,9 +1,8 @@
|
||||
#
|
||||
# Author:: Justin Schuhmann
|
||||
# Cookbook:: iis
|
||||
# Resource:: lock
|
||||
# Resource:: section
|
||||
#
|
||||
# Copyright:: 2016, Justin Schuhmann
|
||||
# Copyright:: 2016-2017, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -18,10 +17,57 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :lock, :unlock
|
||||
default_action :lock
|
||||
require 'rexml/document'
|
||||
|
||||
attribute :section, kind_of: String
|
||||
attribute :returns, kind_of: [Integer, Array], default: 0
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
include Opscode::IIS::SectionHelper
|
||||
include Opscode::IIS::Processors
|
||||
|
||||
attr_accessor :exists
|
||||
property :section, String, name_property: true
|
||||
property :site, String
|
||||
property :application_path, String
|
||||
property :returns, [Integer, Array], default: 0
|
||||
property :locked, String
|
||||
|
||||
default_action :unlock
|
||||
|
||||
load_current_value do |desired|
|
||||
section desired.section
|
||||
site desired.site
|
||||
application_path desired.application_path
|
||||
command_path = 'MACHINE/WEBROOT/APPHOST'
|
||||
command_path << "/#{site}" if site
|
||||
command_path << application_path.to_s if application_path
|
||||
cmd = "#{appcmd(node)} list config \"#{command_path}\""
|
||||
cmd << " -section:\"#{section}\" /commit:apphost /config:* /xml"
|
||||
Chef::Log.debug(cmd)
|
||||
cmd = shell_out(cmd)
|
||||
if cmd.stderr.empty?
|
||||
xml = cmd.stdout
|
||||
doc = Document.new(xml)
|
||||
locked value doc.root, 'CONFIG/@overrideMode'
|
||||
else
|
||||
Chef::Log.info(cmd.stderr)
|
||||
end
|
||||
end
|
||||
|
||||
action :lock do
|
||||
if current_resource.locked != 'Deny'
|
||||
converge_by "Locking the section - \"#{new_resource}\"" do
|
||||
lock node, new_resource.section, "#{new_resource.site}#{new_resource.application_path}", new_resource.returns
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already locked - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :unlock do
|
||||
if current_resource.locked != 'Allow'
|
||||
converge_by "Unlocking the section - \"#{new_resource}\"" do
|
||||
unlock node, new_resource.section, "#{new_resource.site}#{new_resource.application_path}", new_resource.returns
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already unlocked - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#
|
||||
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
||||
# Cookbook:: iis
|
||||
# Resource:: site
|
||||
#
|
||||
# Copyright:: 2011-2016, Chef Software, Inc.
|
||||
# Copyright:: 2017, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -18,20 +17,219 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :add, :delete, :start, :stop, :restart, :config
|
||||
require 'rexml/document'
|
||||
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
include Opscode::IIS::Processors
|
||||
|
||||
property :site_name, String, name_property: true
|
||||
property :site_id, Integer
|
||||
property :port, Integer, default: 80, coerce: proc { |v| v.to_i }
|
||||
property :path, String
|
||||
property :protocol, [Symbol, String], equal_to: [:http, :https], default: :http, coerce: proc { |v| v.to_sym }
|
||||
property :host_header, String
|
||||
property :bindings, String
|
||||
property :application_pool, String
|
||||
property :options, String, default: ''
|
||||
property :log_directory, String, default: node['iis']['log_dir']
|
||||
property :log_period, [Symbol, String], equal_to: [:Daily, :Hourly, :MaxSize, :Monthly, :Weekly], default: :Daily, coerce: proc { |v| v.to_sym }
|
||||
property :log_truncsize, Integer, default: 1_048_576
|
||||
property :running, [true, false], desired_state: true
|
||||
|
||||
default_action :add
|
||||
|
||||
attribute :site_name, kind_of: String, name_attribute: true
|
||||
attribute :site_id, kind_of: Integer
|
||||
attribute :port, kind_of: Integer, default: 80
|
||||
attribute :path, kind_of: String
|
||||
attribute :protocol, kind_of: Symbol, default: :http, equal_to: [:http, :https]
|
||||
attribute :host_header, kind_of: String, default: nil
|
||||
attribute :bindings, kind_of: String, default: nil
|
||||
attribute :application_pool, kind_of: String, default: nil
|
||||
attribute :options, kind_of: String, default: ''
|
||||
attribute :log_directory, kind_of: String, default: node['iis']['log_dir']
|
||||
attribute :log_period, kind_of: Symbol, default: :Daily, equal_to: [:Daily, :Hourly, :MaxSize, :Monthly, :Weekly]
|
||||
attribute :log_truncsize, kind_of: Integer, default: 1_048_576
|
||||
load_current_value do |desired|
|
||||
site_name desired.site_name
|
||||
# Sanitize windows file system path
|
||||
desired.path = windows_cleanpath(desired.path) if desired.path
|
||||
desired.log_directory = windows_cleanpath(desired.log_directory) if desired.log_directory
|
||||
cmd = shell_out "#{appcmd(node)} list site \"#{site_name}\""
|
||||
Chef::Log.debug(appcmd(node))
|
||||
# 'SITE "Default Web Site" (id:1,bindings:http/*:80:,state:Started)'
|
||||
Chef::Log.debug("#{desired} list site command output: #{cmd.stdout}")
|
||||
if cmd.stderr.empty?
|
||||
result = cmd.stdout.gsub(/\r\n?/, "\n") # ensure we have no carriage returns
|
||||
result = result.match(/^SITE\s\"(?<site>#{desired.site_name})\"\s\(id:(?<site_id>.*),bindings:(?<bindings>.*),state:(?<state>.*)\)$/i)
|
||||
Chef::Log.debug("#{desired} current_resource match output: #{result}")
|
||||
if result
|
||||
site_id result[:site_id].to_i
|
||||
bindings result[:bindings]
|
||||
running result[:state] =~ /Started/ ? true : false
|
||||
else
|
||||
running false
|
||||
end
|
||||
|
||||
attr_accessor :exists, :running
|
||||
if site_id
|
||||
values = "#{bindings},".match(%r{(?<protocol>[^\/]+)\/\*:(?<port>[^:]+):(?<host_header>[^,]*),})
|
||||
# get current values
|
||||
cmd = "#{appcmd(node)} list site \"#{site_name}\" /config:* /xml"
|
||||
Chef::Log.debug(cmd)
|
||||
cmd = shell_out cmd
|
||||
if cmd.stderr.empty?
|
||||
xml = cmd.stdout
|
||||
doc = Document.new(xml)
|
||||
path windows_cleanpath(value(doc.root, 'SITE/site/application/virtualDirectory/@physicalPath'))
|
||||
log_directory windows_cleanpath(value(doc.root, 'SITE/site/logFile/@directory'))
|
||||
log_period value(doc.root, 'SITE/site/logFile/@period').to_sym
|
||||
log_truncsize value(doc.root, 'SITE/site/logFile/@truncateSize').to_i
|
||||
application_pool value doc.root, 'SITE/site/application/@applicationPool'
|
||||
end
|
||||
|
||||
if values
|
||||
protocol values[:protocol].to_sym
|
||||
port values[:port].to_i
|
||||
host_header values[:host_header]
|
||||
end
|
||||
else
|
||||
running false
|
||||
end
|
||||
|
||||
if values
|
||||
protocol values[:protocol]
|
||||
port values[:port].to_i
|
||||
host_header values[:host_header]
|
||||
end
|
||||
else
|
||||
Chef::Log.warn "Failed to run iis_site action :config, #{cmd.stderr}"
|
||||
end
|
||||
end
|
||||
|
||||
action :add do
|
||||
if exists
|
||||
Chef::Log.debug("#{new_resource} site already exists - nothing to do")
|
||||
else
|
||||
converge_by "Created the Site - \"#{new_resource}\"" do
|
||||
cmd = "#{appcmd(node)} add site /name:\"#{new_resource.site_name}\""
|
||||
cmd << " /id:#{new_resource.site_id}" if new_resource.site_id
|
||||
cmd << " /physicalPath:\"#{new_resource.path}\"" if new_resource.path
|
||||
if new_resource.bindings
|
||||
cmd << " /bindings:\"#{new_resource.bindings}\""
|
||||
else
|
||||
cmd << " /bindings:#{new_resource.protocol}/*"
|
||||
cmd << ":#{new_resource.port}:" if new_resource.port
|
||||
cmd << new_resource.host_header if new_resource.host_header
|
||||
end
|
||||
|
||||
# support for additional options -logDir, -limits, -ftpServer, etc...
|
||||
cmd << " #{new_resource.options}" if new_resource.options
|
||||
shell_out!(cmd, returns: [0, 42])
|
||||
|
||||
configure
|
||||
|
||||
if new_resource.application_pool
|
||||
shell_out!("#{appcmd(node)} set site /site.name:\"#{new_resource.site_name}\" /[path='/'].applicationPool:\"#{new_resource.application_pool}\"", returns: [0, 42])
|
||||
end
|
||||
Chef::Log.info("#{new_resource} added new site '#{new_resource.site_name}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :config do
|
||||
configure if exists
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if exists
|
||||
converge_by "Deleted the Site - \"#{new_resource}\"" do
|
||||
Chef::Log.info("#{appcmd(node)} stop site /site.name:\"#{new_resource.site_name}\"")
|
||||
shell_out!("#{appcmd(node)} delete site /site.name:\"#{new_resource.site_name}\"", returns: [0, 42])
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} site does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
if exists && !current_resource.running
|
||||
converge_by "Started the Site - \"#{new_resource}\"" do
|
||||
shell_out!("#{appcmd(node)} start site /site.name:\"#{new_resource.site_name}\"", returns: [0, 42])
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already running - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
if exists && current_resource.running
|
||||
converge_by "Stopped the Site - \"#{new_resource}\"" do
|
||||
Chef::Log.info("#{appcmd(node)} stop site /site.name:\"#{new_resource.site_name}\"")
|
||||
shell_out!("#{appcmd(node)} stop site /site.name:\"#{new_resource.site_name}\"", returns: [0, 42])
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already stopped - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
converge_by "Restarted the Site - \"#{new_resource}\"" do
|
||||
shell_out!("#{appcmd(node)} stop site /site.name:\"#{new_resource.site_name}\"", returns: [0, 42]) if running
|
||||
sleep 2
|
||||
shell_out!("#{appcmd(node)} start site /site.name:\"#{new_resource.site_name}\"", returns: [0, 42])
|
||||
end
|
||||
end
|
||||
|
||||
action_class.class_eval do
|
||||
def exists
|
||||
current_resource.site_id ? true : false
|
||||
end
|
||||
|
||||
def configure
|
||||
if new_resource.bindings
|
||||
converge_if_changed :bindings do
|
||||
cmd = "#{appcmd(node)} set site /site.name:\"#{new_resource.site_name}\""
|
||||
cmd << " /bindings:\"#{new_resource.bindings}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
elsif new_resource.port || new_resource.host_header || new_resource.protocol
|
||||
converge_if_changed :bindings, :host_header, :protocol do
|
||||
cmd = "#{appcmd(node)} set site \"#{new_resource.site_name}\""
|
||||
cmd << " /bindings:#{new_resource.protocol}/*:#{new_resource.port}:#{new_resource.host_header}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
end
|
||||
|
||||
converge_if_changed :application_pool do
|
||||
cmd = "#{appcmd(node)} set app \"#{new_resource.site_name}/\" /applicationPool:\"#{new_resource.application_pool}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd, returns: [0, 42])
|
||||
end
|
||||
|
||||
converge_if_changed :path do
|
||||
cmd = "#{appcmd(node)} set vdir \"#{new_resource.site_name}/\""
|
||||
cmd << " /physicalPath:\"#{new_resource.path}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
converge_if_changed :site_id do
|
||||
cmd = "#{appcmd(node)} set site \"#{new_resource.site_name}\""
|
||||
cmd << " /id:#{new_resource.site_id}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
converge_if_changed :log_directory do
|
||||
cmd = "#{appcmd(node)} set site \"#{new_resource.site_name}\""
|
||||
cmd << " /logFile.directory:#{new_resource.log_directory}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
converge_if_changed :log_period do
|
||||
cmd = "#{appcmd(node)} set site \"#{new_resource.site_name}\""
|
||||
cmd << " /logFile.period:#{new_resource.log_period}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
converge_if_changed :log_truncsize do
|
||||
cmd = "#{appcmd(node)} set site \"#{new_resource.site_name}\""
|
||||
cmd << " /logFile.truncateSize:#{new_resource.log_truncsize}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#
|
||||
# Author:: Justin Schuhmann (<jmschu02@gmail.com>)
|
||||
# Cookbook:: iis
|
||||
# Resource:: site
|
||||
# Resource:: vdir
|
||||
#
|
||||
# Copyright:: 2016, Justin Schuhmann
|
||||
# Copyright:: 2016-2017, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -18,15 +17,128 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :add, :delete, :config
|
||||
require 'rexml/document'
|
||||
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
include Opscode::IIS::Processors
|
||||
|
||||
property :application_name, String, name_property: true
|
||||
property :path, String
|
||||
property :physical_path, String
|
||||
property :username, String
|
||||
property :password, String
|
||||
property :logon_method, [Symbol, String], default: :ClearText, equal_to: [:Interactive, :Batch, :Network, :ClearText], coerce: proc { |v| v.to_sym }
|
||||
property :allow_sub_dir_config, [true, false], default: true
|
||||
|
||||
default_action :add
|
||||
|
||||
attribute :application_name, kind_of: String, name_attribute: true
|
||||
attribute :path, kind_of: String
|
||||
attribute :physical_path, kind_of: String
|
||||
attribute :username, kind_of: String, default: nil
|
||||
attribute :password, kind_of: String, default: nil
|
||||
attribute :logon_method, kind_of: Symbol, default: :ClearText, equal_to: [:Interactive, :Batch, :Network, :ClearText]
|
||||
attribute :allow_sub_dir_config, kind_of: [TrueClass, FalseClass], default: true
|
||||
load_current_value do |desired|
|
||||
# Sanitize Application Name
|
||||
desired.application_name = application_cleanname(desired.application_name)
|
||||
# Sanitize Physical Path
|
||||
desired.physical_path = windows_cleanpath(desired.physical_path) if desired.physical_path
|
||||
application_name desired.application_name
|
||||
path desired.path
|
||||
cmd = shell_out("#{appcmd(node)} list vdir \"#{application_name.chomp('/') + path}\"")
|
||||
Chef::Log.debug("#{desired} list vdir command output: #{cmd.stdout}")
|
||||
|
||||
attr_accessor :exists
|
||||
if cmd.stderr.empty?
|
||||
# VDIR "Testfu Site/Content/Test"
|
||||
result = cmd.stdout.match(/^VDIR\s\"#{Regexp.escape(application_name.chomp('/') + path)}\"/)
|
||||
Chef::Log.debug("#{desired} current_resource match output: #{result}")
|
||||
unless result.nil?
|
||||
cmd = shell_out("#{appcmd(node)} list vdir \"#{application_name.chomp('/') + path}\" /config:* /xml")
|
||||
if cmd.stderr.empty?
|
||||
xml = cmd.stdout
|
||||
doc = Document.new(xml)
|
||||
physical_path windows_cleanpath(value(doc.root, 'VDIR/@physicalPath'))
|
||||
username value doc.root, 'VDIR/virtualDirectory/@userName'
|
||||
password value doc.root, 'VDIR/virtualDirectory/@password'
|
||||
logon_method value(doc.root, 'VDIR/virtualDirectory/@logonMethod').to_sym
|
||||
allow_sub_dir_config bool(value(doc.root, 'VDIR/virtualDirectory/@allowSubDirConfig'))
|
||||
end
|
||||
end
|
||||
else
|
||||
Chef::Log.warn "Failed to run iis_vdir action :load_current_resource, #{cmd.stderr}"
|
||||
end
|
||||
end
|
||||
|
||||
action :add do
|
||||
if exists
|
||||
Chef::Log.debug("#{new_resource} virtual directory already exists - nothing to do")
|
||||
else
|
||||
converge_by "Created the VDIR - \"#{new_resource}\"" do
|
||||
cmd = "#{appcmd(node)} add vdir /app.name:\"#{vdir_identifier}\""
|
||||
cmd << " /path:\"#{new_resource.path}\""
|
||||
cmd << " /physicalPath:\"#{new_resource.physical_path}\""
|
||||
cmd << " /userName:\"#{new_resource.username}\"" if new_resource.username
|
||||
cmd << " /password:\"#{new_resource.password}\"" if new_resource.password
|
||||
cmd << " /logonMethod:#{new_resource.logon_method}" if new_resource.logon_method
|
||||
cmd << " /allowSubDirConfig:#{new_resource.allow_sub_dir_config}" if new_resource.allow_sub_dir_config
|
||||
cmd << ' /commit:\"MACHINE/WEBROOT/APPHOST\"'
|
||||
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd, returns: [0, 42, 183])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :config do
|
||||
if exists
|
||||
cmd = "#{appcmd(node)} set vdir \"#{application_identifier}\""
|
||||
converge_if_changed :physical_path do
|
||||
cmd << " /physicalPath:\"#{new_resource.physical_path}\""
|
||||
end
|
||||
|
||||
converge_if_changed :username do
|
||||
cmd << " /userName:\"#{new_resource.username}\""
|
||||
end
|
||||
|
||||
converge_if_changed :password do
|
||||
cmd << " /password:\"#{new_resource.password}\""
|
||||
end
|
||||
|
||||
converge_if_changed :logon_method do
|
||||
cmd << " /logonMethod:#{new_resource.logon_method}"
|
||||
end
|
||||
|
||||
converge_if_changed :allow_sub_dir_config do
|
||||
cmd << " /allowSubDirConfig:#{new_resource.allow_sub_dir_config}"
|
||||
end
|
||||
|
||||
if cmd != "#{appcmd(node)} set vdir \"#{application_identifier}\""
|
||||
converge_by "Updated the VDIR - \"#{new_resource}\"" do
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} virtual directory - nothing changed")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if exists
|
||||
converge_by "Deleted the VDIR - \"#{new_resource}\"" do
|
||||
Chef::Log.debug("#{appcmd(node)} delete vdir \"#{application_identifier}\"")
|
||||
shell_out!("#{appcmd(node)} delete vdir \"#{application_identifier}\"", returns: [0, 42])
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} virtual directory does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action_class.class_eval do
|
||||
def exists
|
||||
current_resource.physical_path ? true : false
|
||||
end
|
||||
|
||||
def application_identifier
|
||||
new_resource.path.start_with?('/') ? vdir_identifier.chomp('/') + new_resource.path : vdir_identifier + new_resource.path
|
||||
end
|
||||
|
||||
def vdir_identifier
|
||||
new_resource.application_name.include?('/') ? new_resource.application_name : new_resource.application_name + '/'
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user