首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >配置多个mpd实例的厨师配方

配置多个mpd实例的厨师配方
EN

Stack Overflow用户
提问于 2014-05-29 07:55:19
回答 1查看 831关注 0票数 0

我试图创建一个厨师食谱,以启动多个mpd实例在我的流浪虚拟盒(使用厨师-独奏)。

我希望像下面这样配置Vagrantfile中的每个实例:

代码语言:javascript
复制
mpd: {
  channels: {
    mix: {
      name: 'mpd_mix',
      bind: '0.0.0.0',
      socket: '/home/vagrant/.mpd/socket/mix',
      port: '6600'
    },
    tech: {
      name: 'mpd_tech',
      bind: '0.0.0.0',
      socket: '/home/vagrant/.mpd/socket/tech',
      port: '6601'
    }
  }
}

因此,菜谱应该使用这些设置并循环它们(为每个通道创建一个mpd实例)。

这就是我目前的食谱:

代码语言:javascript
复制
package "mpd"

node.normal[:mpd][:channels].each_value do |channel|
    # create socket
    file channel[:socket] do
      action :touch
    end

    # trying to set the attributes for the config file and the service
    node.set[:mpd][:port] = channel[:port]
    node.set[:mpd][:db_file] = "/var/lib/mpd/tag_cache_" + channel[:name]
    node.set[:mpd][:bind_2] = channel[:socket]
    node.set[:mpd][:icecast_mountpoint] = "/" + channel[:name] + ".mp3"
    node.set[:mpd][:channel_name] = channel[:name]

    # create service
    service channel[:name] do
      service_name "mpd" # linux service command
      action :enable
    end

    # create the corresponding config file
    config_filename = "/etc/" + channel[:name] + ".conf"
    template config_filename do
      source "mpd.conf.erb"
      mode "0644"
      notifies :restart, resources(:service => channel[:name])
    end
end

我对此有几个问题:

  1. Ist不为每个mpd实例创建系统服务,所以我可以执行sudo service mpd_mix start。为什么?
  2. 在启动mpd时,它不使用/etc/mpd_mix.conf配置文件,因为它仍然调用使用/etc/mpd.conf/etc/init.d/mpd start。如何更改它,以便它对每个mpd实例使用正确的配置文件?
  3. 为创建配置文件调整属性不像预期的那样工作(请参阅上面代码中的node.set部分)。配置文件、/etc/mpd_tech.conf/etc/mpd_mix.conf都使用技术通道属性。看起来混合设置被覆盖了吗?我怎么才能解决呢?

我真的很想在这方面提供一些帮助,因为我对厨师烹饪书很陌生。

EN

回答 1

Stack Overflow用户

发布于 2014-05-29 13:27:20

我想出了怎么做。以下是相关代码部分:

代码语言:javascript
复制
node[:mpd][:channels].each_value do |channel|

    # create socket
    file channel[:socket] do
      action :touch
    end

    # create init file
    init_filename = "/etc/init.d/" + channel[:name]
    template init_filename do
      variables :channel => channel
      source "mpd.init.erb"
      mode "0755"
    end

    # create service
    service channel[:name] do
      service_name channel[:name] # linux service command
      action :enable
    end

    # create config file
    config_filename = "/etc/" + channel[:name] + ".conf"
    template config_filename do
      variables :channel => channel
      source "mpd.conf.erb"
      mode "0644"
      notifies :restart, resources(:service => channel[:name])
    end

end

如果您想仔细查看一下,请查看github:https://github.com/i42n/chef-cookbook-mpd/blob/master/recipes/default.rb上完整的食谱存储库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23928478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档