0

I have a spring boot application that running on embedded tomcat with java -jar app.jar on a server away from my work office, and I haven't any ssh or other access to that server. So when I want to install and run newer version of application, I should go to the server place, physically connect to server and then install and run newer version.

Is there a way to run newer version of application without going to the server place? for example, upload newer jar file into my running application, and itself update it.

NOTE

I don't have any access to server and cannot use and run any continous delivery tools like jenkins or other, because of IP and port restrictions.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Rasool Ghafari
  • 4,128
  • 7
  • 44
  • 71
  • From what I understood the server does not accept any inbound connections. Can it call any outbound service then? – Jagger Aug 07 '19 at 12:01
  • @Jagger maybe can, do you know a way? – Rasool Ghafari Aug 07 '19 at 12:03
  • What about creating an app who has one endpoint, that accepts an upload. Make this upload be a JAR file, and have your app Runtime.exec() it. I would say it is not a really maintainable way of doing things, but it is doable. In short : make an app that can deploy an app. Whatever you do to achieve this, from a security point of view, this is also nightmar-ish. So you be warned :-) – GPI Aug 07 '19 at 12:05
  • @RasoolGhafari If the server can make an outbound connection for example to an SFTP server where you will store your jar file then write a script (`.bat`, `.sh` or whatever depending on the server's operating system) that will download the file and then redeploy the application with `java -jar your_app.jar`. You can use the hint from the forespeaker and run `Runtime.exec()` from a scheduled job in Spring Boot (`@Scheduled` annotation). Alternatively you can use some `SFTP` library in Java itself but then you would have the problem with stopping the application from itself. – Jagger Aug 07 '19 at 12:08
  • 1
    @Jagger if the app is accessible through HTTP (if it's a Tomcat enabled SpringBoot app, you bet it is), then you do not even have to make an outbound connection, just HTTP POST your JAR. The only limits may be : HTTP request limits from the firewall/proxy/server (but you can just slice your uploads if it is the case), and security policy restrictions (Runtime.exec() might be forbidden by the Java runtime administrator). – GPI Aug 07 '19 at 12:19
  • @GPI you are completely right. One could just upload the file over HTTP(S). – Jagger Aug 07 '19 at 12:21

2 Answers2

2

I did something like this a while back which worked out pretty well.

So you could create a super small app on the server(so small that it "never" needs to be updated) and have that monitor the versions and when a new version is available it could stop the real process and restart it with the new jar file.

I unfortunately don't have the code for that starter app, but it shouldn't take that long to write one that suits your needs

munHunger
  • 2,572
  • 5
  • 34
  • 63
1

Why don't you install a Tomcat to the server and use it's management GUI to deploy the newer version of the app? It is a very old fashion but works well. The only thing you will need to modify in your source code is to replace the packaging from jar to war in the pom.xml, so you can deploy it via Tomcat Manager. This how the manager GUI looks like: enter image description here

You can learn more about the Tomcat Manager here.

SaWo
  • 1,515
  • 2
  • 14
  • 32