chef can't create cron -
i tried simplest example given http://docs.opscode.com/resource_cron.html#examples
cron "name_of_cron_entry" hour "8" weekday "6" mailto "admin@opscode.com" action :create end
i use knife ssh make recipe run on chef client, , client gives error:
error executing action create on resource cron[name_of_cron_entry] error updating state of name_of_cron_entry, exit: 1
has met same problem before? solutions?
i stumbled same problem , found example using had newlines in it. problem cron provider runs crontab -u user -
, pipes stdin process. appears doesn't accept newlines whatever reason.
in /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/provider/cron.rb
, found this:
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) |pid, stdin, stdout, stderr| stdin.write crontab end if status.exitstatus > 0 raise chef::exceptions::cron, "error updating state of #{@new_resource.name}, exit: #{status.exitstatus}" end
strangely enough, running example seems work me, , creates empty crontab entry root:
root@chef-test-01:~# crontab -l # chef name: name_of_cron_entry mailto=admin@opscode.com * 8 * * 6
this suggests me using different version of chef gem & cron provider.
so, depending on version of chef gem using, this bug
for reference, example didn't work me based on one:
cron "cookbooks_report" 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
the command running was:
command %q{ cd /path/to/src/my-project && bundle exec my_script.rb }
there 2 fixes worked me:
- use
command 'cd /path/to/src/my-project && bundle exec my_script.rb'
- change
cron
providercron_d
provider cron cookbook
note: don't think documentation either provider in chef correct however... newlines not supported in crontab format unless escaped backslash \
. in testing second fix above, resulting crontab not valid , had newlines between commands not escaped.
Comments
Post a Comment