Start tomcat

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 ??

Hi

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é

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

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
    get_url: url=http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.1/bin/apache-tomcat-8.0.1.tar.gz dest=/opt/apache-tomcat-8.0.1.tar.gz

  • 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

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

I posted my playbook could please look an eye on it

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

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

still having the same issue after adding the pause

Yes, my suggestion is between the start tomcat and the wait_for

Yeah I tried and still not working

Is tomcat configured to listen on 8080 ? I notice you have a custom server.xml

are there errors in tomcat logs?

Did you ever manually check if that tomcat eventually starts?