5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ChefのCronリソースがPredefined scheduling指定に対応した

Last updated at Posted at 2014-05-04

@rebootとかのアレ。Chef-Clientの11.12以降(多分)で実装されています。

Cron#Predefined_scheduling_definitions | Wikipedia

レシピサンプル

リブート時を指定してジョブを登録するにはtime Resource Attributeを使ってこうする。

cron.rb
cron 'at_reboot' do
  command '/bin/true'
  time :reboot
end

chef-applyで試してみる

chef-apply_stdout
$ chef-client -v
Chef: 11.12.4


$ sudo chef-apply cron.rb 
Recipe: (chef-apply cookbook)::(chef-apply recipe)
  * cron[at_reboot] action create
    - add crontab entry for cron[at_reboot]

エントリーを確認すると、@rebootなジョブが。

$ sudo crontab -l -u root
# Chef Name: at_reboot
@reboot /bin/true

指定できるのは次の通り。

SPECIAL_TIME_VALUES = [:reboot, :yearly, :annually, :monthly, :weekly, :daily, :midnight, :hourly]

消せない件

Amazon linux+omunibus installのchef-clientで試してるんですが、action :deleteでジョブがちゃんと消えない。

$ sudo chef-apply cron.rb 
Recipe: (chef-apply cookbook)::(chef-apply recipe)
  * cron[at_reboot] action delete
    - save unmodified crontab

## ?? unmodified ??

$ sudo crontab -l -u root
@reboot /bin/true

マークだけ消えた。改行の扱い周りだと思うので、原因調べて治したいとこです。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?