主厨服务资源init_command,有人可以向我解释一下

时间:2014-10-20 12:06:01

标签: service chef

我对init_command感到有些困惑。

如何使用此命令?

例如,我可以这样做:

init_command "path\to\service\rake serivce:"

并将它作为

运行

开始:

"path\to\service\rake serivce:start"

停止:

"path\to\service\rake serivce:stop"

或将它运行为:

"path\to\service\rake serivce:"

只为其他命令添加启动,停止等?

手动指定每个命令会更好吗,因此启动它会是:

start_command "path\to\service\rake serivce:start"

并且停止它将是:

stop_command "path\to\service\rake serivce:stop"

我的意思是,我查看了服务资源文档,但它没有很好地解释这一点。

1 个答案:

答案 0 :(得分:1)

首先,init_command似乎仅适用于init资源的service提供商。如果您使用的是redhat家庭操作系统,那么这没问题,但其他操作系统系列可能不会默认为init

其次,即使在init提供商中,您也无法获得所追求的结果。你会得到:

'path/to/service/rake: start' # note the space between the ':' and the command

最后,init_command实际上是在寻找标准的init脚本,而不是rake命令。

如果您想要这种行为,我建议您使用cookbook_file资源将包装脚本放在/etc/initd目录中。该脚本只是传递命令来进行rake。

#!/bin/bash
path/to/rake/command service:$1

然后,您可以将其提供给init_command,或者确保文件为/etc/init/service_name.conf,这是init提供商的默认设置。

非常好奇,init_command的用法在这里:

https://github.com/opscode/chef/blob/master/lib/chef/provider/service/init.rb#L53