Uploaded image for project: 'JBoss Web Server'
  1. JBoss Web Server
  2. JWS-864

tomcat systemd does not cope with - in service names.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • JWS 5.0_RHEL DR1
    • None
    • rpm, tomcat
    • None

      +++ This bug was initially created as a clone of Bug #1523112 +++

      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@ntis-adapter.service: control process exited, code=exited status=1
      Dec 07 09:13:07 NECA-web-client systemd[1]: Unit tomcat@ntis-adapter.service entered failed state.
      Dec 07 09:13:07 NECA-web-client systemd[1]: tomcat@ntis-adapter.service 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"
      

      — Additional comment from Lukáš Nykrýn on 2017-12-07 04:34:11 EST —

      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.

      — Additional comment from Joe Madden on 2017-12-07 04:36:08 EST —

      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

      — Additional comment from Lukáš Nykrýn on 2017-12-07 06:28:47 EST —

      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@a-a.service
      Job for test@a-a.service failed because a configured resource limit was exceeded. See "systemctl status test@a-a.service" and "journalctl -xe" for details.
      

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

      — Additional comment from Lukáš Nykrýn on 2017-12-07 08:33:41 EST —

      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.

              rhn-support-csutherl Coty Sutherland
              rhn-support-csutherl Coty Sutherland
              Jan Onderka Jan Onderka
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: