How do you remotely update Java applications?

前端 未结 9 1715
予麋鹿
予麋鹿 2021-01-30 17:30

We\'ve got a Java server application that runs on a number of computers, all connected to the Internet, some behind firewalls. We need to remotely update the JAR files and start

9条回答
  •  [愿得一人]
    2021-01-30 18:04

    It's very hard to make the update atomic, especially if you have any database updating to do.

    But, if you don't, what you can do is first make sure your application can run from a relative path. That is, you can put your app in some directory, and all of the important files are found relative to that location, so that that your actual installation location is not really important.

    Next, duplicate your installation. Now, you have the "running" version and you have the "new" version.

    Update the "new" version using whatever tech you like (FTP, rsync, paper tape, whatever floats your boat).

    Verify your installation (checksums, quick unit tests, whatever you need -- even start it up on a test port if you like).

    When you are happy with the new installation, down the original running instance, RENAME the original directory (mv application application_old), rename the NEW directory (mv application_new application), and start it back up.

    Your down time is reduced to server shut down and start up time (since rename is "free").

    If, by chance, you detect a critical error, you have your original version still there. Stop the new server, rename it back, restart the old. Very fast fall back.

    The other nice thing is that your service infrastructure is static (like your rc scripts, cron jobs, etc.) since they point to the "application" directory, and it doesn't change.

    It can also be done with soft links instead of renaming directories. either way is fine.

    But the technique is simple, and near bullet proof if your application cooperates.

    Now, if you have DB changes, well, that's completely different nasty issue. Ideally if you can make your DB changes "backward compatible", then hopefully the old application version can run on the new schema, but that's not always possible.

提交回复
热议问题