Skip to content

Commit

Permalink
Make the pool provider whyrun able
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Maurice committed Jan 19, 2017
1 parent 9e14409 commit f9b773d
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions providers/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
include Opscode::IIS::Helper
include Opscode::IIS::Processors

def whyrun_supported?
true
end

action :add do
if !@current_resource.exists
cmd = "#{appcmd(node)} add apppool /name:\"#{new_resource.pool_name}\""
Expand All @@ -38,7 +42,9 @@
cmd << " /managedPipelineMode:#{new_resource.pipeline_mode.capitalize}" if new_resource.pipeline_mode
cmd << " /commit:\"MACHINE/WEBROOT/APPHOST\""
Chef::Log.debug(cmd)
shell_out!(cmd)
execute "Adding the IIS pool #{new_resource.pool_name}" do
command cmd
end
configure
new_resource.updated_by_last_action(true)
Chef::Log.info('App pool created')
Expand All @@ -53,7 +59,9 @@

action :delete do
if @current_resource.exists
shell_out!("#{appcmd(node)} delete apppool \"#{site_identifier}\"")
execute "Deleting the IIS pool #{new_resource.pool_name}" do
command "#{appcmd(node)} delete apppool \"#{site_identifier}\""
end
new_resource.updated_by_last_action(true)

This comment has been minimized.

Copy link
@kamaradclimber

kamaradclimber Jan 19, 2017

you can remove this line which is a very old and deprecated way to support why-run. Since you are using chef resources inside your provider, iis_pool is maked as updated automatically whenever the execute resource is updated.

Chef::Log.info("#{new_resource} deleted")
else
Expand All @@ -63,17 +71,21 @@

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")
execute "Starting IIS pool #{site_identifier}" do
command "#{appcmd(node)} start apppool \"#{site_identifier}\""
end
new_resource.updated_by_last_action(true)

This comment has been minimized.

Copy link
@kamaradclimber

kamaradclimber Jan 19, 2017

same here

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}\"")
execute "Stopping the IIS pool #{new_resource.pool_name}" do
command "#{appcmd(node)} stop apppool \"#{site_identifier}\""
end
new_resource.updated_by_last_action(true)

This comment has been minimized.

Copy link
@kamaradclimber

kamaradclimber Jan 19, 2017

same here

Chef::Log.info("#{new_resource} stopped")
else
Expand All @@ -82,15 +94,21 @@
end

action :restart do
shell_out!("#{appcmd(node)} stop APPPOOL \"#{site_identifier}\"")
execute "Stopping the IIS pool #{site_identifier}" do
command "#{appcmd(node)} stop apppool \"#{site_identifier}\""
end
sleep 2
shell_out!("#{appcmd(node)} start APPPOOL \"#{site_identifier}\"")
execute "Starting the IIS pool #{site_identifier}" do
command "#{appcmd(node)} start apppool \"#{site_identifier}\""
end
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}\"")
execute "Recycling the IIS pool #{new_resource.pool_name}" do
command "#{appcmd(node)} recycle APPPOOL \"#{site_identifier}\""
end
new_resource.updated_by_last_action(true)
Chef::Log.info("#{new_resource} recycled")
end
Expand Down Expand Up @@ -239,7 +257,9 @@ def configure
is_new_recycle_at_time = true
clear_pool_schedule_cmd = "#{appcmd(node)} set config /section:applicationPools \"/-[name='#{new_resource.pool_name}'].recycling.periodicRestart.schedule\""
Chef::Log.debug(clear_pool_schedule_cmd)
shell_out!(clear_pool_schedule_cmd)
execute "Recycling items" do
command clear_pool_schedule_cmd
end
end

configure_application_pool(new_resource.recycle_after_time && is_new_recycle_after_time, "recycling.periodicRestart.time:#{new_resource.recycle_after_time}")
Expand Down Expand Up @@ -269,8 +289,10 @@ def configure
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")
execute "#{appcmd(node)} set config /section:applicationPools" do
command @cmd
end
Chef::Log.debug(@cmd)
shell_out!(@cmd)
end

# Application Pool Identity Settings
Expand All @@ -280,16 +302,20 @@ def configure
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)
converge_by("#{cmd}") do
Chef::Log.debug(cmd)
shell_out!(cmd)
end
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)
execute cmd do
command cmd
end
end

if @was_updated
Expand Down

0 comments on commit f9b773d

Please sign in to comment.