Smooth redeployment of WAR in production?
Asked Answered
U

6

11

I was wondering if there is a 'smooth way' of redeploying a Java WAR to a production server (no cluster, no OSGi)?

All I can come up with is stop server, update file, restart server. And 10 minutes beforehand I need to display a maintenance warning on the site.

What's your approach?

Unholy answered 31/5, 2010 at 14:59 Comment(3)
why stop server, update file, restart server and not just undeploy/deploy? We've got several .war webapps on our production servers and typically only undeploy/redeploy: no need to take the whole server with all the webapps down!?Popup
@nooz: well, I only run 1 app on the server. I wasn't able to find any tutorials/guides on doing re-deploy with Jetty, all I find is how to do this for rapid developmentUnholy
oh I see... I don't know about Jetty (maybe other will comment). But with Tomcat there are several ways to undeploy/redeploy a single .war (I used to do it from an Ant task but now I'm using the manager app). This saves the time needed to shutdown/restart Tomcat.Popup
E
8

First, hot-deploy doesn't always work. We spent so much time to make sure every new module is loaded and decided it's not worth the trouble. So what you are doing may sound bad but it's the most reliable way to deploy a new WAR.

Our current approach is to use a switch with load-balancer in front of all servers. We run at least 2 instances of the application servers. When we shutdown one server for maintenance, the traffic automatically goes to the other one.

Some of the switches are really inexpensive. If you don't have enough load to justify a new box and your 2 instances can run on the same box.

In some circumstances, the switches can actually save money. For example, we have a SSL page that used to use 6 boxes and now it runs fine on 2 boxes with SSL acceleration in the switch.

Eugenle answered 31/5, 2010 at 15:38 Comment(2)
sounds very clever - yet I'm wondering: How do you handle state? When you take one down, all the state must obviously be available on another resource (DB, cache, 2nd app?). And secondly how well does that work out? -based on my humble java framework experiences (jsf, seam, wicket) I'd expect you'd have to jump quite a few hoops when not using 'sticky sessions' in a cluster.Unholy
Good question. Stateless server has be a requirement here for so long that I take it for granted. If you have state in the server, you have to do some trick in load-balancer, like sticky routing based on source IP or cookies.Eugenle
I
1

You might have a look at JRebel, though I wouldn't use it in production. In production we do basically the same, though our boss keeps on dreaming of hot redeploys. Unfortunately they are supported mostly on paper - in most complex applications something always goes wrong with hot redeploys. The same is even truer for incremental hot redeploys...

Indecipherable answered 31/5, 2010 at 15:1 Comment(0)
A
1

Some application servers do support redeployment without interruption of service. This is at least true for WebLogic, see Using Production Redeployment to Update Applications. Note that this is not hot deploy (and I would NEVER use hot deploy with production servers).

Without application server support, I'm afraid you won't be able to do real "smooth" redeployments. If you want to minimize downtime, one approach is to deploy the new application in parallel (on the same server or another one) and to change the routing rules when done. But clients will loose their session.

Armillas answered 31/5, 2010 at 15:51 Comment(0)
A
1

Usually it's possible to optimize start-up time. Our web application starts with Jetty in 5-7 seconds. Other Java web servers are worse, because they start very slow.

Also, as I'm aware (not I did it), the front-end web server (such as apache, we use lighttpd) could be configured to hold request some period of time (up to 30 seconds on ours) while the Jetty is not ready. So, we just easily restart the Jetty while deploying, and users just have several seconds delay in worst case, which usually just looks like an Internet connection glitch.

Archaean answered 3/9, 2010 at 7:51 Comment(0)
I
0

Usually, mv old.war new.war and let the AS take it from there, although with very busy 24/7 services, I imagine this wouldn't be an option.

Illumination answered 31/5, 2010 at 15:27 Comment(2)
hm, I tried this once with Jetty, maybe I did sth. wrong, but nothing happened after few minutes; probably each AS handles it differently. On which AS did you actually do this?Unholy
It's configurable: you can make Tomcat and JBoss work that way. I'd be surprised to learn Jetty doesn't allow you to set it up in a similar way. Just as a matter of terminology, Tomcat and Jetty are servlet containers, JBoss (and Glassfish, JOnAS, etc.) are application severs.Illumination
N
0

As ZZ Coder has already mentioned load balancer is a good solution especially for big deployments. For my own project I use reverse http proxy functionality of nginx web server. It redirects all http packets from a specified web context (seen from the Internet) to a server inside my network. Configuration is really easy:

location /best-app-ever/ { proxy_pass host-address:8080/some-app-1.1 root /home/www/some-app-1.1 }

Switching version should be smooth as well. Assuming that you have already deployed new version of application just change nginx configuration file and apply changes:

location /best-app-ever/ { proxy_pass host-address:8080/some-app-1.2 root /home/www/some-app-1.2 }

sudo nginx -t
sudo service nginx restart

Be warned that in case your web application is stateful and/or contains some running or scheduled processes, the deployment and undeployment might not be as smooth.

Nanoid answered 30/7, 2014 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.