Start tomcat

208 views
Skip to first unread message

GBANE FETIGUE

unread,
Mar 13, 2016, 9:15:46 PM3/13/16
to Ansible Development
Hi folks,

Is anybody has an idea how can i resolve that error message? 
TASK [tomcat : copy mmc.war to webapps] ****************************************
ok: [webserver1]

TASK [tomcat : Set Java_opts for tomcat] ***************************************
ok: [webserver1]

TASK [tomcat : install Tomcat init script] *************************************
ok: [webserver1]

TASK [tomcat : Start Tomcat] ***************************************************
changed: [webserver1]

TASK [tomcat : wait for tomcat to start] ***************************************
fatal: [webserver1]: FAILED! => {"changed": false, "elapsed": 30, "failed": true, "msg": "Timeout when waiting for 127.0.0.1:8080"}

NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @mmc.retry

PLAY RECAP *********************************************************************
webserver1                 : ok=13   changed=1    unreachable=0    failed=1


any suggestion ??

Rene Moser

unread,
Mar 14, 2016, 2:51:28 AM3/14/16
to ansibl...@googlegroups.com
Hi

On 03/14/2016 02:15 AM, GBANE FETIGUE wrote:

> TASK [tomcat : wait for tomcat to start]
> ***************************************
> fatal: [webserver1]: FAILED! => {"changed": false, "elapsed": 30,
> "failed": true, "msg": "Timeout when waiting for 127.0.0.1:8080"}

You didn't share the playbook so I can just guess this task is done with
wait_for, right?

It seems you defined the timeout to 30 seconds, increasing this timeout
to a more appropriate value could solve this issue. If you remove the
timeout argument, the default would be 300 sec. Find more docs and
examples on http://docs.ansible.com/ansible/wait_for_module.html

- wait_for:
port: 8080
timeout: 60

Regards
René

jhawkesworth

unread,
Mar 14, 2016, 7:50:39 AM3/14/16
to Ansible Development
Since this is tomcat I would recommend inserting a pause before your use wait_for as tomcat seems to come up, grab the port, do a lot of stuff and then only start listening on the port once it has deployed any wars inside it.   This messes up wait_for as it can't make sense out of the locked port.

I set a different pause interval according the environment I am running in so the pause period doesn't have to be unnecessarily long.  
I usually use a value which is a few seconds long than it takes for the message 'Server startup in ...' to appear in the tomcat stderr logging.

Hope this helps,

Jon

GBANE FETIGUE

unread,
Mar 14, 2016, 10:16:38 AM3/14/16
to Ansible Development
 name: Install Java 1.7
  apt: name=openjdk-7-jdk state=present update_cache=true

- name: add group Tomcat
  group: name=tomcat state=present

- name: add Tomcat User
  user: name=tomcat group=tomcat home=/usr/share/tomcat createhome=no
  sudo: True

- name: Download Tomcat

- name: Extract archive
  command: chdir=/usr/share  /bin/tar -xvf /opt/apache-tomcat-8.0.1.tar.gz -C /opt/ creates=/opt/apache-tomcat-8.0.1

- name: Symlink Install directory
  file: src=/opt/apache-tomcat-8.0.1 path=/usr/share/tomcat state=link

- name: Configure Tomcat server
  template: src=server.xml dest=/usr/share/tomcat/conf/
  notify: restart tomcat

- name: Configure Tomcat users
  template: src=tomcat-users.xml dest=/usr/share/tomcat/conf/
  notify: restart tomcat

- name: copy mmc.war to webapps
  copy: src=files/mmc.war dest=/usr/share/tomcat/webapps/

- name: Set Java_opts for tomcat
  lineinfile: dest=/opt/apache-tomcat-8.0.1/bin/setenv.sh line='export JAVA_OPTS="-Xms1024M -Xmx1024M -XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=256m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true' create=yes state=present mode=0555

- name: install Tomcat init script
  copy:  src=files/tomcat-init.sh  dest=/etc/init.d/tomcat mode=0755

#- name: Restart Tomcat
# command: service tomcat restart
#- name: stop Tomcat
 # command: /usr/share/tomcat/bin/shutdown.sh

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

- name: wait for tomcat to start
  wait_for: port=8080 delay=10

GBANE FETIGUE

unread,
Mar 14, 2016, 10:18:06 AM3/14/16
to Ansible Development


- name: wait for tomcat to start
  wait_for: port=8080 delay=10


GBANE FETIGUE

unread,
Mar 14, 2016, 10:31:25 AM3/14/16
to Ansible Development
I posted my playbook could please look an eye on it 


On Monday, March 14, 2016 at 7:50:39 AM UTC-4, jhawkesworth wrote:

jhawkesworth

unread,
Mar 14, 2016, 11:20:06 AM3/14/16
to Ansible Development
Looks good, as I said, I suggest adding something like

- name: give tomcat some time to start up
  pause: seconds={{ tomcat_startup_delay | default(30) }}
  delegate_to: localhost

... before your wait_for because of the port-grabbed-but-not-yet-listening problem mentioned above.

You might want to delegate the wait_for to localhost as well so that you are checking it is available from a remote machine too, depending on your needs.

Also I notice you have some 

notify: restart_tomcat 

statements in your playbook, implying you are using a handler to restart tomcat.

  I don't use handlers myself but it possible that tomcat will be being restarted after all the steps in your playbook have completed, which you probably don't want straight after waiting for tomcat to come back up.

Hope this helps,

Jon

GBANE FETIGUE

unread,
Mar 14, 2016, 11:47:01 AM3/14/16
to Ansible Development
I would like to know 
- name: give tomcat some time to start up
  pause: seconds={{ tomcat_startup_delay | default(30) }}
  delegate_to: localhost

need to be between the start tomcat and the wait for or complete before start tomcat ; also I want to let you know that i am testing that locally I don't have any remote host 

GBANE FETIGUE

unread,
Mar 14, 2016, 11:55:34 AM3/14/16
to Ansible Development
still having the same issue after adding the pause 


On Monday, March 14, 2016 at 11:20:06 AM UTC-4, jhawkesworth wrote:

jhawkesworth

unread,
Mar 14, 2016, 11:55:36 AM3/14/16
to Ansible Development
Yes, my suggestion is between the start tomcat and the wait_for

GBANE FETIGUE

unread,
Mar 14, 2016, 12:00:10 PM3/14/16
to Ansible Development
Yeah I tried and still not working 

jhawkesworth

unread,
Mar 14, 2016, 12:04:56 PM3/14/16
to Ansible Development
Is tomcat configured to listen on 8080 ?  I notice you have a custom server.xml

are there errors in tomcat logs?

Serge van Ginderachter

unread,
Mar 14, 2016, 12:07:07 PM3/14/16
to Ansible Development
Did you ever manually check if that tomcat eventually starts?
Reply all
Reply to author
Forward
0 new messages