0

我的食谱使用 IIS 食谱删除然后添加并启动一个带有绑定的 IIS 网站,然后使用以下命令http添加绑定:httpsshell_out

iis_site iis_site_name do
    action :delete
end


   ... other things ...

iis_site iis_site_name do
    protocol :http
    port 80
    path site_dir
    application_pool iis_site_name
    host_header site_header
    action [:add,:start]
end

if https
    https_binding(iis_site_name, site_header)
end


def https_binding(site_name, site_header)
  cmd = "#{appcmd} set site /site.name:\"#{site_name}\" /+bindings.[protocol='https',bindingInformation='*:443:#{site_header}']"
  Chef::Log.info("Running HTTPS config command")
  Chef::Log.debug(cmd)
  shell_out!(cmd, {:returns => [0,42]})
  Chef::Log.info("HTTPS config command run")
end

查看调试日志,它显示https_binding在删除 IIS 站点之前调用了日志调试/信息调用:

[2013-08-30T16:22:01+00:00] INFO: Running HTTPS config command
[2013-08-30T16:22:01+00:00] DEBUG: C:\Windows\System32\inetsrv\appcmd.exe set site /site.name:"mysite" /+bindings.[protocol='https',bindingInformation='*:443:mysite.com']
ERROR ( message:New binding object missing required attributes. Cannot add duplicate collection entry of type 'binding'
with combined key attributes 'protocol, bindingInformation' respectively set to 'https, *:443:mysite.com'
. )
[2013-08-30T16:22:01+00:00] INFO: HTTPS config command run
 (up to date)
Recipe: <Dynamically Defined Resource>
* iis_site[mysite action delete[2013-08-30T16:22:01+00:00] INFO: Processing iis_site[mysite] action delete (c:/chef/cache/cookbooks/mycookbook/providers/website.rb line 47)

为什么这些命令运行得这么晚而不是被调用时?

4

1 回答 1

0

将我的代码更改为以下似乎可行,但我不喜欢这种方法。有没有更好的办法?

deleteSite = iis_site iis_site_name do
end

deleteSite.run_action(:delete)


   ... other things ...

createSite = iis_site iis_site_name do
    protocol :http
    port 80
    path site_dir
    application_pool iis_site_name
    host_header site_header
end

createSite.run_action(:add)
createSite.run_action(:start)

if https
    https_binding(iis_site_name, site_header)
end


def https_binding(site_name, site_header)
  cmd = "#{appcmd} set site /site.name:\"#{site_name}\" /+bindings.[protocol='https',bindingInformation='*:443:#{site_header}']"
  Chef::Log.info("Running HTTPS config command")
  Chef::Log.debug(cmd)
  shell_out!(cmd, {:returns => [0,42]})
  Chef::Log.info("HTTPS config command run")
end
于 2013-08-30T21:12:47.237 回答