Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I've created a systemd service to run a tomcat application based on the information found in this article. The short version of the article recommends avoiding the shell script wrappers, and executing java directly, with the appropriate environment and command line.

Here is the entirety of the systemd service (with the app name replaced):

[Unit]
Description=MyApp Tomcat Container

[Service]
EnvironmentFile=/opt/myapp/environment
ExecStart=/usr/bin/env ${JAVA_HOME}/bin/java $JAVA_OPTS $CATALINA_OPTS \
-classpath ${CLASSPATH} \
-Dcatalina.base=${CATALINA_BASE} \
-Dcatalina.home=${CATALINA_HOME} \
-Djava.endorsed.dirs=${JAVA_ENDORSED_DIRS} \
-Djava.io.tmpdir=${CATALINA_TMPDIR} \
-Djava.util.logging.config.file=${CATALINA_BASE}/conf/logging.properties \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
org.apache.catalina.startup.Bootstrap start

ExecStop=/usr/bin/env $JAVA_HOME/bin/java $JAVA_OPTS \
-classpath $CLASSPATH \
-Dcatalina.base=$CATALINA_BASE \
-Dcatalina.home=$CATALINA_HOME \
-Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS \
-Djava.io.tmpdir=$CATALINA_TMPDIR \
-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
org.apache.catalina.startup.Bootstrap stop

[Install]
WantedBy=multi-user.target

This works quite well as far as I know. The service starts, stops, and reports status correctly. The problem I'm having is with the logs as reported by journalctl:

# journalctl -u myapp.service --since today

Sep 14 00:26:00 myserver.domain.com env[654]: MyApp:2015-09-14 00:26:00: INFO Detail irrelevant
Sep 14 00:26:00 myserver.domain.com env[654]: MyApp:2015-09-14 00:26:00: INFO Detail irrelevant
Sep 14 00:26:17 myserver.domain.com env[654]: MyApp:2015-09-14 00:26:17: INFO Detail irrelevant

See here that env is being logged as the running executable. I would much rather see java as the executable, considering that's the program we actually care about. The env is noise. I've noticed quite a few different systemd service files that recommend prefixing the start command with /usr/bin/env, so I assumed I might be able to find some information about the logs produced. Apparently not.

Can I report the executable as java rather than env while using this same pattern of executing java directly (not the startup.sh wrappers)?

For extra points, I would love some hints and tips about what my service file might be missing. This is the first time I've written a systemd service, and am keen to learn more about best practises.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

The SyslogIdentifier directive allows you to set the name of the executable name in the logs.

SyslogIdentifier=java
# or my app name, but not both!
SyslogIdentifier=myapp
share|improve this answer
    
which version of systemd are you using? SyslogIdentifier works fine with defaults. – Evgeny Vereshchagin Oct 5 at 7:32
    
@EvgenyVereshchagin Output of systemd-cat --version is "systemd 208" and then a list of +MODULES. Is the 208 the version number? On RHEL 7 – Josh Smeaton Oct 5 at 23:59
1  
yes, 208 is the version number. I've checked a simple service with the version 208 (on CentOS Linux 7). Works fine. Try this. Does it work? – Evgeny Vereshchagin Oct 6 at 0:38
    
@EvgenyVereshchagin you're right, works fine. I'm fairly sure I forgot to daemon-reload when I was making these changes (because puppet does not trigger daemon-reload by default!!). Thanks for following this up, I'll modify my answer. – Josh Smeaton Oct 6 at 2:51
1  
yeah, daemon-reload is the problem:) There is an issue: RFE: systemd should reload changed unit files automatically – Evgeny Vereshchagin Oct 6 at 3:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.