如何让厨师重新启动服务并传入其他参数?

Tom*_*ies 1 sphinx chef-infra

我有一个用于Sphinx配置的Rails站点的模板.在不同端口上运行的同一台机器上可以有多个不同的Sphinx服务,每个应用程序一个.因此,如果相应的配置模板发生更改,则II仅希望为每个站点重新启动Sphinx.我创建了一个/etc/init.d/sphinx脚本,根据类似于的参数重新启动一个sphinx:

/etc/init.d/sphinx restart /etc/sphinx/site1.conf
Run Code Online (Sandbox Code Playgroud)

其中site1.conf由Chef模板定义.我真的很想使用Chef Templates的通知功能在模板更改时传入正确的site1.conf参数.这可能吗?

或者,我想我可以为每个站点注册一个不同的服务,类似于:

/etc/init.d/sphinx_site1
Run Code Online (Sandbox Code Playgroud)

但是,我更愿意将参数传递给脚本.

and*_*wle 6

定义service资源时,您可以自定义将要运行的启动,停止和重新启动命令.您可以service使用这些自定义命令为每个站点定义资源,并设置相应的通知.

例如:

service "sphinx_site1" do
  supports :restart => true
  restart_command "/etc/init.d/sphinx restart /etc/sphinx/site1.conf"
  action :nothing
end

template "/etc/sphinx/site1.conf" do
  notifies :restart, "service[sphix_site1]"
end