Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1523112 - tomcat systemd does not cope with - in service names.
Summary: tomcat systemd does not cope with - in service names.
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: tomcat
Version: 7.7
Hardware: x86_64
OS: Linux
unspecified
low
Target Milestone: rc
: ---
Assignee: Coty Sutherland
QA Contact: tomcat-qe
URL:
Whiteboard:
Depends On:
Blocks: 1810269 1523248
TreeView+ depends on / blocked
 
Reported: 2017-12-07 09:26 UTC by Joe Madden
Modified: 2020-09-29 20:32 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1523248 (view as bug list)
Environment:
Last Closed: 2020-09-29 20:31:09 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2020:4004 0 None None None 2020-09-29 20:32:01 UTC

Description Joe Madden 2017-12-07 09:26:28 UTC
Description of problem:

Installing a service called ntis-adapter the - causes issues with systemd/tomcat start/stop where by it does not load the specific configuration in /etc/sysconfig/tomcat@ntis-adapter



Version-Release number of selected component (if applicable):

systemd-219-42.el7_4.4.x86_64
tomcat-7.0.76-3.el7_4.noarch

How reproducible:


Steps to Reproduce:
1. Create tomcat service with a - in the name using this RHEL soloution (https://access.redhat.com/solutions/2386441)

2. Attempt to start the service - Errors will occour as it will look in /var/lib/tomcats instead of looking at the correct CATALINA_BASE

3. Rename the service removing the - and rename the configuration in /etc/sysconfig

4. Start the service - It works and loads in the configuration values correctly

Actual results:

Dec 07 09:13:06 NECA-web-client server[20100]: Dec 07, 2017 9:13:06 AM org.apache.catalina.startup.Catalina load
Dec 07 09:13:06 NECA-web-client server[20100]: WARNING: Unable to load server configuration from [/var/lib/tomcats/ntis/adapter/conf/server.xml]
Dec 07 09:13:06 NECA-web-client server[20100]: Dec 07, 2017 9:13:06 AM org.apache.catalina.startup.Catalina load
Dec 07 09:13:06 NECA-web-client server[20100]: WARNING: Unable to load server configuration from [/var/lib/tomcats/ntis/adapter/conf/server.xml]
Dec 07 09:13:06 NECA-web-client server[20100]: Dec 07, 2017 9:13:06 AM org.apache.catalina.startup.Catalina start
Dec 07 09:13:06 NECA-web-client server[20100]: SEVERE: Cannot start server. Server instance is not configured.
Dec 07 09:13:06 NECA-web-client server[20131]: Java virtual machine used: /usr/lib/jvm/jre/bin/java
Dec 07 09:13:06 NECA-web-client server[20131]: classpath used: /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar
Dec 07 09:13:06 NECA-web-client server[20131]: main class used: org.apache.catalina.startup.Bootstrap
Dec 07 09:13:06 NECA-web-client server[20131]: flags used:
Dec 07 09:13:06 NECA-web-client server[20131]: options used: -Dcatalina.base=/var/lib/tomcats/ntis/adapter -Dcatalina.home=/usr/share/tomcat -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat/temp -Djava.util.logging.config.file=/usr/share/tomcat/conf/logging.prope
Dec 07 09:13:06 NECA-web-client server[20131]: arguments used: stop
Dec 07 09:13:07 NECA-web-client server[20131]: java.util.logging.ErrorManager: 4: Unable to create [/var/lib/tomcats/ntis/adapter/logs]
Dec 07 09:13:07 NECA-web-client server[20131]: java.util.logging.ErrorManager: 4: Unable to create [/var/lib/tomcats/ntis/adapter/logs]
Dec 07 09:13:07 NECA-web-client server[20131]: java.util.logging.ErrorManager: 4: Unable to create [/var/lib/tomcats/ntis/adapter/logs]
Dec 07 09:13:07 NECA-web-client server[20131]: java.util.logging.ErrorManager: 4: Unable to create [/var/lib/tomcats/ntis/adapter/logs]
Dec 07 09:13:07 NECA-web-client server[20131]: Dec 07, 2017 9:13:07 AM org.apache.catalina.startup.Catalina stopServer
Dec 07 09:13:07 NECA-web-client server[20131]: SEVERE: Catalina.stop:
Dec 07 09:13:07 NECA-web-client server[20131]: java.io.FileNotFoundException: /var/lib/tomcats/ntis/adapter/conf/server.xml (No such file or directory)
Dec 07 09:13:07 NECA-web-client server[20131]: at java.io.FileInputStream.open0(Native Method)
Dec 07 09:13:07 NECA-web-client server[20131]: at java.io.FileInputStream.open(FileInputStream.java:195)
Dec 07 09:13:07 NECA-web-client server[20131]: at java.io.FileInputStream.<init>(FileInputStream.java:138)
Dec 07 09:13:07 NECA-web-client server[20131]: at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:466)
Dec 07 09:13:07 NECA-web-client server[20131]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Dec 07 09:13:07 NECA-web-client server[20131]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Dec 07 09:13:07 NECA-web-client server[20131]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Dec 07 09:13:07 NECA-web-client server[20131]: at java.lang.reflect.Method.invoke(Method.java:498)
Dec 07 09:13:07 NECA-web-client server[20131]: at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:343)
Dec 07 09:13:07 NECA-web-client server[20131]: at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:430)
Dec 07 09:13:07 NECA-web-client systemd[1]: tomcat: control process exited, code=exited status=1
Dec 07 09:13:07 NECA-web-client systemd[1]: Unit tomcat entered failed state.
Dec 07 09:13:07 NECA-web-client systemd[1]: tomcat failed.


