Initial Chef repository
This commit is contained in:
146
cookbooks/iis/providers/app.rb
Normal file
146
cookbooks/iis/providers/app.rb
Normal file
@@ -0,0 +1,146 @@
|
||||
#
|
||||
# Author:: Kendrick Martin (kendrick.martin@webtrends.com)
|
||||
# Contributor:: Adam Wayne (awayne@waynedigital.com)
|
||||
# Cookbook Name:: iis
|
||||
# Provider:: app
|
||||
#
|
||||
# Copyright:: 2011, Webtrends Inc.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/mixin/shell_out'
|
||||
require 'rexml/document'
|
||||
|
||||
include Chef::Mixin::ShellOut
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
|
||||
action :add do
|
||||
if !@current_resource.exists
|
||||
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:\"#{windows_cleanpath(new_resource.physical_path)}\"" if new_resource.physical_path
|
||||
cmd << " /enabledProtocols:\"#{new_resource.enabled_protocols}\"" if new_resource.enabled_protocols
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info('App created')
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} app already exists - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :config do
|
||||
was_updated = false
|
||||
cmd_current_values = "#{appcmd(node)} list app \"#{site_identifier}\" /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)
|
||||
is_new_path = new_or_empty_value?(doc.root, 'APP/application/@path', new_resource.path.to_s)
|
||||
is_new_application_pool = new_or_empty_value?(doc.root, 'APP/application/@applicationPool', new_resource.application_pool.to_s)
|
||||
is_new_enabled_protocols = new_or_empty_value?(doc.root, 'APP/application/@enabledProtocols', new_resource.enabled_protocols.to_s)
|
||||
is_new_physical_path = new_or_empty_value?(doc.root, 'APP/application/virtualDirectory/@physicalPath', new_resource.physical_path.to_s)
|
||||
|
||||
# only get the beginning of the command if there is something that changeds
|
||||
cmd = "#{appcmd(node)} set app \"#{site_identifier}\"" if ((new_resource.path && is_new_path) ||
|
||||
(new_resource.application_pool && is_new_application_pool) ||
|
||||
(new_resource.enabled_protocols && is_new_enabled_protocols))
|
||||
# adds path to the cmd
|
||||
cmd << " /path:\"#{new_resource.path}\"" if new_resource.path && is_new_path
|
||||
# adds applicationPool to the cmd
|
||||
cmd << " /applicationPool:\"#{new_resource.application_pool}\"" if new_resource.application_pool && is_new_application_pool
|
||||
# adds enabledProtocols to the cmd
|
||||
cmd << " /enabledProtocols:\"#{new_resource.enabled_protocols}\"" if new_resource.enabled_protocols && is_new_enabled_protocols
|
||||
Chef::Log.debug(cmd)
|
||||
|
||||
if (cmd.nil?)
|
||||
Chef::Log.debug("#{new_resource} application - nothing to do")
|
||||
else
|
||||
shell_out!(cmd)
|
||||
was_updated = true
|
||||
end
|
||||
|
||||
if ((new_resource.path && is_new_path) ||
|
||||
(new_resource.application_pool && is_new_application_pool) ||
|
||||
(new_resource.enabled_protocols && is_new_enabled_protocols))
|
||||
was_updated = true
|
||||
end
|
||||
|
||||
if new_resource.physical_path && is_new_physical_path
|
||||
was_updated = true
|
||||
cmd = "#{appcmd(node)} set vdir /vdir.name:\"#{vdir_identifier}\""
|
||||
cmd << " /physicalPath:\"#{windows_cleanpath(new_resource.physical_path)}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
if was_updated
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} configured application")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} application - nothing to do")
|
||||
end
|
||||
else
|
||||
log "Failed to run iis_app action :config, #{cmd_current_values.stderr}" do
|
||||
level :warn
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if @current_resource.exists
|
||||
shell_out!("#{appcmd(node)} delete app \"#{site_identifier}\"")
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} deleted")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} app does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
@current_resource = Chef::Resource::IisApp.new(new_resource.name)
|
||||
@current_resource.site_name(new_resource.site_name)
|
||||
@current_resource.path(new_resource.path)
|
||||
@current_resource.application_pool(new_resource.application_pool)
|
||||
cmd = shell_out("#{appcmd(node)} list app")
|
||||
Chef::Log.debug("#{new_resource} list app command output: #{cmd.stdout}")
|
||||
regex = /^APP\s\"#{new_resource.site_name}#{new_resource.path}\"/
|
||||
Chef::Log.debug('Running regex')
|
||||
if cmd.stderr.empty?
|
||||
result = cmd.stdout.match(regex)
|
||||
Chef::Log.debug("#{new_resource} current_resource match output:#{result}")
|
||||
if result
|
||||
@current_resource.exists = true
|
||||
else
|
||||
@current_resource.exists = false
|
||||
end
|
||||
else
|
||||
log "Failed to run iis_app action :load_current_resource, #{cmd_current_values.stderr}" do
|
||||
level :warn
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
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
|
||||
33
cookbooks/iis/providers/config.rb
Normal file
33
cookbooks/iis/providers/config.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
#
|
||||
# Author:: Kendrick Martin (kendrick.martin@webtrends.com)
|
||||
# Contributor:: David Dvorak (david.dvorak@webtrends.com)
|
||||
# Cookbook Name:: iis
|
||||
# Resource:: config
|
||||
#
|
||||
# Copyright:: 2011, Webtrends Inc.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/mixin/shell_out'
|
||||
|
||||
include Chef::Mixin::ShellOut
|
||||
include Opscode::IIS::Helper
|
||||
|
||||
action :config do
|
||||
cmd = "#{appcmd(node)} set config #{new_resource.cfg_cmd}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd, returns: new_resource.returns)
|
||||
Chef::Log.info('IIS Config command run')
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
93
cookbooks/iis/providers/module.rb
Normal file
93
cookbooks/iis/providers/module.rb
Normal file
@@ -0,0 +1,93 @@
|
||||
#
|
||||
# Author:: Jon DeCamp (<jon.decamp@nordstrom.com>)
|
||||
# Cookbook Name:: iis
|
||||
# Provider:: site
|
||||
#
|
||||
# Copyright:: 2013, Nordstrom, Inc.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/mixin/shell_out'
|
||||
include Chef::Mixin::ShellOut
|
||||
include Opscode::IIS::Helper
|
||||
|
||||
# Support whyrun
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
# appcmd syntax for adding modules
|
||||
# appcmd add module /name:string /type:string /preCondition:string
|
||||
action :add do
|
||||
if !@current_resource.exists
|
||||
converge_by("add IIS module #{new_resource.module_name}") do
|
||||
cmd = "#{appcmd(node)} add module /module.name:\"#{new_resource.module_name}\""
|
||||
|
||||
if new_resource.application
|
||||
cmd << " /app.name:\"#{new_resource.application}\""
|
||||
end
|
||||
|
||||
if new_resource.type
|
||||
cmd << " /type:\"#{new_resource.type}\""
|
||||
end
|
||||
|
||||
if new_resource.precondition
|
||||
cmd << " /preCondition:\"#{new_resource.precondition}\""
|
||||
end
|
||||
|
||||
shell_out!(cmd, returns: [0, 42])
|
||||
|
||||
Chef::Log.info("#{new_resource} added module '#{new_resource.module_name}'")
|
||||
end
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} module already exists - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if @current_resource.exists
|
||||
converge_by("delete IIS module #{new_resource.module_name}") do
|
||||
cmd = "#{appcmd(node)} delete module /module.name:\"#{new_resource.module_name}\""
|
||||
if new_resource.application
|
||||
cmd << " /app.name:\"#{new_resource.application}\""
|
||||
end
|
||||
|
||||
shell_out!(cmd, returns: [0, 42])
|
||||
end
|
||||
|
||||
Chef::Log.info("#{new_resource} deleted")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} module does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
@current_resource = Chef::Resource::IisModule.new(new_resource.name)
|
||||
@current_resource.module_name(new_resource.module_name)
|
||||
if new_resource.application
|
||||
cmd = shell_out("#{appcmd(node)} list module /module.name:\"#{new_resource.module_name}\" /app.name:\"#{new_resource.application}\"")
|
||||
else
|
||||
cmd = shell_out("#{appcmd(node)} list module /module.name:\"#{new_resource.module_name}\"")
|
||||
end
|
||||
|
||||
# 'MODULE "Module Name" ( type:module.type, preCondition:condition )'
|
||||
# 'MODULE "Module Name" ( native, preCondition:condition )'
|
||||
|
||||
Chef::Log.debug("#{new_resource} list module command output: #{cmd.stdout}")
|
||||
if cmd.stdout.empty?
|
||||
@current_resource.exists = false
|
||||
else
|
||||
@current_resource.exists = true
|
||||
end
|
||||
end
|
||||
287
cookbooks/iis/providers/pool.rb
Normal file
287
cookbooks/iis/providers/pool.rb
Normal file
@@ -0,0 +1,287 @@
|
||||
#
|
||||
# Author:: Kendrick Martin (kendrick.martin@webtrends.com)
|
||||
# Contributor:: David Dvorak (david.dvorak@webtrends.com)
|
||||
# Cookbook Name:: iis
|
||||
# Provider:: pool
|
||||
#
|
||||
# Copyright:: 2011, Webtrends Inc.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/mixin/shell_out'
|
||||
require 'rexml/document'
|
||||
|
||||
include Chef::Mixin::ShellOut
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
|
||||
action :add do
|
||||
if !@current_resource.exists
|
||||
cmd = "#{appcmd(node)} add apppool /name:\"#{new_resource.pool_name}\""
|
||||
cmd << ' /managedRuntimeVersion:' if new_resource.runtime_version || new_resource.no_managed_code
|
||||
cmd << "v#{new_resource.runtime_version}" if new_resource.runtime_version && !new_resource.no_managed_code
|
||||
cmd << " /managedPipelineMode:#{new_resource.pipeline_mode.capitalize}" if new_resource.pipeline_mode
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
configure
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info('App pool created')
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} pool already exists - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :config do
|
||||
configure
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if @current_resource.exists
|
||||
shell_out!("#{appcmd(node)} delete apppool \"#{site_identifier}\"")
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} deleted")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} pool does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
if !@current_resource.running
|
||||
shell_out!("#{appcmd(node)} start apppool \"#{site_identifier}\"")
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} started")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already running - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
if @current_resource.running
|
||||
shell_out!("#{appcmd(node)} stop apppool \"#{site_identifier}\"")
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} stopped")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already stopped - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
shell_out!("#{appcmd(node)} stop APPPOOL \"#{site_identifier}\"")
|
||||
sleep 2
|
||||
shell_out!("#{appcmd(node)} start APPPOOL \"#{site_identifier}\"")
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} restarted")
|
||||
end
|
||||
|
||||
action :recycle do
|
||||
shell_out!("#{appcmd(node)} recycle APPPOOL \"#{site_identifier}\"")
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} recycled")
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
@current_resource = Chef::Resource::IisPool.new(new_resource.name)
|
||||
@current_resource.pool_name(new_resource.pool_name)
|
||||
cmd = shell_out("#{appcmd(node)} list apppool")
|
||||
# APPPOOL "DefaultAppPool" (MgdVersion:v2.0,MgdMode:Integrated,state:Started)
|
||||
Chef::Log.debug("#{new_resource} list apppool command output: #{cmd.stdout}")
|
||||
if cmd.stderr.empty?
|
||||
result = cmd.stdout.gsub(/\r\n?/, "\n") # ensure we have no carriage returns
|
||||
result = result.match(/^APPPOOL\s\"(#{new_resource.pool_name})\"\s\(MgdVersion:(.*),MgdMode:(.*),state:(.*)\)$/)
|
||||
Chef::Log.debug("#{new_resource} current_resource match output: #{result}")
|
||||
if result
|
||||
@current_resource.exists = true
|
||||
@current_resource.running = (result[4] =~ /Started/) ? true : false
|
||||
else
|
||||
@current_resource.exists = false
|
||||
@current_resource.running = false
|
||||
end
|
||||
else
|
||||
log "Failed to run iis_pool action :load_current_resource, #{cmd_current_values.stderr}" do
|
||||
level :warn
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def site_identifier
|
||||
new_resource.pool_name
|
||||
end
|
||||
|
||||
def configure
|
||||
@was_updated = false
|
||||
cmd_current_values = "#{appcmd(node)} list apppool \"#{new_resource.pool_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
|
||||
is_new_managed_runtime_version = new_value?(doc.root, 'APPPOOL/@RuntimeVersion', "v#{new_resource.runtime_version}")
|
||||
is_new_pipeline_mode = new_value?(doc.root, 'APPPOOL/@PipelineMode'.capitalize, "#{new_resource.pipeline_mode}".to_s.capitalize)
|
||||
|
||||
# add items
|
||||
is_new_start_mode = new_value?(doc.root, 'APPPOOL/add/@startMode', new_resource.start_mode.to_s)
|
||||
is_new_auto_start = new_value?(doc.root, 'APPPOOL/add/@autoStart', new_resource.auto_start.to_s)
|
||||
is_new_queue_length = new_value?(doc.root, 'APPPOOL/add/@queueLength', new_resource.queue_length.to_s)
|
||||
is_new_enable_32_bit_app_on_win_64 = new_value?(doc.root, 'APPPOOL/add/@enable32BitAppOnWin64', new_resource.thirty_two_bit.to_s)
|
||||
|
||||
# processModel items
|
||||
is_new_max_processes = new_or_empty_value?(doc.root, 'APPPOOL/add/processModel/@maxProcesses', new_resource.max_proc.to_s)
|
||||
is_new_load_user_profile = new_value?(doc.root, 'APPPOOL/add/processModel/@loadUserProfile', new_resource.load_user_profile.to_s)
|
||||
is_new_identity_type = new_value?(doc.root, 'APPPOOL/add/processModel/@identityType', new_resource.pool_identity.to_s)
|
||||
is_new_user_name = new_or_empty_value?(doc.root, 'APPPOOL/add/processModel/@userName', new_resource.pool_username.to_s)
|
||||
is_new_password = new_or_empty_value?(doc.root, 'APPPOOL/add/processModel/@password', new_resource.pool_password.to_s)
|
||||
is_new_logon_type = new_value?(doc.root, 'APPPOOL/add/processModel/@logonType', new_resource.logon_type.to_s)
|
||||
is_new_manual_group_membership = new_value?(doc.root, 'APPPOOL/add/processModel/@manualGroupMembership', new_resource.manual_group_membership.to_s)
|
||||
is_new_idle_timeout = new_value?(doc.root, 'APPPOOL/add/processModel/@idleTimeout', new_resource.idle_timeout.to_s)
|
||||
is_new_shutdown_time_limit = new_value?(doc.root, 'APPPOOL/add/processModel/@shutdownTimeLimit', new_resource.shutdown_time_limit.to_s)
|
||||
is_new_startup_time_limit = new_value?(doc.root, 'APPPOOL/add/processModel/@startupTimeLimit', new_resource.startup_time_limit.to_s)
|
||||
is_new_pinging_enabled = new_value?(doc.root, 'APPPOOL/add/processModel/@pingingEnabled', new_resource.pinging_enabled.to_s)
|
||||
is_new_ping_interval = new_value?(doc.root, 'APPPOOL/add/processModel/@pingInterval', new_resource.ping_interval.to_s)
|
||||
is_new_ping_response_time = new_value?(doc.root, 'APPPOOL/add/processModel/@pingResponseTime', new_resource.ping_response_time.to_s)
|
||||
|
||||
# failure items
|
||||
is_new_load_balancer_capabilities = new_value?(doc.root, 'APPPOOL/add/failure/@loadBalancerCapabilities', new_resource.load_balancer_capabilities.to_s)
|
||||
is_new_orphan_worker_process = new_value?(doc.root, 'APPPOOL/add/failure/@orphanWorkerProcess', new_resource.orphan_worker_process.to_s)
|
||||
is_new_orphan_action_exe = new_or_empty_value?(doc.root, 'APPPOOL/add/failure/@orphanActionExe', new_resource.orphan_action_exe.to_s)
|
||||
is_new_orphan_action_params = new_or_empty_value?(doc.root, 'APPPOOL/add/failure/@orphanActionParams', new_resource.orphan_action_params.to_s)
|
||||
is_new_rapid_fail_protection = new_value?(doc.root, 'APPPOOL/add/failure/@rapidFailProtection', new_resource.rapid_fail_protection.to_s)
|
||||
is_new_rapid_fail_protection_interval = new_value?(doc.root, 'APPPOOL/add/failure/@rapidFailProtectionInterval', new_resource.rapid_fail_protection_interval.to_s)
|
||||
is_new_rapid_fail_protection_max_crashes = new_value?(doc.root, 'APPPOOL/add/failure/@rapidFailProtectionMaxCrashes', new_resource.rapid_fail_protection_max_crashes.to_s)
|
||||
is_new_auto_shutdown_exe = new_or_empty_value?(doc.root, 'APPPOOL/add/failure/@autoShutdownExe', new_resource.auto_shutdown_exe.to_s)
|
||||
is_new_auto_shutdown_params = new_or_empty_value?(doc.root, 'APPPOOL/add/failure/@autoShutdownParams', new_resource.auto_shutdown_params.to_s)
|
||||
|
||||
# recycling items
|
||||
is_new_disallow_overlapping_rotation = new_value?(doc.root, 'APPPOOL/add/recycling/@disallowOverlappingRotation', new_resource.disallow_overlapping_rotation.to_s)
|
||||
is_new_disallow_rotation_on_config_change = new_value?(doc.root, 'APPPOOL/add/recycling/@disallowRotationOnConfigChange', new_resource.disallow_rotation_on_config_change.to_s)
|
||||
is_new_recycle_after_time = new_or_empty_value?(doc.root, 'APPPOOL/add/recycling/periodicRestart/@time', new_resource.recycle_after_time.to_s)
|
||||
is_new_recycle_at_time = new_or_empty_value?(doc.root, 'APPPOOL/add/recycling/periodicRestart/schedule/add/@value', new_resource.recycle_at_time.to_s)
|
||||
is_new_private_memory = new_or_empty_value?(doc.root, 'APPPOOL/add/recycling/periodicRestart/@privateMemory', new_resource.private_mem.to_s)
|
||||
is_new_log_event_on_recycle = new_value?(doc.root, 'APPPOOL/add/recycling/@logEventOnRecycle', 'Time, Requests, Schedule, Memory, IsapiUnhealthy, OnDemand, ConfigChange, PrivateMemory')
|
||||
|
||||
# cpu items
|
||||
is_new_cpu_action = new_value?(doc.root, 'APPPOOL/add/cpu/@action', new_resource.cpu_action.to_s)
|
||||
is_new_cpu_limit = new_value?(doc.root, 'APPPOOL/add/cpu/@limit', new_resource.cpu_limit.to_s)
|
||||
is_new_cpu_smp_affinitized = new_value?(doc.root, 'APPPOOL/add/cpu/@smpAffinitized', new_resource.cpu_smp_affinitized.to_s)
|
||||
is_new_cpu_reset_interval = new_value?(doc.root, 'APPPOOL/add/cpu/@resetInterval', new_resource.cpu_reset_interval.to_s)
|
||||
is_new_smp_processor_affinity_mask = new_value?(doc.root, 'APPPOOL/add/cpu/@smpProcessorAffinityMask', new_resource.smp_processor_affinity_mask.to_s)
|
||||
is_new_smp_processor_affinity_mask_2 = new_value?(doc.root, 'APPPOOL/add/cpu/@smpProcessorAffinityMask2', new_resource.smp_processor_affinity_mask_2.to_s)
|
||||
|
||||
# Application Pool Config
|
||||
@cmd = "#{appcmd(node)} set config /section:applicationPools"
|
||||
|
||||
# root items
|
||||
configure_application_pool(is_new_auto_start, "autoStart:#{new_resource.auto_start}")
|
||||
configure_application_pool(is_new_start_mode, "startMode:#{new_resource.start_mode}")
|
||||
configure_application_pool(new_resource.runtime_version && is_new_managed_runtime_version, "managedRuntimeVersion:v#{new_resource.runtime_version}")
|
||||
configure_application_pool(new_resource.pipeline_mode && is_new_pipeline_mode, "managedPipelineMode:#{new_resource.pipeline_mode}")
|
||||
configure_application_pool(new_resource.thirty_two_bit && is_new_enable_32_bit_app_on_win_64, "enable32BitAppOnWin64:#{new_resource.thirty_two_bit}")
|
||||
configure_application_pool(new_resource.queue_length && is_new_queue_length, "queueLength:#{new_resource.queue_length}")
|
||||
|
||||
# processModel items
|
||||
configure_application_pool(new_resource.max_proc && is_new_max_processes, "processModel.maxProcesses:#{new_resource.max_proc}")
|
||||
configure_application_pool(is_new_load_user_profile, "processModel.loadUserProfile:#{new_resource.load_user_profile}")
|
||||
configure_application_pool(is_new_logon_type, "processModel.logonType:#{new_resource.logon_type}")
|
||||
configure_application_pool(is_new_manual_group_membership, "processModel.manualGroupMembership:#{new_resource.manual_group_membership}")
|
||||
configure_application_pool(is_new_idle_timeout, "processModel.idleTimeout:#{new_resource.idle_timeout}")
|
||||
configure_application_pool(is_new_shutdown_time_limit, "processModel.shutdownTimeLimit:#{new_resource.shutdown_time_limit}")
|
||||
configure_application_pool(is_new_startup_time_limit, "processModel.startupTimeLimit:#{new_resource.startup_time_limit}")
|
||||
configure_application_pool(is_new_pinging_enabled, "processModel.pingingEnabled:#{new_resource.pinging_enabled}")
|
||||
configure_application_pool(is_new_ping_interval, "processModel.pingInterval:#{new_resource.ping_interval}")
|
||||
configure_application_pool(is_new_ping_response_time, "processModel.pingResponseTime:#{new_resource.ping_response_time}")
|
||||
|
||||
# recycling items
|
||||
## Special case this collection removal for now.
|
||||
if (new_resource.recycle_at_time && is_new_recycle_at_time)
|
||||
@was_updated = true
|
||||
cmd = "#{appcmd(node)} set config /section:applicationPools \"/-[name='#{new_resource.pool_name}'].recycling.periodicRestart.schedule\""
|
||||
Chef::Log.debug(@cmd)
|
||||
shell_out!(@cmd)
|
||||
end
|
||||
configure_application_pool(new_resource.recycle_after_time && is_new_recycle_after_time, "recycling.periodicRestart.time:#{new_resource.recycle_after_time}")
|
||||
configure_application_pool(new_resource.recycle_at_time && is_new_recycle_at_time, "recycling.periodicRestart.schedule.[value='#{new_resource.recycle_at_time}']", '+')
|
||||
configure_application_pool(is_new_log_event_on_recycle, 'recycling.logEventOnRecycle:PrivateMemory,Memory,Schedule,Requests,Time,ConfigChange,OnDemand,IsapiUnhealthy')
|
||||
configure_application_pool(new_resource.private_mem && is_new_private_memory, "recycling.periodicRestart.privateMemory:#{new_resource.private_mem}")
|
||||
configure_application_pool(is_new_disallow_rotation_on_config_change, "recycling.disallowRotationOnConfigChange:#{new_resource.disallow_rotation_on_config_change}")
|
||||
configure_application_pool(is_new_disallow_overlapping_rotation, "recycling.disallowOverlappingRotation:#{new_resource.disallow_overlapping_rotation}")
|
||||
|
||||
# failure items
|
||||
configure_application_pool(is_new_load_balancer_capabilities, "failure.loadBalancerCapabilities:#{new_resource.load_balancer_capabilities}")
|
||||
configure_application_pool(is_new_orphan_worker_process, "failure.orphanWorkerProcess:#{new_resource.orphan_worker_process}")
|
||||
configure_application_pool(new_resource.orphan_action_exe && is_new_orphan_action_exe, "failure.orphanActionExe:#{new_resource.orphan_action_exe}")
|
||||
configure_application_pool(new_resource.orphan_action_params && is_new_orphan_action_params, "failure.orphanActionParams:#{new_resource.orphan_action_params}")
|
||||
configure_application_pool(is_new_rapid_fail_protection, "failure.rapidFailProtection:#{new_resource.rapid_fail_protection}")
|
||||
configure_application_pool(is_new_rapid_fail_protection_interval, "failure.rapidFailProtectionInterval:#{new_resource.rapid_fail_protection_interval}")
|
||||
configure_application_pool(is_new_rapid_fail_protection_max_crashes, "failure.rapidFailProtectionMaxCrashes:#{new_resource.rapid_fail_protection_max_crashes}")
|
||||
configure_application_pool(new_resource.auto_shutdown_exe && is_new_auto_shutdown_exe, "failure.autoShutdownExe:#{new_resource.auto_shutdown_exe}")
|
||||
configure_application_pool(new_resource.auto_shutdown_params && is_new_auto_shutdown_params, "failure.autoShutdownParams:#{new_resource.auto_shutdown_params}")
|
||||
|
||||
# cpu items
|
||||
configure_application_pool(is_new_cpu_action, "cpu.action:#{new_resource.cpu_action}")
|
||||
configure_application_pool(is_new_cpu_limit, "cpu.limit:#{new_resource.cpu_limit}")
|
||||
configure_application_pool(is_new_cpu_reset_interval, "cpu.resetInterval:#{new_resource.cpu_reset_interval}")
|
||||
configure_application_pool(is_new_cpu_smp_affinitized, "cpu.smpAffinitized:#{new_resource.cpu_smp_affinitized}")
|
||||
configure_application_pool(is_new_smp_processor_affinity_mask, "cpu.smpProcessorAffinityMask:#{new_resource.smp_processor_affinity_mask}")
|
||||
configure_application_pool(is_new_smp_processor_affinity_mask_2, "cpu.smpProcessorAffinityMask2:#{new_resource.smp_processor_affinity_mask_2}")
|
||||
|
||||
if (@cmd != "#{appcmd(node)} set config /section:applicationPools")
|
||||
Chef::Log.debug(@cmd)
|
||||
shell_out!(@cmd)
|
||||
end
|
||||
|
||||
# Application Pool Identity Settings
|
||||
if ((new_resource.pool_username && new_resource.pool_username != '') && (is_new_user_name || is_new_password))
|
||||
@was_updated = true
|
||||
cmd = "#{appcmd(node)} set config /section:applicationPools"
|
||||
cmd << " \"/[name='#{new_resource.pool_name}'].processModel.identityType:SpecificUser\""
|
||||
cmd << " \"/[name='#{new_resource.pool_name}'].processModel.userName:#{new_resource.pool_username}\""
|
||||
cmd << " \"/[name='#{new_resource.pool_name}'].processModel.password:#{new_resource.pool_password}\"" if (new_resource.pool_password && new_resource.pool_password != '' && is_new_password)
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
elsif ((new_resource.pool_username.nil? || new_resource.pool_username == '') &&
|
||||
(new_resource.pool_password.nil? || new_resource.pool_username == '') &&
|
||||
(is_new_identity_type && new_resource.pool_identity != 'SpecificUser'))
|
||||
@was_updated = true
|
||||
cmd = "#{appcmd(node)} set config /section:applicationPools"
|
||||
cmd << " \"/[name='#{new_resource.pool_name}'].processModel.identityType:#{new_resource.pool_identity}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
if @was_updated
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} configured application pool")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} application pool - nothing to do")
|
||||
end
|
||||
else
|
||||
log "Failed to run iis_pool action :config, #{cmd_current_values.stderr}" do
|
||||
level :warn
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def configure_application_pool(condition, config, add_remove = '')
|
||||
unless condition
|
||||
return
|
||||
end
|
||||
|
||||
@was_updated = true
|
||||
@cmd << " \"/#{add_remove}[name='#{new_resource.pool_name}'].#{config}\""
|
||||
end
|
||||
71
cookbooks/iis/providers/section.rb
Normal file
71
cookbooks/iis/providers/section.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
#
|
||||
# Author:: Justin Schuhmann
|
||||
# Cookbook Name:: iis
|
||||
# Resource:: lock
|
||||
#
|
||||
# Copyright:: Justin Schuhmann
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/mixin/shell_out'
|
||||
require 'rexml/document'
|
||||
|
||||
include Chef::Mixin::ShellOut
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
|
||||
action :lock do
|
||||
@current_resource.exists = new_value?(doc.root, 'CONFIG/@overrideMode', 'Deny')
|
||||
|
||||
if !@current_resource.exists
|
||||
cmd = "#{appcmd(node)} lock config -section:\"#{new_resource.section}\" -commit:apphost"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd, returns: new_resource.returns)
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info('IIS Config command run')
|
||||
else
|
||||
Chef::Log.debug("#{new_resource.section} already locked - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :unlock do
|
||||
@current_resource.exists = new_value?(doc.root, 'CONFIG/@overrideMode', 'Allow')
|
||||
|
||||
if !@current_resource.exists
|
||||
cmd = "#{appcmd(node)} unlock config -section:\"#{new_resource.section}\" -commit:apphost"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd, returns: new_resource.returns)
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info('IIS Config command run')
|
||||
else
|
||||
Chef::Log.debug("#{new_resource.section} already unlocked - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
@current_resource = Chef::Resource::IisSection.new(new_resource.section)
|
||||
@current_resource.section(new_resource.section)
|
||||
end
|
||||
|
||||
def doc
|
||||
cmd_current_values = "#{appcmd(node)} list config \"\" -section:#{new_resource.section} /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
|
||||
return Document.new(xml)
|
||||
end
|
||||
|
||||
cmd_current_values.error!
|
||||
end
|
||||
221
cookbooks/iis/providers/site.rb
Normal file
221
cookbooks/iis/providers/site.rb
Normal file
@@ -0,0 +1,221 @@
|
||||
#
|
||||
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
||||
# Cookbook Name:: iis
|
||||
# Provider:: site
|
||||
#
|
||||
# Copyright:: 2011, 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.
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/mixin/shell_out'
|
||||
require 'rexml/document'
|
||||
|
||||
include Chef::Mixin::ShellOut
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
|
||||
action :add do
|
||||
if !@current_resource.exists
|
||||
cmd = "#{appcmd(node)} add site /name:\"#{new_resource.site_name}\""
|
||||
cmd << " /id:#{new_resource.site_id}" if new_resource.site_id
|
||||
cmd << " /physicalPath:\"#{windows_cleanpath(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...
|
||||
if new_resource.options
|
||||
cmd << " #{new_resource.options}"
|
||||
end
|
||||
shell_out!(cmd, returns: [0, 42])
|
||||
|
||||
configure
|
||||
|
||||
if new_resource.application_pool
|
||||
shell_out!("#{appcmd(node)} set app \"#{new_resource.site_name}/\" /applicationPool:\"#{new_resource.application_pool}\"", returns: [0, 42])
|
||||
end
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} added new site '#{new_resource.site_name}'")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} site already exists - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :config do
|
||||
configure
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if @current_resource.exists
|
||||
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])
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} deleted")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} site does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
if !@current_resource.running
|
||||
shell_out!("#{appcmd(node)} start site /site.name:\"#{new_resource.site_name}\"", returns: [0, 42])
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} started")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already running - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
if @current_resource.running
|
||||
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])
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} stopped")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} already stopped - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
shell_out!("#{appcmd(node)} stop site /site.name:\"#{new_resource.site_name}\"", returns: [0, 42])
|
||||
sleep 2
|
||||
shell_out!("#{appcmd(node)} start site /site.name:\"#{new_resource.site_name}\"", returns: [0, 42])
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} restarted")
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
@current_resource = Chef::Resource::IisSite.new(new_resource.name)
|
||||
@current_resource.site_name(new_resource.site_name)
|
||||
cmd = shell_out("#{appcmd(node)} list site")
|
||||
Chef::Log.debug(appcmd(node))
|
||||
# 'SITE "Default Web Site" (id:1,bindings:http/*:80:,state:Started)'
|
||||
Chef::Log.debug("#{new_resource} 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\"(#{new_resource.site_name})\"\s\(id:(.*),bindings:(.*),state:(.*)\)$/)
|
||||
Chef::Log.debug("#{new_resource} current_resource match output: #{result}")
|
||||
if result
|
||||
@current_resource.site_id(result[2].to_i)
|
||||
@current_resource.exists = true
|
||||
@current_resource.bindings(result[3])
|
||||
@current_resource.running = (result[4] =~ /Started/) ? true : false
|
||||
else
|
||||
@current_resource.exists = false
|
||||
@current_resource.running = false
|
||||
end
|
||||
else
|
||||
log "Failed to run iis_site action :config, #{cmd.stderr}" do
|
||||
level :warn
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def configure
|
||||
was_updated = false
|
||||
cmd_current_values = "#{appcmd(node)} list site \"#{new_resource.site_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)
|
||||
is_new_bindings = new_value?(doc.root, 'SITE/@bindings', new_resource.bindings.to_s)
|
||||
is_new_physical_path = new_or_empty_value?(doc.root, 'SITE/site/application/virtualDirectory/@physicalPath', new_resource.path.to_s)
|
||||
is_new_port_host_provided = !"#{XPath.first(doc.root, 'SITE/@bindings')},".include?("#{new_resource.protocol}/*:#{new_resource.port}:#{new_resource.host_header},")
|
||||
is_new_site_id = new_value?(doc.root, 'SITE/site/@id', new_resource.site_id.to_s)
|
||||
is_new_log_directory = new_or_empty_value?(doc.root, 'SITE/logFiles/@directory', new_resource.log_directory.to_s)
|
||||
is_new_log_period = new_or_empty_value?(doc.root, 'SITE/logFile/@period', new_resource.log_period.to_s)
|
||||
is_new_log_trunc = new_or_empty_value?(doc.root, 'SITE/logFiles/@truncateSize', new_resource.log_truncsize.to_s)
|
||||
is_new_application_pool = new_value?(doc.root, 'SITE/site/application/@applicationPool', new_resource.application_pool)
|
||||
|
||||
if (new_resource.bindings && is_new_bindings)
|
||||
was_updated = true
|
||||
cmd = "#{appcmd(node)} set site /site.name:\"#{new_resource.site_name}\""
|
||||
cmd << " /bindings:\"#{new_resource.bindings}\""
|
||||
shell_out!(cmd)
|
||||
new_resource.updated_by_last_action(true)
|
||||
elsif (((new_resource.port || new_resource.host_header || new_resource.protocol) && is_new_port_host_provided) && !new_resource.bindings)
|
||||
was_updated = true
|
||||
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)
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
|
||||
if new_resource.application_pool && is_new_application_pool
|
||||
was_updated = true
|
||||
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
|
||||
|
||||
if new_resource.path && is_new_physical_path
|
||||
was_updated = true
|
||||
cmd = "#{appcmd(node)} set vdir \"#{new_resource.site_name}/\""
|
||||
cmd << " /physicalPath:\"#{windows_cleanpath(new_resource.path)}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
if new_resource.site_id && is_new_site_id
|
||||
cmd = "#{appcmd(node)} set site \"#{new_resource.site_name}\""
|
||||
cmd << " /id:#{new_resource.site_id}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
|
||||
if new_resource.log_directory && is_new_log_directory
|
||||
cmd = "#{appcmd(node)} set site \"#{new_resource.site_name}\""
|
||||
cmd << " /logFile.directory:#{windows_cleanpath(new_resource.log_directory)}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
|
||||
if new_resource.log_period && is_new_log_period
|
||||
cmd = "#{appcmd(node)} set site \"#{new_resource.site_name}\""
|
||||
cmd << " /logFile.period:#{new_resource.log_period}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
|
||||
if new_resource.log_truncsize && is_new_log_trunc
|
||||
cmd = "#{appcmd(node)} set site \"#{new_resource.site_name}\""
|
||||
cmd << " /logFile.truncateSize:#{new_resource.log_truncsize}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
|
||||
if was_updated
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} configured site '#{new_resource.site_name}'")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} site - nothing to do")
|
||||
end
|
||||
else
|
||||
log "Failed to run iis_site action :config, #{cmd_current_values.stderr}" do
|
||||
level :warn
|
||||
end
|
||||
end
|
||||
end
|
||||
155
cookbooks/iis/providers/vdir.rb
Normal file
155
cookbooks/iis/providers/vdir.rb
Normal file
@@ -0,0 +1,155 @@
|
||||
#
|
||||
# Author:: Justin Schuhmann (<jmschu02@gmail.com>)
|
||||
# Cookbook Name:: iis
|
||||
# Provider:: site
|
||||
#
|
||||
# Copyright:: Justin Schuhmann
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/mixin/shell_out'
|
||||
require 'rexml/document'
|
||||
|
||||
include Chef::Mixin::ShellOut
|
||||
include REXML
|
||||
include Opscode::IIS::Helper
|
||||
|
||||
action :add do
|
||||
if !@current_resource.exists
|
||||
cmd = "#{appcmd(node)} add vdir /app.name:\"#{new_resource.application_name}\""
|
||||
cmd << " /path:\"#{new_resource.path}\""
|
||||
cmd << " /physicalPath:\"#{windows_cleanpath(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
|
||||
|
||||
Chef::Log.info(cmd)
|
||||
shell_out!(cmd, returns: [0, 42, 183])
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} added new virtual directory to application: '#{new_resource.application_name}'")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} virtual directory already exists - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
action :config do
|
||||
was_updated = false
|
||||
cmd_current_values = "#{appcmd(node)} list vdir \"#{application_identifier}\" /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)
|
||||
is_new_physical_path = new_or_empty_value?(doc.root, 'VDIR/@physicalPath', new_resource.physical_path.to_s)
|
||||
is_new_user_name = new_or_empty_value?(doc.root, 'VDIR/virtualDirectory/@userName', new_resource.username.to_s)
|
||||
is_new_password = new_or_empty_value?(doc.root, 'VDIR/virtualDirectory/@password', new_resource.password.to_s)
|
||||
is_new_logon_method = new_or_empty_value?(doc.root, 'VDIR/virtualDirectory/@logonMethod', new_resource.logon_method.to_s)
|
||||
is_new_allow_sub_dir_config = new_or_empty_value?(doc.root, 'VDIR/virtualDirectory/@allowSubDirConfig', new_resource.allow_sub_dir_config.to_s)
|
||||
|
||||
if new_resource.physical_path && is_new_physical_path
|
||||
was_updated = true
|
||||
cmd = "#{appcmd(node)} set vdir \"#{application_identifier}\" /physicalPath:\"#{new_resource.physical_path}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
if new_resource.username && is_new_user_name
|
||||
was_updated = true
|
||||
cmd = "#{appcmd(node)} set vdir \"#{application_identifier}\" /userName:\"#{new_resource.username}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
if new_resource.password && is_new_password
|
||||
was_updated = true
|
||||
cmd = "#{appcmd(node)} set vdir \"#{application_identifier}\" /password:\"#{new_resource.password}\""
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
if new_resource.logon_method && is_new_logon_method
|
||||
was_updated = true
|
||||
cmd = "#{appcmd(node)} set vdir \"#{application_identifier}\" /logonMethod:#{new_resource.logon_method}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
if new_resource.allow_sub_dir_config && is_new_allow_sub_dir_config
|
||||
was_updated = true
|
||||
cmd = "#{appcmd(node)} set vdir \"#{application_identifier}\" /allowSubDirConfig:#{new_resource.allow_sub_dir_config}"
|
||||
Chef::Log.debug(cmd)
|
||||
shell_out!(cmd)
|
||||
end
|
||||
|
||||
if was_updated
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} configured virtual directory to application: '#{new_resource.application_name}'")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} virtual directory - nothing to do")
|
||||
end
|
||||
else
|
||||
log "Failed to run iis_vdir action :config, #{cmd_current_values.stderr}" do
|
||||
level :warn
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
if @current_resource.exists
|
||||
shell_out!("#{appcmd(node)} delete vdir \"#{application_identifier}\"", returns: [0, 42])
|
||||
new_resource.updated_by_last_action(true)
|
||||
Chef::Log.info("#{new_resource} deleted")
|
||||
else
|
||||
Chef::Log.debug("#{new_resource} virtual directory does not exist - nothing to do")
|
||||
end
|
||||
end
|
||||
|
||||
def load_current_resource
|
||||
@current_resource = Chef::Resource::IisVdir.new(new_resource.name)
|
||||
@current_resource.application_name(application_name_check)
|
||||
@current_resource.path(new_resource.path)
|
||||
@current_resource.physical_path(new_resource.physical_path)
|
||||
cmd = shell_out("#{ appcmd(node) } list vdir \"#{application_identifier}\"")
|
||||
Chef::Log.debug("#{ new_resource } list vdir command output: #{ cmd.stdout }")
|
||||
|
||||
if cmd.stderr.empty?
|
||||
# VDIR "Testfu Site/Content/Test"
|
||||
result = cmd.stdout.match(/^VDIR\s\"#{Regexp.escape(application_identifier)}\"/)
|
||||
Chef::Log.debug("#{ new_resource } current_resource match output: #{ result }")
|
||||
if result
|
||||
@current_resource.exists = true
|
||||
else
|
||||
@current_resource.exists = false
|
||||
end
|
||||
else
|
||||
log "Failed to run iis_vdir action :load_current_resource, #{cmd_current_values.stderr}" do
|
||||
level :warn
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def application_identifier
|
||||
new_resource.application_name.chomp('/') + new_resource.path
|
||||
end
|
||||
|
||||
def application_name_check
|
||||
if !new_resource.application_name.include?('/') && !new_resource.application_name.end_with?('/')
|
||||
new_resource.application_name("#{new_resource.application_name}/")
|
||||
elsif new_resource.application_name.chomp('/').include?('/') && new_resource.application_name.end_with?('/')
|
||||
new_resource.application_name(new_resource.application_name.chomp('/'))
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user