Ohai Chefs,
I have a cookbook that installs Tomcat7, sets up an `/etc/init.d` service to start, stop, or restart Tomcat, and provides a LWRP to deploy applications to the instance from our Artifactory setup.
It all works with one caveat: Tomcat gets restarted every time the chef-client daemon runs, or every 15 minutes in this case.
Here is the `default` recipe, which installs Tomcat and sets up the service:
# Create a tomcat user
user node['tomcat']['tomcat_user'] do
comment 'tomcat user'
system true
shell "/bin/false"
end
# Create home for Tomcat
directory "#{node['tomcat']['tomcat_home']}" do
owner node['tomcat']['tomcat_user']
group node['tomcat']['tomcat_user']
mode "0755"
recursive true
action :create
end
# use ark to extract the archive
ark "#{node['tomcat']['tomcat_version']}" do
path node['tomcat']['tomcat_home']
url node['tomcat']['tomcat_url']
version node['tomcat']['tomcat_version']
owner node['tomcat']['tomcat_user']
checksum node['tomcat']['checksum']
action [ :put ]
end
# Create /etc/init.d entry for Tomcat
template "#{node['tomcat']['service']}" do
source "tomcat7.erb"
mode "0755"
owner "root"
group "root"
end
# Tomcat Service
# Control whether Tomcat restarts automatically or not
if node['tomcat']['autostart']
service 'tomcat' do
# service_name "tomcat#{node['tomcat']['base_version']}"
service_name "tomcat7"
supports :restart => false, :reload => false, :start => true, :stop => true
action [ :start, :enable ]
notifies :run, 'execute[wait for tomcat]', :immediately
retries 4
retry_delay 30
end
end
execute 'wait for tomcat' do
command 'sleep 5'
action :nothing
end
I recently added the conditional `if node[‘tomcat’][‘autostart’]` around the `service`. Even with that attribute set to `false` the service restarts with every daemon run.
For completeness sake, here is the template I’m using for the `/etc/init.d` script.
#!/bin/bash
#
### BEGIN INIT INFO
# Provides: tomcat7
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop Tomcat server
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
if [ -f <%= node["tomcat"]["tomcat_conf"] %>/catalina.sh.includes ]; then
source <%= node["tomcat"]["tomcat_conf"] %>/catalina.sh.includes
fi
start() {
sh <%= node["tomcat"]["tomcat_bin"] %>/startup.sh
}
stop() {
sh <%= node["tomcat"]["tomcat_bin"] %>/catalina.sh stop -force
}
showconfig() {
echo ${JAVA_OPTS}
}
case $1 in
start|stop|showconfig) $1;;
restart) stop; sleep 2; start;;
*) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac
Any ideas as to what I’m doing that is causing Tomcat to be restarted with each daemon run?
Thanks in advance,
Mark
Archive powered by MHonArc 2.6.16.