5

I am running java apps via systemd:

[Unit]
Description=test service

[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/testserver
WorkingDirectory=/opt/testserver
ExecStart=/usr/bin/java -jar /opt/testserver/test.jar
StandardOutput=syslog
StandardError=syslog
User=testserver
Group=testserver
SyslogIdentifier=testserver

[Install]
WantedBy=multi-user.target

I want to get stdout in /opt/testserver/stdout.log and stderr in /opt/testserver/stderr.log - any working options are acceptable (i.e. if possible to do through syslog). If possible I want to avoid logging at least one of these in journald log.

Thanks...

GioMac
  • 4,544
  • 4
  • 27
  • 41
  • Given that the journal data flow is a "all roads lead to Rome" kind of deal, I'm curious as to how this plays out. – Avery Payne Oct 02 '14 at 18:11
  • So far, only through rsyslog, which is a additional overhead and very hard to manage even with "syslogidentifier". – GioMac Oct 05 '14 at 20:23
  • I've been working with the "other camp" (supervise/runit/s6), which has an entirely different take on logging. So, yeah, finding out how you deal with this + journal + whatever duct tape is needed is very much a curiosity for me. If you do get it working as intended, definitely post your answer, along with the *why* of it, so others can understand. – Avery Payne Oct 08 '14 at 18:31
  • 1
    @GioMac I was trying to do similar task: make stderr and stdout different log level records. Unit files do not allow specifying different default log levels per stdout and stderr, but you may use prefixes like "<1>", "<2>" etc. on every output line to define log level as specified in man page for [sd-daemon](http://faqbay.com/man/7/sd-daemon). This way I was able to have different log levels (and via syslog you shall be able targeting them into different files). – Jan Vlcinsky May 08 '15 at 20:58
  • @JanVlcinsky, yep, that's good when you've got new type of daemon – GioMac May 10 '15 at 07:19

1 Answers1

1

I'm trying the following for Logstash to replace its init.d script. Basically, wrapping it with bash to provide stdout and stderr redirection. Not sure if this is quite what you want, or would want to use (it's not too hideous, but clearly not how systemd wants you to do it), but I needed something to make it start after Elasticsearch, and I didn't want my team to notice anything different about where the log files ended up, so hopefully this will tide me over until they provide one of their own:

[Unit]
Description=Logstash
After=elasticsearch.service
Requires=elasticsearch.service

[Service]
Type=simple
User=logstash
Group=logstash
ExecStart=/bin/bash -c 'exec /opt/logstash/bin/logstash agent \
    -f /etc/logstash/conf.d \
    -l /var/log/logstash/logstash.log \
    >/var/log/logstash/logstash.stdout \
    2>/var/log/logstash/logstash.err'
WorkingDirectory=/var/lib/logstash
LimitNICE=19
LimitNOFILE=16384
Restart=always

[Install]
WantedBy=multi-user.target 

Edit: I just realized I could create /etc/systemd/system/logstash.service.d/after-es.conf as follows and not have to rewrite their init.d script:

[Unit]
After=elasticsearch.service
Requires=elasticsearch.service

Oh well, leaving the above in case it's useful.

Steve Kehlet
  • 1,105
  • 1
  • 10
  • 16