如何确定目录中的任何文件是否已更改 [英] How to determine if any file in a directory has changed

查看:85
本文介绍了如何确定目录中的任何文件是否已更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chef是否可以确定它是否更改了给定目录中的任何文件?如果要更新conf.d目录中的任何设置,我想重新启动服务器进程。

Is there a way for Chef to determine if it has changed any file in a given directory? I'd like to restart a server process if any settings in a conf.d directory are updated.

我确定可以将md5sums列表写入到在每次厨师客户运行中保存文件,并将当前结果与以前的迭代进行比较。但这是解决似乎是常见情况的大量代码。有更好的方法吗?

I'm sure it's possible to write a list of md5sums to a file on each chef-client run, and compare current to previous iterations. But that's a fair bit of code to address what seems to be a common scenario. Is there a better way?

推荐答案

厨师提供了一个称为通知

这可让您定义一个资源的更改触发另一资源的执行。提到的在配置文件更改后重启服务可能是最常见的用例。

This allows you to define that a change in one resource triggers execution of another resource. The mentioned restart of a service after the config file changed is probably the most common use case.

template "/etc/foo/conf.d/example.conf" do
    notifies :restart, "service[foo]"
end

service "foo" do
    supports :restart => true, :reload => true
    action :enable
end

默认情况下,通知为:delayed ,这意味着它们在Chef运行结束时被触发。这可以帮助您避免例如为每个更改的配置文件重新启动一次的服务。如果要立即通知,请使用

By default, notifications are :delayed, which means that they are triggered at the end of the Chef run. This helps you to avoid e.g. a service to restart once for every single changed configuration file. If you want an immediate notification, use

notifies :restart, "service[foo]", :immediately

当然,您不仅可以将Chef的通知用于服务,还可以用于任何资源。 文档中给出了更多示例。

Of course, you can use Chef's notifications not only for services, but for any resource. More examples are given in the documentation.

这篇关于如何确定目录中的任何文件是否已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