Docker execute ant script after tomcat starts?

陌路散爱 提交于 2021-02-11 08:56:10

问题


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.


回答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.




回答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)


来源:https://stackoverflow.com/questions/37437658/docker-execute-ant-script-after-tomcat-starts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!