gpt4 book ai didi

mongodb - Chef 不会启动我的 init.d 服务

转载 作者:太空宇宙 更新时间:2023-11-03 17:19:06 25 4
gpt4 key购买 nike

我正在通过这个 mongo doc 创建一个服务.

我的 Recipe 中有这个通过模板安装服务:

service 'disable-transparent-hugepages' do
supports :restart => true, :start => true, :stop => true, :reload => true
action :nothing
end

template 'disable-transparent-hugepages' do
path '/etc/init.d/disable-transparent-hugepages'
source 'disable-transparent-hugepages.erb'
owner 'root'
group 'root'
mode '0755'
notifies :enable, 'service[disable-transparent-hugepages]'
notifies :start, 'service[disable-transparent-hugepages]'
end

当我多次运行配方时,它会将 init.d 脚本拉到正确的位置,但如果我检查它的状态,我会看到: enter image description here

在我确认它已安装后,我在配方中添加了一行以正常启动服务:

service 'disable-transparent-hugepages' do
action :start
end

但还没有开始。

如果我手动启动它,我可以看到它工作: enter image description here

为什么 Chef 不开始服务?

编辑:好的,所以我找到了 this SO question那说我的问题可能是我需要 init.d 脚本(在 mongo 文档的链接中找到)需要以非 0 返回码退出。我不确定如何让脚本在检查状态时返回非零代码。

最佳答案

这与脚本支持命令的假设有关。

引用 Chef 文档关于 service resource关于 supports 属性(强调最后一行是我的):

supports Ruby Type: Hash

A list of properties that controls how the chef-client is to attempt to manage a service: :restart, :reload, :status. For :restart, the init script or other service provider can use a restart command; if :restart is not specified, the chef-client attempts to stop and then start a service. For :reload, the init script or other service provider can use a reload command. For :status, the init script or other service provider can use a status command to determine if the service is running; if :status is not specified, the chef-client attempts to match the service_name against the process table as a regular expression, unless a pattern is specified as a parameter property. Default value: { :restart => false, :reload => false, :status => false } for all platforms (except for the Red Hat platform family, which defaults to { :restart => false, :reload => false, :status => true }.)

statustrue 时,提供者尝试调用它,如果它返回 0,则服务应该正在运行。

根据您提供的链接,该脚本仅支持 start,因此在使用参数 status 调用时返回 0。

解决此问题的一种方法是使用更精确的服务定义,如下所示:

service 'disable-transparent-hugepages' do
supports :restart => false, :start => true, :stop => false, :reload => false, :status => false
action :start
end

另一种方法是修复初始化脚本以实现状态命令,如果文件具有正确的内容则返回 0,否则返回 1。

我认为沿着这条线作为状态案例的东西(未经测试):

status)
if [ -d /sys/kernel/mm/transparent_hugepage ]; then
thp_path=/sys/kernel/mm/transparent_hugepage
elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
thp_path=/sys/kernel/mm/redhat_transparent_hugepage
else
return 0
fi

re='^(0|no)$'
return [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]]
;;

我的看法:

因为它不完全是真正的服务,所以我会直接管理这些文件,而不是为此使用伪服务。

关于mongodb - Chef 不会启动我的 init.d 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39340867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com