4

Do you know how to force WebSphere Liberty to start WARs (deployed separetly or within single EAR file) in given order. By default WLP is starting it in parallel and there is no information how to tweak it up.

I know that in full WebSphere Application server there was/is such option to define starting weight in deployment.xml but in WLP it seems to be missing.

Thomas Bitonti
  • 1,179
  • 7
  • 14
e1m7bo
  • 53
  • 4
  • 1
    similar question to https://stackoverflow.com/questions/48253233/openliberty-order-web-app-activation – Andy Guibert Apr 24 '19 at 16:12
  • 1
    Out of the box, no, there is not a way to enforce app start ordering. However, there are ways this can be accomplished by deployment scripting. Could you describe the use case a bit more? I suspect there is a better alternative design which won't require apps to come up in a certain order. – Andy Guibert Apr 24 '19 at 16:12
  • I have two applications working on the same database. One application is loading some data on the startup and second one is assuming that this data is already available on DB - it is kind of functional requirement of customer for which I'm preparing deployment. – e1m7bo Apr 24 '19 at 16:23
  • I was already thinking about preparing such starting script that it copy given WAR into WLP's 'apps' folder, waiting for startup and when it is started copying second application and repeat the procedure. But it is not performing well (have to extract WAR every time serer is started). I was also thinking about MBeans - perhaps there is some API for starting application which have "autoStart" set to 'false' in server.xml. But non of this solution are clear and simple, unfortunately. – e1m7bo Apr 24 '19 at 16:23
  • Perhaps you should modify the 2nd app to not assume the data is ready and handle the possibility it will need to wait for it? It seems that even if you could make app2 wait for app1 startup, a slow query or database access problem in app1 would still cause app2 to fail – F Rowe Apr 24 '19 at 16:47
  • @FRowe As I've already written above: this is customer requirement and additionally one app is not written by me so I cannot easily change it. I just need to start those apps in that order. – e1m7bo Apr 24 '19 at 17:12

2 Answers2

3

This is now possible in Liberty as of version 20.0.0.4 (though it will be in beta until at least 20.0.0.6).

To start "app1" before "app2", you would specify the "startAfter" attribute on "app2".

<application id="app1" location="start_me_first.war"/>
<application id="app2" location="start_me_later.war" startAfter="app1"/>

The startAfter attribute takes a list of application IDs, so you can specify more than one application that must be started before that application can start.

Brent Daniel
  • 355
  • 1
  • 4
2

At the moment, there is no out-of-the-box way to control application start order in Liberty.

A few alternate options may be:

1) Use 1 app per server

Split apart the server so you only have 1 app per server, then use a container orchestration layer to mandate an ordering at the server level.

2) Use dropins + shell script

Use the ${server.config.dir}/dropins/ folder and move applications into that folder in a controlled order using scripting. For example:

mv firstApp.war /path/to/server/dropins/
# wait some amount of time as a heuristic
sleep 5
mv nextApp.war /path/to/server/dropins/

3) Use autoStart=false and start with ApplicationMBean

If you set <application autoStart="false"> on your applications, you can control the start ordering by invoking ApplicationMBean.start() via JMX. See the ApplicationMBean doc as well as Working with JMX MBeans on Liberty.


This request has come up a few times though, so we've opened this github issue to discuss a built-in solution.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
  • Do you know if it is possible to achieve something using MBeans provided by WLP, e.g. [com.ibm.websphere.webcontainer.WebModuleMBean](https://www.ibm.com/support/knowledgecenter/en/SS7K4U_liberty/com.ibm.websphere.wlp.zseries.doc/ae/rwlp_mbeans_list.html#rwlp_mbeans_list__WebModuleMBean) ? – e1m7bo Apr 24 '19 at 21:10
  • 1
    yes, you could also use JMX, although you'd want to use the ApplicationMBean instead of the WebModuleMBean. I've updated my answer to include a 3rd option – Andy Guibert Apr 24 '19 at 22:06
  • It is more or less the same what I was already planned to do (see my previous comment). But thanks for confirmation that it is not possible doing different way. BTW You created issue for OpenLiberty. Does it mean that it will be also considered for IBM Websphere Liberty? – e1m7bo Apr 25 '19 at 06:58
  • yes, because OpenLiberty is a subset of IBM WebSphere Liberty. Here is a q/a that clarifies further: https://stackoverflow.com/questions/46306036/what-is-the-difference-between-openliberty-and-websphere-liberty – Andy Guibert Apr 25 '19 at 13:09