我使用Chef配方来管理在Amazon EC2实例上运行的一些Tomcat服务器。在我需要使用大量相同的Tomcats并且具有相同的.jars / Java选项/等的场景中,它非常适合我。
但是,我遇到了一个我不确定如何处理的用例。基本上,每个Tomcat都有一个context.xml(位于/ etc / tomcat7)文件,我希望将其配置为具有需要指向特定端点的Manager元素(Amazon中与其名称对应的Elasticache,所以TomcatA有ElasticacheA等等)。最初,我在配方中使用关联的context.xml模板获得了以下代码:
elasticache="TomcatA"
elasticache_suffix = ".xxx.cfg.use1.cache.amazonaws.com"
template 'tomcat context.xml configuration' do
path ::File.join(tomcat_directory, 'context.xml')
source 'context.xml.erb'
variables(
{
:elasticache => elasticache,
:elasticache_suffix => elasticache_suffix
}
)
owner 'root'
group node["tomcat"]["group"]
mode 00644
notifies :restart, 'service[tomcat7]', :delayed
end
context.xml的模板:
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application ->
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Manager
className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="<%=@elasticache%><%=@elasticache_suffix%>:11211"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
sessionBackupAsync="true"
sticky="true"
copyCollectionsForSerialization="false"
/>
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
</Context>
然而,这显然不适用于我的目的,因为Chef将确保所有现有设置都使用ElasticacheA。
我可以使用AWS CLI获取我需要的Elasticache名称值,但是如何确保Chef每次都不会使用该值覆盖现有设置?理想情况下,每次运行配方都会为此模板生成一个新结果,该结果不会影响已在使用的任何设置。
答案 0 :(得分:0)
这里你的选择很少。所有都来自节点属性,而不是硬编码的elasticache
变量,您应该使用节点属性,例如node["tomcat"]["elasticache"]
。您可以通过两种方式将其调整为每个部署。