java - 如果使用 Chef 更改了文件,如何删除目录?

标签 java tomcat chef-infra

我想创建一个 Chef 配方来使用 tomcat 部署 java 应用程序。当我更新 java 应用程序(我的 Recipe 中的 .WAR 文件,上传并获取一个节点来运行更新的 Recipe )时,我希望 Chef 停止 tomcat,删除 tomcat/webapps 文件夹的内容,复制新的 war,然后启动 tomcat再次。

我看过 if File.exists 的语法,但还没有看到 if 的任何内容。我怎样才能做到这一点? 我认为 Chef 具有此功能,因为它仅在校验和更改时更新文件。

最佳答案

我遗漏了一些细节,例如如何将 WAR 文件放在正确的位置。所以我假设您使用 cookbook_file 资源。

cookbook_file "path/to/release.war" do
  notifies :execute, "cleanup tomcat webapp directory", :before
  notifies :start,  "service[tomcat]"
end

execute "cleanup tomcat directory" do
  notifies :stop, "service[tomcat]", :before
  command "rm -r path/tomcat/webapps/*"
  action :nothing 
end

在计时器需要 chef 12.7 之前,服务 tomcat 必须在您将放置此代码的资源范围内可用。

但是,此解决方案可能会在运行 rm -r 时引入停机时间,并且需要完全停止/启动 tomcat。使用 hot deploy 不是更好吗? (在运行的服务器上)?

关于java - 如果使用 Chef 更改了文件,如何删除目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39117513/

相关文章:

java - Gradle在相关测试项目中找不到包

eclipse - 临时文件夹到eclipse

tomcat - 替换 Tomcat 7 中的 RequestDumperValve

amazon-web-services - 使用 cloudformation 为具有 Chef 角色的节点添加标签

curl - 如何在 Chef 配方中执行 curl 命令?

java - Java 中的二叉树抽象

java - 无法加载 fxml 文件

java - 如何在java中通过UDP发送音频流?

url-rewriting - 如何在 Apache-Tomcat Web 应用程序中获取浏览器 URL?

node.js - 使用 OpsWorks 在 AWS Linux 上安装hiredis 时出现问题