Using the cuba scheduler I created a groovy script that is able to detect if on cloud storage there is a new version of the application war, there are problems with Tomcat that does not correctly deploy the updated war because some jar result in use (windows environment), it seems that you need to stop tomcat then replace the war and start tomcat again … There is a better strategy for a kind of continuous update or deployement ?
Hi,
replacing the war itself is not that easy, when you only control the application within the tomcat (meaning the war).
There are multiple ways to achieve auto-update functionality of your application / parts of your application.
- CUBA has the configuration directory which allows to hot-deploy screen UIs, controller and business logic - but no entity changes). The admin-tools app component has the ability to pass in those files via the admin UI (see admin-tools - config loader). This process can even be enhances by a UI for the end user as I did with the import wizard for data-import (which is a similar use case).
- If you have a process outside of the tomcat available to run a regular update checker script, then it also once again becomes easier. E.g. you could have a script running in a docker container alongside with the tomcat process, that does the update-check and orchestration.
- If you know which parts you want to update, you could also take a look at the scripting facilities. E.g. this one here: GitHub - cuba-rnd/spring-script-repositories: Spring library for script execution repositories management
But this oftentimes only work in a non-HA environment, because perhaps you want to have more control on when the update happens, at which servers etc.
IMHO this is better handled by an external service/application, like the tomcat manager one.
In my personal experience, after having deployed 3 CUBA apps on Windows, the best way to update WARs is to leave the Tomcat service/contexts running, and just reload the applications deployed in it.
This can be accomplished in several ways, for example in a dev/test environment you could use the method explained here:
I quote the relevant part here:
Just add a reloadable=true attribute to the Context. Quoting the documentation:
Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications. That’s why the default setting for this attribute is false. You can use the Manager web application, however, to trigger reloads of deployed applications on demand.
Another method is to use the tomcat manager app, if it’s running on your tomcat setup, and it is explained here:
Ensure that you have user with “manager-script” role in your tomcat user database. That usually means that you have line like this in your ${TOMCAT}/conf/tomcat-users.xml :
<user username="admin" password="secret" roles="manager-gui,manager-script"/>
Otherwise, you will get a 403 error because of cross-site request forgery (CSRF) protection.
Use curl or whatever command line tool you like to fetch the URl /manager/text/reload?path=/<context_path>:
curl --user user:secret http://localhost:8080/manager/text/reload?path=/mypath
As you can see, you can call the manager endpoints in an external update script/application and do several things against the tomcat instance. But please ensure that the manager is only accessible from localhost, or it is otherwise secured from external access!
Finally, you could use the JMXProxy
Servlet (the one that the Manager app uses under the hood) to programmatically control Tomcat. This requires more effort, and it’s not so well documented, but you’ll find some directions in the following article:
The Pros and Cons of Using Tomcat JMX
There are even more advanced techniques, but I hope you got the point
PS: I’m thinking of developing a manager to deploy/update CUBA apps on Windows, and if I’ll succeed I’ll post an announcement here on the forum. I had so much troubles in deploying on Tomcat/Windows, that I think it deserves the time investment…
Paolo
UPDATE: Quoting @mario response, please be aware that things get way more complicated in a HA deployment. The first suggestion I can give, in that case, is… Look elsewhere, and stay away from Windows! No, seriously, you can succeed even on Windows, but you’ll need 3x the time and costs than using a container based architecture, for example.