Reputation: 3030
I have a Spring Boot JAR on a linux server located at some directory /dev/ExampleApplication.jar
.
Is it possible for the Spring Boot application to monitor that specific JAR for an update (maybe a change in the checksum), and if there is an update, shut itself down, and start the updated JAR?
I want something like this in pseudo code:
@Scheduled(fixedDelay = 1000)
public void checkForUpdates() {
long fileChecksum = getJarChecksum();
if (checksum != fileChecksum) {
command("java -jar /dev/ExampleApplication.jar");
context.shutdown();
}
}
Upvotes: 1
Views: 1270
Reputation: 734
You could use inotify-tools to re-launch the jar file any time it is deleted or altered.
You'll need to install inotify-tools on your Linux distro if it is not already.
while inotifywait -e close_write /dev/ExampleApplication.jar; do java -jar /dev/ExampleApplication.jar; done
The -e parameter takes an event type. You can also watch a directory to see if anything is deleted or created in that directory. See here for more on the inotifywait event types: https://linux.die.net/man/1/inotifywait
Upvotes: 3