111
111
doc = Document . new ( xml )
112
112
113
113
# root items
114
- runtime_version value doc . root , 'APPPOOL/@RuntimeVersion'
114
+ runtime_version value ( doc . root , 'APPPOOL/@RuntimeVersion' ) . gsub ( /^v/ , '' )
115
115
pipeline_mode value ( doc . root , 'APPPOOL/@PipelineMode' ) . to_sym
116
116
117
117
# add items
125
125
load_user_profile bool ( value ( doc . root , 'APPPOOL/add/processModel/@loadUserProfile' ) )
126
126
identity_type value ( doc . root , 'APPPOOL/add/processModel/@identityType' ) . to_sym if iis_version > 7.0
127
127
username value doc . root , 'APPPOOL/add/processModel/@userName'
128
+ unless username . nil? || desired . username . nil?
129
+ Chef ::Log . info ( 'username: ' + username + ' -> ' + desired . username )
130
+ end
128
131
password value doc . root , 'APPPOOL/add/processModel/@password'
129
132
logon_type value ( doc . root , 'APPPOOL/add/processModel/@logonType' ) . to_sym if iis_version > 7.0
130
133
manual_group_membership bool ( value ( doc . root , 'APPPOOL/add/processModel/@manualGroupMembership' ) )
189
192
end
190
193
191
194
action :config do
192
- converge_by "Configured Application Pool \" #{ new_resource } \" " do
193
- configure
194
- end
195
+ configure
195
196
end
196
197
197
198
action :delete do
198
199
if current_resource . runtime_version
199
200
converge_by "Deleted Application Pool \" #{ new_resource } \" " do
200
- shell_out! ( "#{ appcmd ( node ) } delete apppool \" #{ site_identifier } \" " )
201
+ shell_out! ( "#{ appcmd ( node ) } delete apppool \" #{ new_resource . name } \" " )
201
202
end
202
203
else
203
204
Chef ::Log . debug ( "#{ new_resource } pool does not exist - nothing to do" )
207
208
action :start do
208
209
if !current_resource . runtime_version
209
210
converge_by "Started Application Pool \" #{ new_resource } \" " do
210
- shell_out! ( "#{ appcmd ( node ) } start apppool \" #{ site_identifier } \" " ) unless new_resource . running
211
+ shell_out! ( "#{ appcmd ( node ) } start apppool \" #{ new_resource . name } \" " ) unless new_resource . running
211
212
end
212
213
else
213
214
Chef ::Log . debug ( "#{ new_resource } already running - nothing to do" )
217
218
action :stop do
218
219
if current_resource . runtime_version
219
220
converge_by "Stopped Application Pool \" #{ new_resource } \" " do
220
- shell_out! ( "#{ appcmd ( node ) } stop apppool \" #{ site_identifier } \" " )
221
+ shell_out! ( "#{ appcmd ( node ) } stop apppool \" #{ new_resource . name } \" " )
221
222
end
222
223
else
223
224
Chef ::Log . debug ( "#{ new_resource } already stopped - nothing to do" )
224
225
end
225
226
end
226
227
227
228
action :restart do
228
- converge_by "Restarted Application Pool \" #{ new_resource } \" " do
229
- shell_out! ( "#{ appcmd ( node ) } stop APPPOOL \" #{ site_identifier } \" " ) if running
230
- sleep 2
231
- shell_out! ( "#{ appcmd ( node ) } start APPPOOL \" #{ site_identifier } \" " )
229
+ if current_resource . runtime_version
230
+ converge_by "Restarted Application Pool \" #{ new_resource } \" " do
231
+ shell_out! ( "#{ appcmd ( node ) } stop APPPOOL \" #{ new_resource . name } \" " ) if running
232
+ sleep 2
233
+ shell_out! ( "#{ appcmd ( node ) } start APPPOOL \" #{ new_resource . name } \" " )
234
+ end
232
235
end
233
236
end
234
237
235
238
action :recycle do
236
- converge_by "Recycled Application Pool \" #{ new_resource } \" " do
237
- shell_out! ( "#{ appcmd ( node ) } recycle APPPOOL \" #{ site_identifier } \" " )
239
+ if current_resource . runtime_version
240
+ converge_by "Recycled Application Pool \" #{ new_resource } \" " do
241
+ shell_out! ( "#{ appcmd ( node ) } recycle APPPOOL \" #{ new_resource . name } \" " )
242
+ end
238
243
end
239
244
end
240
245
241
246
action_class . class_eval do
242
- def site_identifier
243
- new_resource . name
244
- end
245
-
246
247
def configure
247
248
# Application Pool Config
248
249
cmd = "#{ appcmd ( node ) } set config /section:applicationPools"
249
250
250
251
# root items
251
- converge_if_changed :auto_start do
252
- cmd << configure_application_pool ( "autoStart:#{ new_resource . auto_start } " )
253
- only_if { iis_version >= 7.0 }
252
+ if iis_version >= 7.0
253
+ converge_if_changed :auto_start do
254
+ cmd << configure_application_pool ( "autoStart:#{ new_resource . auto_start } " )
255
+ end
254
256
end
255
257
256
- converge_if_changed :start_mode do
257
- cmd << configure_application_pool ( "startMode:#{ new_resource . start_mode } " )
258
- only_if { iis_version >= 7.5 }
258
+ if iis_version >= 7.5
259
+ converge_if_changed :start_mode do
260
+ cmd << configure_application_pool ( "startMode:#{ new_resource . start_mode } " )
261
+ end
259
262
end
260
263
261
264
if new_resource . no_managed_code
@@ -294,9 +297,10 @@ def configure
294
297
converge_if_changed :idle_timeout do
295
298
cmd << configure_application_pool ( "processModel.idleTimeout:#{ new_resource . idle_timeout } " )
296
299
end
297
- converge_if_changed :idle_timeout_action do
298
- cmd << configure_application_pool ( "processModel.idleTimeoutAction:#{ new_resource . idle_timeout_action } " )
299
- only_if { iis_version >= 8.5 }
300
+ if iis_version >= 8.5
301
+ converge_if_changed :idle_timeout_action do
302
+ cmd << configure_application_pool ( "processModel.idleTimeoutAction:#{ new_resource . idle_timeout_action } " )
303
+ end
300
304
end
301
305
converge_if_changed :shutdown_time_limit do
302
306
cmd << configure_application_pool ( "processModel.shutdownTimeLimit:#{ new_resource . shutdown_time_limit } " )
@@ -314,17 +318,18 @@ def configure
314
318
cmd << configure_application_pool ( "processModel.pingResponseTime:#{ new_resource . ping_response_time } " )
315
319
end
316
320
317
- should_clear_apppool_schedules = ( ( new_resource . recycle_at_time != current_resource . recycle_at_time ) && !@node_array . empty? ) || ( new_resource . recycle_schedule_clear && !@node_array . empty? )
321
+ 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? )
318
322
319
323
# recycling items
320
324
## Special case this collection removal for now.
321
325
# TODO: test if this is needed
322
326
# is_new_recycle_at_time = true
323
- converge_by "Cleared Periodic Restart Schedule #{ new_resource } " do
324
- clear_pool_schedule_cmd = "#{ appcmd ( node ) } set config /section:applicationPools \" /-[name='#{ new_resource . name } '].recycling.periodicRestart.schedule\" "
325
- Chef ::Log . debug ( clear_pool_schedule_cmd )
326
- shell_out! ( clear_pool_schedule_cmd )
327
- only_if { should_clear_apppool_schedules }
327
+ if should_clear_apppool_schedules
328
+ converge_by "Cleared Periodic Restart Schedule #{ new_resource } - #{ should_clear_apppool_schedules } " do
329
+ clear_pool_schedule_cmd = "#{ appcmd ( node ) } set config /section:applicationPools \" /-[name='#{ new_resource . name } '].recycling.periodicRestart.schedule\" "
330
+ Chef ::Log . debug ( clear_pool_schedule_cmd )
331
+ shell_out! ( clear_pool_schedule_cmd )
332
+ end
328
333
end
329
334
330
335
converge_if_changed :recycle_after_time do
@@ -398,25 +403,23 @@ def configure
398
403
cmd << configure_application_pool ( "cpu.smpProcessorAffinityMask2:#{ new_resource . smp_processor_affinity_mask_2 . floor } " )
399
404
end
400
405
401
- converge_by "Configured Application Pool settings \" #{ new_resource } \" " do
402
- Chef ::Log . debug ( cmd )
403
- shell_out! ( cmd )
404
- not_if { cmd == "#{ appcmd ( node ) } set config /section:applicationPools" }
406
+ unless cmd == "#{ appcmd ( node ) } set config /section:applicationPools"
407
+ converge_by "Configured Application Pool \" #{ new_resource } \" " do
408
+ Chef ::Log . debug ( cmd )
409
+ shell_out! ( cmd )
410
+ end
405
411
end
406
412
407
413
# Application Pool Identity Settings
408
414
if new_resource . username && new_resource . username != ''
409
- cmd_default = "#{ appcmd ( node ) } set config /section:applicationPools"
410
- cmd_default << " \" /[name='#{ new_resource . name } '].processModel.identityType:SpecificUser\" "
411
-
412
- cmd = cmd_default
415
+ cmd = default_app_pool_user
413
416
converge_if_changed :username do
414
417
cmd << " \" /[name='#{ new_resource . name } '].processModel.userName:#{ new_resource . username } \" "
415
418
end
416
419
converge_if_changed :password do
417
420
cmd << " \" /[name='#{ new_resource . name } '].processModel.password:#{ new_resource . password } \" "
418
421
end
419
- if cmd != cmd_default
422
+ if cmd != default_app_pool_user
420
423
Chef ::Log . debug ( cmd )
421
424
shell_out! ( cmd )
422
425
end
@@ -432,6 +435,11 @@ def configure
432
435
end
433
436
end
434
437
438
+ def default_app_pool_user
439
+ cmd_default = "#{ appcmd ( node ) } set config /section:applicationPools"
440
+ cmd_default << " \" /[name='#{ new_resource . name } '].processModel.identityType:SpecificUser\" "
441
+ end
442
+
435
443
def configure_application_pool ( config , add_remove = '' )
436
444
" \" /#{ add_remove } [name='#{ new_resource . name } '].#{ config } \" "
437
445
end
0 commit comments