[英]How to Extern log4j.properties file with Spring Boot Microservice and Run It As a Linux Service?
Have a Spring Boot (1.5.4.RELEASE) based microservice which I deploy a jar to an AWS EC Instance (Linux environment). 有一个基于Spring Boot(1.5.4.RELEASE)的微服务,我将jar部署到AWS EC实例(Linux环境)。 Now, I am also deploying an external log4j.properties file so I have to start the microservice like this:
现在,我还部署了一个外部log4j.properties文件,所以我必须像这样启动微服务:
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: 如何将此Spring Boot微服务配置为Linux服务,我可以使用这些标志启动和停止它:
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... 使用指向springboot应用程序的符号链接,您可以将其作为服务进行控制......
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. 将
application.properties
放入myapp文件夹,您可以覆盖应用程序中捆绑的应用程序。 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. 只需将日志配置的路径指定为其内部属性键
logging.config
值。
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.
一旦你在生产中运行了一大堆服务,你可能更愿意采用Spring cloud配置的内容来进行外部化配置,你可能还希望将日志聚合在一个集中的服务上,以便对所有服务进行概述。您的服务在一个地方登录。
As per spring-boot deployment , 根据spring-boot部署 ,
A fully executable jar can be executed like any other executable binary or it can be registered with
init.d
orsystemd
完全可执行的jar可以像任何其他可执行二进制文件一样执行,也可以使用
init.d
或systemd
注册
Make sure you build your app using the plug-in below (gradle version in shared link): 确保使用下面的插件构建应用程序(共享链接中的gradle版本):
<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: 并且如Jörg所示,在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. 更多问题,您需要自定义init,这可以通过
conf
文件完成 - 所有这些都在文档中指定。
With the exception of
JARFILE
andAPP_NAME
, the settings can be configured using a .conf file.除
JARFILE
和APP_NAME
,可以使用.conf文件配置设置。 The file is expected next to the jar file and have the same name but suffixed with .conf rather than .jar.该文件位于jar文件旁边,并且具有相同的名称,但后缀为.conf而不是.jar。 For example, a jar named /var/myapp/myapp.jar will use the configuration file named /var/myapp/myapp.conf.
例如,名为/var/myapp/myapp.jar的jar将使用名为/var/myapp/myapp.conf的配置文件。
such as: myapp.conf 例如: myapp.conf
JAVA_OPTS=-Xmx1024M
LOG_FOLDER=/custom/log/folder
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.