我试图创建一个厨师食谱,以启动多个mpd实例在我的流浪虚拟盒(使用厨师-独奏)。
我希望像下面这样配置Vagrantfile中的每个实例:
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实例)。
这就是我目前的食谱:
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我对此有几个问题:
sudo service mpd_mix start。为什么?/etc/mpd_mix.conf配置文件,因为它仍然调用使用/etc/mpd.conf的/etc/init.d/mpd start。如何更改它,以便它对每个mpd实例使用正确的配置文件?/etc/mpd_tech.conf和/etc/mpd_mix.conf都使用技术通道属性。看起来混合设置被覆盖了吗?我怎么才能解决呢?我真的很想在这方面提供一些帮助,因为我对厨师烹饪书很陌生。
发布于 2014-05-29 13:27:20
我想出了怎么做。以下是相关代码部分:
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上完整的食谱存储库。
https://stackoverflow.com/questions/23928478
复制相似问题