1

Dockerfile works correctly for tomcat. After tomcat starts, I have to trigger ant scripts. catalina.sh is started from a separate run.sh file. So, Dockerfile has CMD ["/tmp/run.sh"]

The run.sh file has below lines:

  • catalina.sh run
  • antscript

Tomcat starts but ant scripts are not called. I also tried other possibilities like:

  • catalina.sh run && antscripts

tomcat starts but antscripts are not triggered

Is there a way that I can call the ant scripts automatically after tomcat starts? I dont want to run the scripts afterwards by using docker exec.

sandy
  • 25
  • 8
  • The reason your antscript does not executed is because you catalina.sh never completes. With docker the tomcat process is in foreground and antscript is not executed. – Shibashis May 25 '16 at 13:08
  • One of the ways, I can think of achieving the functionality is by starting antscripts with nohup command before catalina.sh, and add a delay in antscript (use a wrapper shell script with sleep command). The delay can be simple time based wait, or could just watch tomcat logs till server startup is complete to start execution. – Shibashis May 25 '16 at 13:10
  • using nohup command to run a wrapper script worked for me. Thanks – sandy May 26 '16 at 11:52
  • cool. I am making it an answer then. – Shibashis May 26 '16 at 12:18

2 Answers2

2

You can write you commands next way:

catalina.sh run & (sleep 20 && antscripts)

It will call antscripts in 20 seconds after catalina execution start. You can change time for estimated time of tomcat start.

Also you can wait for open some tcp port:

catalina.sh run & ((while ! echo exit | nc localhost 8080; do sleep 10; done) && antscripts)
Cortwave
  • 4,747
  • 2
  • 25
  • 42
  • Thank you for the idea of using & after catalina.sh run. I can trigger a script that would wait for tomcat to start and then execute the antscripts. – sandy May 30 '16 at 09:43
  • 1
    However, the problem is that the docker container exits after the script ends. – sandy May 31 '16 at 11:11
1

One of the ways, I can think of achieving the functionality is

  • Starting antscripts with nohup command before catalina.sh,
  • and adding a delay in antscript (use a wrapper shell script with sleep command).

The delay can be simple time based wait, or could just watch tomcat logs till server startup is complete to start execution.

Shibashis
  • 8,023
  • 3
  • 27
  • 38