我使用systemd服务运行spring boot应用程序:
[Unit]
Description=Spring Boot 2333 application
After=syslog.target
[Service]
WorkingDirectory=/var/springboot/online_ticket
User=java-webapp-daemon
ExecStart=/usr/lib/jvm/java-11-openjdk-amd64/bin/java -jar myapp.utility-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
在我添加logback-spring.xml来生成日志文件之前,它工作得很好:
<property name="LOGS" value="./logs" />
<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/spring-boot-logger.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<MaxHistory>5</MaxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
现在服务无法启动。“systemctl status-l myapp“不显示任何有用的提示:
myapp.service - Spring Boot 2333 application
Loaded: loaded (/etc/systemd/system/myapp.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2020-02-13 15:33:02 +08; 1min 40s ago
Process: 21440 ExecStart=/usr/lib/jvm/java-11-openjdk-amd64/bin/java -jar myapp.utility-0.0.1-SNAPSHOT.jar (code=exited, status=1/FAILURE)
Main PID: 21440 (code=exited, status=1/FAILURE)
CPU: 2ms
Feb 13 15:33:02 filesrv1 systemd[1]: Started My Spring Boot 2333 application.
Feb 13 15:33:02 filesrv1 systemd[1]: myapp.service: Main process exited, code=exited, status=1/FAILURE
Feb 13 15:33:02 filesrv1 systemd[1]: myapp.service: Unit entered failed state.
Feb 13 15:33:02 filesrv1 systemd[1]: myapp.service: Failed with result 'exit-code'.
journalctl-u myapp.service(我的应用程序服务):
Feb 14 11:19:37 filesrv1 systemd[1]: Started My Spring Boot 2333 application.
Feb 14 11:19:37 filesrv1 systemd[1]: myapp.service: Main process exited, code=exited, status=1/FAILURE
Feb 14 11:19:37 filesrv1 systemd[1]: myapp.service: Unit entered failed state.
Feb 14 11:19:37 filesrv1 systemd[1]: myapp.service: Failed with result 'exit-code'.
~
~
ESCOC
08. --
code=exited, status=1/FAILURE
state.
exit-code'.
但是如果我用命令java-jar手动运行jar,那么启动就没有问题了&logs文件夹是在/var/springboot/online\u-ticket中创建的。
我还用“chownjavawebapp”更改了logs文件夹的所有者-daemon:java-webapp-daemon logs“但没用。
如何解决此问题?
1条答案
按热度按时间qlfbtfca1#
在
<property name="LOGS" value="./logs" />
这个./logs
部分是相对的。当您手动启动它时,工作目录可能与作为服务启动时不同?我会尝试替换./logs
绝对路径只是为了测试。另外,当您手动启动它时,是否作为根用户启动它?