I’ve some micro services that I’ve been moving off commercial PaaS platforms to a Raspberry Pi on my home network. It’s been fun and worked out well, but I did lose one thing in the move, support for continuous delivery. Previously Travis-CI was able to deploy the services to the PaaS, but with the new setup I had to figure out a new solution.
Looking at the service, and seeing as it’s a single jar file, I felt I ought to be able to come out with a simple solution. I knew I could get the jar files onto the Pi, all I needed was some why to cleanly reload the service from the new jar.
A bit of searching turned up this older article on how to Programmatically Restart a Java Application. It was close to what I wanted, if I could just enhance it to behave like the update feature you often see in apps where it doesn’t just restart, but also updates the version.
Reloader is Born
Starting from the article mentioned, I developed reloader. Reloader will restart a java application, but additionally it can:
- Act as a signal handler, so that you can kick it off by sending a signal to the application, optionally creating a pid file.
- Find the newest version of the jar containing the application, and switch to that, allowing for pseudo in place upgrades.
In addition to adding features I brushed six years of dust off the code, and deployed the package to jcenter for easier public use.
Using reloader couldn’t be much simpler. It does pretty much everything on its own. All you need to do is call one method explicitly:
Or set it up as a signal handler:
That’s all it takes.
My Use Case
To achieve continuous delivery from Travis-CI I added two very restricted and hardened breaches in my Raspberry Pi’s security:
- A jar can be pushed to the server remotely
- The service can receive a USR2 signal remotely
I then set up Travis-CI to perform those two actions after any successful build. With reloader added to the service, those two actions were all that was needed.
By its nature reloader is a bit rough around the edges and while it has some test coverage I’ve really only burned it in for my use case. That said if you want to give it a try, or just look at its bits and pieces head over to github and go wild.