Hi
I want to run the tomcat on port 9090 instead of 8080. So I am trying to change the port no. in server.xml file in conf directory of tomcat.
server.xml file
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Chef code in .rb file
xml_edit "#{node['thirdParty']['root_path']}\Tomcat\#{node['tomcat']['directory_name']}/conf/server.xml" do
edits [
{action: :replace, target: '/Server/Service/Connector[@port=""8080""]', fragment: "port=""9090""]"}
]
action :bulk
end
Option 1 -
You could be better off with a template
your_cookbook_name/templates/default/server.xml.erb
Contents, something like -
... Connector port="<%= @port_no %>" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" ...
OR
... Connector port="<%= node['port_no'] %>" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" ...
The port_no value could come from 'ohai' or Policyfile.rb.
Option 2 -
If you don't want to do above, you could do this -
server_xms_conf_file_name = '/path/to/server.xml'
if ::File.exist?(server_xms_conf_file_name)
sever_xml_conf_file = ::Chef::Util::FileEdit.new(server_xms_conf_file_name)
sever_xml_conf_file.search_file_replace(/8080/, '9090')
sever_xml_conf_file.write_file
end
I would pick Option 1, anytime.