Have a Spring Boot (1.5.4.RELEASE) based microservice which I deploy a jar to an AWS EC Instance (Linux environment). Now, I am also deploying an external log4j.properties file so I have to start the microservice like this:
java -jar myapp.jar -Dlogging.config=/path/to/log4j.properties
How can I configure this Spring Boot Microservice as a Linux service where I can start and stop it using these flags:
sudo service myapp start | stop | status | restart
Thank you very much.
Using a symbolic link to your springboot app you can make it controllable as service...
sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp
Placing an application.properties
into your myapp folder you can override the one bundled inside your app. This way you don't need to use command line switches. Simply specify the path to your log configuration as value to property key logging.config
inside of it.
NOTE, though, that this solution is not really best practice. Once you're running a whole bunch of services in production, you probably rather want to go for something along the lines of spring cloud config for externalizing configuration and you probably also want your logs aggregated at a centralized service that allows for an overview of all your services' logs in one place.
As per spring-boot deployment,
A fully executable jar can be executed like any other executable binary or it can be registered with
init.d
orsystemd
Make sure you build your app using the plug-in below (gradle version in shared link):
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
and as shown by Jörg, create a symbolic link inside init.d:
sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp
That is the simplified version :)
More to your question, you need to customize the init and this can be done by a conf
file - all specified in the documentation.
With the exception of
JARFILE
andAPP_NAME
, the settings can be configured using a .conf file. The file is expected next to the jar file and have the same name but suffixed with .conf rather than .jar. For example, a jar named /var/myapp/myapp.jar will use the configuration file named /var/myapp/myapp.conf.
such as: myapp.conf
JAVA_OPTS=-Xmx1024M
LOG_FOLDER=/custom/log/folder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With