6
6

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を設定するときの注意点

Last updated at Posted at 2013-12-31

結論を先に書くと、「cron resourceのcommandの中身には改行をいれてはだめ」

これではまってしまう原因は、chefのreferenceに載っているexampleのせい

recipe.rb
cron "cookbooks_report" do
  action node.tags.include?('cookbooks-report') ? :create : :delete
  minute "0"
  hour "0"
  weekday "1"
  user "opscode"
  mailto "nharvey@opscode.com"
  home "/srv/opscode-community-site/shared/system"
  command %Q{
    cd /srv/opscode-community-site/current &&
    env RUBYLIB="/srv/opscode-community-site/current/lib"
    RAILS_ASSET_ID=`git rev-parse HEAD` RAILS_ENV="#{rails_env}"
    bundle exec rake cookbooks_report
  }
end

あんまり深く考えずにこれだけみると、commandの値を内容をcookbooks_reportという名前のスクリプトにしてどこかに保存してくれるのかと思ってそのままつかおうとしてみたが以下のようなエラーでうまくうごかない

Chef::Exceptions::Cron: cron[crontest] (crontest::default line 98) had an error: Chef::Exceptions::Cron: Error updating state of crontest, exit: 1
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider/cron.rb:210:in `write_crontab'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider/cron.rb:140:in `block in action_create'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/mixin/why_run.rb:52:in `call'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/mixin/why_run.rb:52:in `add_action'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider.rb:149:in `converge_by'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider/cron.rb:139:in `action_create'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider.rb:114:in `run_action'
:
:

以下によるとcommandの中に改行をいれてはだめらしい。

改行をなくせば回避できる

6
6
1

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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?