len
len

Reputation: 404

Systemd: cannot start spring boot after added logback

I run my spring boot application using systemd service:

[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

It worked fine before I added the logback-spring.xml to generate the log file:

<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>

Now the service cannot start. "systemctl status -l myapp" doesn't show any useful hint:

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'.

But if I run the jar manually with command java -jar it has no problem to start & the logs folder is created in /var/springboot/online_ticket.

I also changed the logs folder owner with "chown java-webapp-daemon:java-webapp-daemon logs" but it doesn't help.

How to troubleshoot this issue?

Upvotes: 1

Views: 2485

Answers (1)

dfritsi
dfritsi

Reputation: 1232

In <property name="LOGS" value="./logs" /> the ./logs part is relative. Maybe the working directory when you launch it manually is different when launched as a service? I would try to replace ./logs with an absolute path just for testing. Also when you launch it manually do you launch it as a root user?

Upvotes: 0

Related Questions