如何使用Chef配方添加cron作业条目

son*_*rma 3 shell cron cookbook chef-infra chef-recipe

所有,

我有一个shell脚本,它创建日志的tar文件.我把食谱中的食谱嵌入了食谱中.

配方看起来像这样:

cookbook_file "/var/create-tar.sh" do
source "create-tar.sh"
mode 0755
end

execute "create tar files of logs older than 1 day" do
command "sh /var/create-tar.sh"
end
Run Code Online (Sandbox Code Playgroud)

执行资源正在执行配方.我想通过在cronjob中创建一个条目来在cron中安排这个shell脚本.

crontab条目应该是:

*/2 * * * * sh -x /var/test.sh  > /var/log/backup 2>&1
Run Code Online (Sandbox Code Playgroud)

如何在食谱中添加此条目?

Ste*_*ing 14

Cron Jobs在厨师

Chef包含用于设置Cron作业的资源 - 它被称为cron.

cron 'test' do
  minute '*/2'
  command 'sh -x /var/test.sh  > /var/log/backup 2>&1'
end
Run Code Online (Sandbox Code Playgroud)

但是你的最终目标是什么?日志轮换?

使用Chef和Logrotate记录旋转

有一个工具,称为logrotate,并有一个厨师食谱:logrotate.

这为您提供了一个资源,允许您指定要旋转的日志以及使用哪些选项:

logrotate_app 'test' do
  path      '/var/log/test/*.log'
  frequency 'daily'
  rotate    30
end
Run Code Online (Sandbox Code Playgroud)

以防你想要实施这样的事情;-)