在移动文件之前,如何让Chef等待应用程序部署?

时间:2014-11-04 20:57:22

标签: chef 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

每次运行它都会正常工作,除非机器是新机器。

当它是一台新机器时,我得到:

  

errno的:: ENOENT   -------------没有这样的文件或目录 - /usr/share/tomcat/webapps/system/WEB-INF/application.properties

我认为这是因为tomcat没有完成部署应用程序,因此运行此语句时该文件夹不存在。

我认为在部署应用程序时移动文件是正常的过程。我该怎么做并保证Chef会等到部署完成?

1 个答案:

答案 0 :(得分:3)

编写一些代码(可能在Ruby或Bash中),以便在将Tomcat放入while循环时查询Tomcat是否完成。

ruby_block 'wait for tomcat' do
  block do
    true until ::File.exists?('/usr/share/tomcat/webapps/system/WEB-INF')
  end
end