4

I have the following Chef recipe

aws_s3_file "/usr/share/tomcat/webapps/system.war" do
  bucket "mybucket"
  remote_path "builds/system_latest.war"
  aws_access_key_id node[:aws_access_key_id]
  aws_secret_access_key node[:aws_secret_access_key]
end

service "tomcat" do
  action [:restart]
end

aws_s3_file "/usr/share/tomcat/webapps/system/WEB-INF/application.properties" do
  bucket "mybucket"
  remote_path "config/application.properties"
  aws_access_key_id node[:aws_access_key_id]
  aws_secret_access_key node[:aws_secret_access_key]
end

It works fine every time I run it, except if the machine is a fresh one.

When it is a fresh machine, I get:

Errno::ENOENT ------------- No such file or directory - /usr/share/tomcat/webapps/system/WEB-INF/application.properties

I think that it happens because tomcat is not done deploying the application, so the folder does not exist when this statement is run.

I imagine that moving files around when an application is deployed is a normal procedure. How can I do that and guarantee that Chef is going to wait until the deploy is done?

1 Answer 1

4

Write some code (probably in either Ruby or Bash) to query if Tomcat is done, when put it in a while loop.

ruby_block 'wait for tomcat' do
  block do
    true until ::File.exists?('/usr/share/tomcat/webapps/system/WEB-INF')
  end
end
4
  • That will result in a resource that will be "updated" every chef run, right? Probably an unfortunate but necessary evil. Just a thought, but what would you think about putting this sort of loop into an only_if or not_if for an existing resource? Would that work? And wouldn't that still cause the chef run to wait, but without the side effect of an "updated" resource? Nov 5, 2014 at 1:49
  • If you are the kind of person that cares about resource update counts (hint: don't) you could use an LWRP instead.
    – coderanger
    Nov 5, 2014 at 8:20
  • But I do want to replace the file even if this exists. This is the file where the developers set the properties for the application, so it should be updated on every deploy :)
    – JSBach
    Nov 5, 2014 at 15:06
  • 1
    How can I add a timeout to this? If file doesnt arrive after (say) 30 seconds then something is wrong and I want my recipe to fail. Oct 10, 2016 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.