java - 如何将自定义脚本链接到 spring boot jar?

标签 java linux spring-boot

我已经为 spring boot 可执行文件 jar 创建了一个符号链接(symbolic link),并且我能够启动该应用程序。我想自定义日志路径、pid 文件夹等。 通过自定义启动 this script .

但我找不到存储自定义脚本的位置以及如何将其链接到可执行应用程序 jar。你能帮忙吗?

最佳答案

创建一个名为 your-app.service 的脚本,将此脚本放在/etc/systemd/system 目录中。

作为 systemd 服务安装,使用 Java 系统属性(VM 参数):

[Unit]
Description= Spring Boot App
After=syslog.target

[Service]
User=myapp
ExecStart=java -Dspring.application.name=example -Dlogging.file=/opt/spring-boot-app/log/app.log -Dspring.pid.file=/opt/spring-boot-app/app.pid -jar /opt/spring-boot-app/app.jar
SuccessExitStatus=200

[Install]
WantedBy=multi-user.target

或者通过程序参数传递:

java -jar /opt/spring-boot-app/app.jar --spring.application.name=example --logging.file=/opt/spring-boot-app/log/app.log --spring.pid.file=/opt/spring-boot-app/app.pid

引用文献 herehere .

  • logging.file= # Log file name (for instance, myapp.log). Names can be an exact location or relative to the current directory.

  • spring.pid.file= # Location of the PID file to write (if ApplicationPidFileWriter is used).

关于java - 如何将自定义脚本链接到 spring boot jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53451348/

相关文章:

Java-交换数组列表索引

java - 让子类序列化为父类(super class)的实例?

c++ - 如何在 Linux 中做一个假的鼠标滚轮移动

javascript - 为什么我的图像不断覆盖自身而不是在 for 循环中显示每个图像?

java - @RequestHeader 不绑定(bind)在 POJO 中,但仅绑定(bind)在变量中

java - 无法使用java通过脚本执行maven命令

java - 具有继承和混合的 Scala 可测试代码

java - Jenkins 执行 Maven 时使用了错误的 Java 版本

linux - 变量 While 循环

java - 由于@OneToMany,JPA 更新记录失败