Systemd – Avoid /usr/bin/env Being Marked in Systemd Logs

systemdsystemd-journaldtomcat

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.

Best Answer

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