How to configure nicely Spring Boot application packaged as executable jar as a Service in linux system? Is this recommended approach, or should I convert this app to war and install into Tomcat?
Currently I can run Spring boot application from screen
session, what is nice, but requires manual start after server reboot.
What I'm looking for is general advice/direction or sample init.d
script, if my approach with executable jar is proper.
Are you using Maven? Then you should try the AppAssembler Plugin:
See: http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/index.html
In systemd unit files you can set environment variables directory or through an
EnvironmentFile
. I would propose doing things this way since it seems to be the least amount of friction.Sample unit file
Then setup a file under
/etc/sysconfig/hello-world
which includes uppercase names of your Spring Boot variables. For example, a variable calledserver.port
would follow the formSERVER_PORT
as an environment variable:The mechanism being exploited here is that Spring Boot applications will take the list of properties and then translate them, making everything uppercase, and replacing dots with underscores. Once the Spring Boot app goes through this process, it then looks for environment variables that match, and uses any found accordingly.
This is highlighted in more detail in this SO Q&A titled: How to set a Spring Boot property with an underscore in its name via Environment Variables?
References
I know this is an older question, but I wanted to present yet another way which is the appassembler-maven-plugin. Here's the relevant part from my POM that includes a lot of additional option values we found useful:
It can be done using Systemd service in Ubuntu
You can follow this link for more elaborated description and different ways to do so. http://www.baeldung.com/spring-boot-app-as-a-service