Expected results:
 (Configuration error in above setup - Complains about missing vairable (Reads the configuration file this time)

Dec 07 09:16:24 NECA-web-client polkitd[833]: Unregistered Authentication Agent for unix-process:20229:23509515 (system bus name :1.1357, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_GB.UTF-8) (disconnected from bus)
Dec 07 09:16:24 NECA-web-client server[20235]: Java virtual machine used: /usr/lib/jvm/jre-1.8.0/bin/java
Dec 07 09:16:24 NECA-web-client server[20235]: classpath used: /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar
Dec 07 09:16:24 NECA-web-client server[20235]: main class used: org.apache.catalina.startup.Bootstrap
Dec 07 09:16:24 NECA-web-client server[20235]: flags used: ${JAVA_OPTS} -Dspring.profiles.active=live,default -Duser.timezone=Europe/London -Dlog4j.configuration=file:${CATALINA_BASE}/conf/ntis-adapter/log4j.xml -server -Xms1024m -Xmx4096m -XX:MaxPermSize=1024m
Dec 07 09:16:24 NECA-web-client server[20235]: options used: -Dcatalina.base=/opt/mottMacDonald/adapters/ntis-adapter/active -Dcatalina.home=/usr/share/tomcat -Djava.endorsed.dirs= -Djava.io.tmpdir=${CATALINA_BASE}/temp -Djava.util.logging.config.file=/usr/share/tomcat/c
Dec 07 09:16:24 NECA-web-client server[20235]: arguments used: start
Dec 07 09:16:24 NECA-web-client server[20235]: Error: Could not find or load main class ${JAVA_OPTS}


Additional info:


/etc/sysconfig/tomcat@ntis-service

# Service-specific configuration file for tomcat. This will be sourced by
# the SysV init script after the global configuration file
# /etc/tomcat/tomcat.conf, thus allowing values to be overridden in
# a per-service manner.
#
# NEVER change the init script itself. To change values for all services make
# your changes in /etc/tomcat/tomcat.conf
#
# To change values for a specific service make your edits here.
# To create a new service create a link from /etc/init.d/<your new service> to
# /etc/init.d/tomcat (do not copy the init script) and make a copy of the
# /etc/sysconfig/tomcat file to /etc/sysconfig/<your new service> and change
# the property values so the two services won't conflict. Register the new
# service in the system as usual (see chkconfig and similars).
#

# Where your java installation lives
JAVA_HOME="/usr/lib/jvm/jre-1.8.0"

# Where your tomcat installation lives
CATALINA_HOME="/usr/share/tomcat"

# Where your tomcat installation lives
CATALINA_BASE="/opt/mottMacDonald/adapters/ntis-adapter/active"
CATALINA_TMPDIR="${CATALINA_BASE}/temp"
CATALINA_OPTS="-server -Xms1024m -Xmx4096m -XX:MaxPermSize=1024m"

#
#Java configuration options
#
JAVA_OPTS="${JAVA_OPTS} -Dspring.profiles.active=live,default -Duser.timezone=Europe/London -Dlog4j.configuration=file:${CATALINA_BASE}/conf/ntis-adapter/log4j.xml"

#
# Pid Location
#
CATALINA_PID="/var/run/ntis-adapter.pid"

#
# User Information
#
TOMCAT_USER="osprey"

#
# Security Manager defaulted to off
#
SECURITY_MANAGER="false"

Comment 2 Lukáš Nykrýn 2017-12-07 09:34:11 UTC
If I am not mistaken, we don't support variable expansion in environment files, so this:
JAVA_OPTS="${JAVA_OPTS} -Dspring.profiles.active=live,default -Duser.timezone=Europe/London -Dlog4j.configuration=file:${CATALINA_BASE}/conf/ntis-adapter/log4j.xml"
and
CATALINA_TMPDIR="${CATALINA_BASE}/temp"
can't work.

Comment 3 Joe Madden 2017-12-07 09:36:08 UTC
Yep - your correct. I've just fixed this in my config.

Please note this is not about my service not working, currently in the process of fixing it but it wouldn't load any of the virables while i had a dash in the service name.

Removed that and it is now loading CATALINA_BASE


Thanks

Comment 4 Lukáš Nykrýn 2017-12-07 11:28:47 UTC
Hmm, looks like there is a bug.

Minimal reproducer:
[root@qeos-13 system]# cat /etc/systemd/system/test@.service
[Service]
EnvironmentFile=/etc/sysconfig/test%I
Type=oneshot
ExecStart=/usr/bin/env
[root@qeos-13 system]# touch /etc/sysconfig/testa-a
[root@qeos-13 system]# systemctl start test
Job for test failed because a configured resource limit was exceeded. See "systemctl status test" and "journalctl -xe" for details.

The same problem seems to be also in upstream version of systemd (systemd-235-4.fc28.x86_64)

Comment 5 Lukáš Nykrýn 2017-12-07 13:33:41 UTC
Ok, so the problem is not in systemd, it behaves correctly, although the error message is terrible and I had to look into the code to see what is actually wrong. But anyway. https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers
"%i" - For instantiated units: this is the string between the "@" character and the suffix of the unit name.
"%I" - Same as "%i", but with escaping undone.

THis means that systemd will do unescaping which in this case means that instead of /etc/sysconfig/tomcat@ntis-adapter systemd is looking at /etc/sysconfig/tomcat@ntis/adapter

So in short: Tomcat needs to replace %I with %i in their unit file.

Comment 14 errata-xmlrpc 2020-09-29 20:31:09 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: tomcat security and bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:4004


Note You need to log in before you can comment on or make changes to this bug.