6

I know it is possible to create a jar from Spring Boot application which can be used as a systemd service. I used this manual to create systemd service from my application on Debian Jessie OS. Eveyrthing works fine, but I can't find a way how to write logs to separate file insted of /var/syslog. As documentation says:

Note that unlike when running as an init.d service, user that runs the application, PID file and console log file behave differently under systemd and must be configured using appropriate fields in ‘service’ script. Consult the service unit configuration man page for more details.

it should be configured in *.service file, but I can't find any appropriate options. Has someone any experience in this question?

DavyJohnes
  • 311
  • 1
  • 3
  • 12

1 Answers1

6

Run the service with a sh process

[Service]
ExecStart=/bin/sh -c "/var/myapp/myapp.jar >> /var/logs/myapp.log"
KillMode=control-group

See this discussion in influxdb github repo https://github.com/influxdata/influxdb/issues/4490

Issam El-atif
  • 2,366
  • 2
  • 17
  • 22
  • The correct command for me is `ExecStart=/bin/sh -c "java -jar /var/myapp/myapp.jar >> /var/logs/myapp.log"` – Winbert Dec 24 '20 at 14:29
  • 1
    This works great except we can't control log file rolling / retention with spring boot properties such as logging.logback.rollingpolicy.max-history. How do we keep that log file from growing out of control? – Ken Krueger Aug 05 '22 at 21:59
  • @KenKrueger I agree we can not benefit from logback rolling policy here. You can control log file size using systemd see https://superuser.com/a/1301058 – Issam El-atif Aug 15 '22 at 21:02