我想创建一个 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/