# issue when starting tomcat

**URL:** <https://forum.ansible.com/t/issue-when-starting-tomcat/13540>\
**Category:** Ansible Project\
**Created:** [September 24, 2013, 2:32pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540 "2013-09-24T14:32:58Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean\_Philippe\_Caruan](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jean\_Philippe\_Caruan](https://forum.ansible.com/u/Jean_Philippe_Caruan)\
**Post date:** [September 24, 2013, 2:32pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/1 "2013-09-24T14:32:58Z")

</div>

Hi,

I'm trying to install and run a tomcat instance. I followed the example  
code at  
[https://github.com/ansible/ansible-examples/tree/master/tomcat-standalone](https://github.com/ansible/ansible-examples/tree/master/tomcat-standalone) and  
it works fine except for starting tomcat.  
My roles/tomcat/tasks/main.yml file ends like this :

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 24, 2013, 6:42pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/2 "2013-09-24T18:42:28Z")

</div>

Tomcat can sometimes take a while to startup. Can you verify that it takes fewer than 30 seconds to say that it’s ready in catalina.out and port 8080 is available?

---

<div class="post-metadata">

**Author:** ![Jean\_Philippe\_Caruan](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jean\_Philippe\_Caruan](https://forum.ansible.com/u/Jean_Philippe_Caruan)\
**Post date:** [September 25, 2013, 7:07am UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/3 "2013-09-25T07:07:47Z")

</div>

Le 24/09/2013 20:42, James Cammarata a �crit :

> Tomcat can sometimes take a while to startup. Can you verify that it  
> takes fewer than 30 seconds to say that it's ready in catalina.out and  
> port 8080 is available?

It takes a few seconds to start, since there is no webapp to start :

INFO: Server startup in 3623 ms

-- Jean-Philippe Caruana

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 25, 2013, 12:24pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/4 "2013-09-25T12:24:40Z")

</div>

If this was saying ‘restarted’, I’d suggest possibly using the delay on the wait\_for parameter because it might have captured the previous run.

How are you determining that it is running and web accessible in 3.6 seconds?

---

<div class="post-metadata">

**Author:** ![Jean\_Philippe\_Caruan](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jean\_Philippe\_Caruan](https://forum.ansible.com/u/Jean_Philippe_Caruan)\
**Post date:** [September 25, 2013, 1:12pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/5 "2013-09-25T13:12:01Z")

</div>

Le 25/09/2013 14:24, Michael DeHaan a �crit :

> If this was saying 'restarted', I'd suggest possibly using the delay on  
> the wait\_for parameter because it might have captured the previous run.

I don't understand.

> How are you determining that it is running and web accessible in 3.6  
> seconds?

THat's what tomcat syas in catalina.out

-- Jean-Philippe Caruana

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 25, 2013, 3:33pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/6 "2013-09-25T15:33:42Z")

</div>

Yeah typically when that log message appears the server is ready to start handling requests. That makes me wonder if there’s not something else preventing the wait\_for from picking up that the port is ready, for instance a firewall with too-restrictive rules maybe? Either that or tomcat is not configured to listen on 127.0.0.1.

Can you do a restart and verify that “telnet localhost 8080” works within 30 seconds?

---

<div class="post-metadata">

**Author:** ![Jean\_Philippe\_Caruan](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jean\_Philippe\_Caruan](https://forum.ansible.com/u/Jean_Philippe_Caruan)\
**Post date:** [September 25, 2013, 5:48pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/7 "2013-09-25T17:48:41Z")

</div>

Le 25/09/2013 17:33, James Cammarata a �crit :

> Yeah typically when that log message appears the server is ready to  
> start handling requests. That makes me wonder if there's not something  
> else preventing the wait\_for from picking up that the port is ready, for  
> instance a firewall with too-restrictive rules maybe? Either that or  
> tomcat is not configured to listen on 127.0.0.1.

the problem is not the wait\_for, the problem is my "start tomcat task"  
doesn't start tomcat

- name: Start Tomcat  
&nbsp;&nbsp;service: name=tomcat state=started enabled=yes

--\> this doesn't start tomcat at all (therefore wait\_for is right), no  
process, nothing.

When I do a wait\_for and start tomcat by hand (sudo service tomcat  
start), then wait\_for is ok, says tomcat is started.

(I always launch my playbook with --ask-sudo-pass)  
-- Jean-Philippe Caruana

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [September 25, 2013, 6:03pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/8 "2013-09-25T18:03:10Z")

</div>

​- do you use the distro's stock tomcat or something you rolled out  
yourself?​  
- ​How do you start tomcat manually?​  
- Which init script are you using fro starting tomcat?

​You might try running the playbook with the option to keep the remote  
ansible files, then re-run those​ manually and try to debug them?

Serge

---

<div class="post-metadata">

**Author:** ![Jean\_Philippe\_Caruan](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jean\_Philippe\_Caruan](https://forum.ansible.com/u/Jean_Philippe_Caruan)\
**Post date:** [September 26, 2013, 8:22am UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/9 "2013-09-26T08:22:37Z")

</div>

Le 25/09/2013 20:03, Serge van Ginderachter a �crit :

> - do you use the distro's stock tomcat or something you rolled out yourself?

something I rolled out myself, as done in the example playbook

> - How do you start tomcat manually?

sudo service tomcat start

> - Which init script are you using fro starting tomcat?

a pretty standard one

> You might try running the playbook with the option to keep the remote  
> ansible files, then re-run those manually and try to debug them?

For now, I just ran it on my own box, locally.

-- Jean-Philippe Caruana

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 26, 2013, 12:25pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/10 "2013-09-26T12:25:59Z")

</div>

“a pretty standard one”

What does that mean? 🙂

---

<div class="post-metadata">

**Author:** ![Jean\_Philippe\_Caruan](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jean\_Philippe\_Caruan](https://forum.ansible.com/u/Jean_Philippe_Caruan)\
**Post date:** [September 26, 2013, 12:57pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/11 "2013-09-26T12:57:51Z")

</div>

Le 26/09/2013 14:25, Michael DeHaan a �crit :

> "a pretty standard one"
> 
> What does that mean? 🙂

It means the standard file (from ansible examples) with a few tweaks  
(JDK as a parameter).

-- Jean-Philippe Caruana

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [September 26, 2013, 1:07pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/12 "2013-09-26T13:07:58Z")

</div>

​The question was about the init script, ansible-examples doesn't carry one  
for tomcat AFAIK.  
I presume you meant the standard tomcat upstream init script​, or the one  
provided by your package.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [September 26, 2013, 1:12pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/13 "2013-09-26T13:12:59Z")

</div>

​OK, so a problem with running the service module​.  
I'd recommend running that manually with the test module hacking script,  
and debugging the service module script to see what happens.

---

<div class="post-metadata">

**Author:** ![Jean\_Philippe\_Caruan](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jean\_Philippe\_Caruan](https://forum.ansible.com/u/Jean_Philippe_Caruan)\
**Post date:** [September 26, 2013, 2:26pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/14 "2013-09-26T14:26:12Z")

</div>

Le 26/09/2013 15:07, Serge van Ginderachter a �crit :

> &nbsp;&nbsp;&nbsp;&nbsp;\> "a pretty standard one"  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> What does that mean? 🙂
> 
> &nbsp;&nbsp;&nbsp;&nbsp;It means the standard file (from ansible examples) with a few tweaks  
> &nbsp;&nbsp;&nbsp;&nbsp;(JDK as a parameter).
> 
> The question was about the init script, ansible-examples doesn't carry  
> one for tomcat AFAIK.  
> I presume you meant the standard tomcat upstream init script, or the one  
> provided by your package.

It took it from  
[https://github.com/ansible/ansible-examples/blob/master/tomcat-standalone/roles/tomcat/files/tomcat-initscript.sh](https://github.com/ansible/ansible-examples/blob/master/tomcat-standalone/roles/tomcat/files/tomcat-initscript.sh)  
and changed a few things, jdk path for example.

> I'd recommend running that manually with the test module hacking script,  
> and debugging the service module script to see what happens.

"sudo service tomcat start" works fine by itself.  
I don't understand with "test module hacking".

-- Jean-Philippe Caruana

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 26, 2013, 2:36pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/15 "2013-09-26T14:36:57Z")

</div>

How did you install tomcat, and what OS are you running on? If you’re using a packaged version, you shouldn’t need to redo the init script.

---

<div class="post-metadata">

**Author:** ![Timothy\_Gerla](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@Timothy\_Gerla](https://forum.ansible.com/u/Timothy_Gerla)\
**Post date:** [September 26, 2013, 3:28pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/16 "2013-09-26T15:28:35Z")

</div>

Hi everyone, just saw this.

Confession time! I wrote the Tomcat example and for various reasons I  
decided to not use the OS packaged version of Tomcat and instead used  
an example initscript provided by Apache. I tested it pretty  
carefully, though. I will dig in when I have a chance soon and see if  
I can reproduce this problem.

-Tim

---

<div class="post-metadata">

**Author:** ![AmiableAlbion](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@AmiableAlbion](https://forum.ansible.com/u/AmiableAlbion)\
**Post date:** [November 7, 2013, 12:40am UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/17 "2013-11-07T00:40:17Z")

</div>

Hi,  
I am experiencing the same issue using this same Ansible example. Perhaps I am also being bitten by the non-standard init script issue. My behavior is exactly like Jean-Philippe’s: I can start the Tomcat server fine if I log into the host and run /etc/init.d/tomcat start, but no matter of Ansible scripting will start it remotely for some reason.

I have confirmed that after a package installation of “tomcat6.noarch” via yum works as expected with the service init script /etc/init.d/tomcat6. If I shut it down on the host and run a simple playbook from my master to start it and wait, everything completes successfully.

Any ideas why the example init script Tim wrote would behave this way, that is, run fine from the command line and not from a playbook?

Thanks  
Albion

---

<div class="post-metadata">

**Author:** ![Morgan\_Bickle](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Morgan\_Bickle](https://forum.ansible.com/u/Morgan_Bickle)\
**Post date:** [December 16, 2013, 12:30am UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/18 "2013-12-16T00:30:21Z")

</div>

> I can start the Tomcat server fine if I log into the host and run /etc/init.d/tomcat start, but no matter of Ansible scripting will start it remotely for some reason.

I had this same issue on CentOS 5.9 and Oracle Linux 5.9.Changing the start tomcat task from **started** to **restarted** in the roles/tomcat/tasks/main.yml file seemed make the problem go away.

> - name: Start Tomcat  
> service: name=tomcat state=restarted enabled=yes

I haven’t been able to figure out why though the init.d start up script looks good to me.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 16, 2013, 1:25pm UTC](https://forum.ansible.com/t/issue-when-starting-tomcat/13540/19 "2013-12-16T13:25:55Z")

</div>

I see this was fixed by pull request, so thanks!
