繁体   English   中英

厨师new_resource。 <value> 与 <value>

[英]Chef new_resource.<value> vs. <value>

我继承了另一本带有自定义资源的食谱的食谱。

我试图弄清楚这段代码中new_resource的使用。

在下面的代码中, path new_resource.fullpath导致“未定义的方法”。

当我将该行更改为仅path fullpath以引用局部变量时,它就可以正常工作。 我不知道以前的意图是什么。

我相信这很简单。 寻找ELI5。 谢谢!

完整代码块。

resource_name :mb_worker_role
default_action :create

property :service_name, String, name_property: true
property :root_path, String, required: true
property :executable, String, required: true
property :wcf_port, [Integer, String], default: 808
property :health_port, [Integer, String], default: 8000
property :use_dummy, [TrueClass, FalseClass], default: true

action :create do
  # Create firewall allow for WCF port
  windows_firewall_rule "#{new_resource.service_name} - WCF" do
    localport new_resource.wcf_port.to_s
    protocol 'TCP'
    firewall_action :allow
  end

  # Create firewall allow for health port
  windows_firewall_rule "#{new_resource.service_name} - Health" do
    localport new_resource.health_port.to_s
    protocol 'TCP'
    firewall_action :allow
  end

  # Full path to service executable at root_path\executable
  fullpath = "#{new_resource.root_path}\\#{new_resource.executable}"

  # Create directory for worker role application root
  directory new_resource.root_path do
    recursive true
    action :create
  end

  # Set NetTCPPortSharing to start on demand
  windows_service 'NetTCPPortSharing' do
    action :configure_startup
    startup_type :manual
  end

  # Stage the dummy worker role executable if requested
  # Only used to verify this resource when testing
  if property_is_set?(:use_dummy)
    cookbook_file 'Stage dummy worker role executable' do
      # path new_resource.fullpath
      path fullpath
      cookbook 'mb_worker_role'
      source 'WorkerRole.Default.exe'
      only_if { new_resource.use_dummy }
      action :create
    end
  end

  # Create windows service if it does not exist
  powershell_script "Installing Windows service #{new_resource.service_name}" do
    code <<-EOH
      # Create the Windows service
      sc.exe create "#{new_resource.service_name}" binPath="#{fullpath}"
    EOH
    not_if "(Get-Service -Name #{new_resource.service_name}).Name -eq '#{new_resource.service_name}'"
  end

  # Set service to automatic and make sure it's running
  windows_service new_resource.service_name do
    action [:configure_startup, :enable, :start]
    startup_type :automatic
  end
end

path fullpath是一个神奇的别名系统,我们目前不鼓励这样做。 尝试这很不错,但是语法存在很多导致意外行为的问题。 使用new_resource.fullpath ,脚步少得多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM