Tomcat 9 no longer starting using systemctl but will start manually

微笑、不失礼 提交于 2020-12-15 01:53:42

问题


Been digging on this for a while. I reviewed multiple articles on this issue. This one was the closest:

Tomcat 8 on CentOS 7 does not start as service (but it starts manually ....)

The difference being that I am running Tomcat 9.0.33. Here are the particulars:

java version "1.8.0_121"\
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)\
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)\

Tomcat 9.0.33

NAME="CentOS Linux"\
VERSION="7 (Core)"\
ID="centos"\
ID_LIKE="rhel fedora"\
VERSION_ID="7"\
PRETTY_NAME="CentOS Linux 7 (Core)"\
ANSI_COLOR="0;31"\
CPE_NAME="cpe:/o:centos:centos:7"\
HOME_URL="https://www.centos.org/"\
BUG_REPORT_URL="https://bugs.centos.org/"\

CENTOS_MANTISBT_PROJECT="CentOS-7"\
CENTOS_MANTISBT_PROJECT_VERSION="7"\
REDHAT_SUPPORT_PRODUCT="centos"\
REDHAT_SUPPORT_PRODUCT_VERSION="7"\

As a side note, everything was starting normally with no issues until recently. As far as I know there haven't been any major changes to the environment. But, when I ran the "systemctl restart" command recently, the startup began to fail. There are 5 instances of Tomcat 9.0.33 running at different ports and paths and those have not changed. I have not restarted two of the instance (afraid they won't start) the other three flat out won't start. Details below:

Systemd unit file for tomcat\
[Unit]\
Description=Apache Tomcat Web Application Container in Liferay 7.32 TEST for UAT\
After=syslog.target network.target

[Service]\
Type=forking

Environment=JAVA_HOME=/opt/jdk1.8.0_121/jre\
Environment=CATALINA_PID=/opt/liferay/uatapi/liferay-ce-portal-7.3.2-ga3/tomcat-9.0.33/temp/tomcat.pid\
Environment=CATALINA_HOME=/opt/liferay/uatapi/liferay-ce-portal-7.3.2-ga3/tomcat-9.0.33\
Environment=CATALINA_BASE=/opt/liferay/uatapi/liferay-ce-portal-7.3.2-ga3/tomcat-9.0.33\
Environment='CATALINA_OPTS=-Xms1024m -Xmx2048m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:SurvivorRatio=20 -XX:ParallelGCThreads=8 -server -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n'\
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Duser.timezone=GMT -Dfile.encoding=UTF-8'

ExecStart=/opt/liferay/uatapi/liferay-ce-portal-7.3.2-ga3/tomcat-9.0.33/bin/startup.sh\
ExecStop=/bin/kill -15 $MAINPID

User=tomcat\
Group=tomcat\
UMask=0007

[Install]\
WantedBy=multi-user.target\

Results when running systemctl start liferayuat

● liferayuat.service - Apache Tomcat Web Application Container in Liferay 7.32 TEST for UAT\
   Loaded: loaded (/etc/systemd/system/liferayuat.service; enabled; vendor preset: disabled)\
   Active: failed (Result: exit-code) since Sat 2020-12-05 08:44:08 CST; 3s ago\
  Process: 10891 ExecStop=/bin/kill -15 $MAINPID (code=exited, status=1/FAILURE)\
  Process: 10851 ExecStart=/opt/liferay/uatapi/liferay-ce-portal-7.3.2-ga3/tomcat-9.0.33/bin/startup.sh \(code=exited, status=0/SUCCESS)\
 Main PID: 10861 (code=exited, status=0/SUCCESS)

Dec 05 08:44:08  systemd[1]: Starting Apache Tomcat Web Application Container in Liferay 7.32 TEST for UAT...\
Dec 05 08:44:08  startup.sh[10851]: Existing PID file found during start.\
Dec 05 08:44:08  startup.sh[10851]: Removing/clearing stale PID file.\
Dec 05 08:44:08  startup.sh[10851]: Tomcat started.\
Dec 05 08:44:08  systemd[1]: Started Apache Tomcat Web Application Container in Liferay 7.32 TEST for UAT.\
Dec 05 08:44:08  systemd[1]: liferayuat.service: control process exited, code=exited status=1\
Dec 05 08:44:08  systemd[1]: Unit liferayuat.service entered failed state.\
Dec 05 08:44:08  systemd[1]: liferayuat.service failed.

Then the ONLY thing in catalina.out:

Listening for transport dt_socket at address: 5000\
java.lang.ClassNotFoundException: org.apache.catalina.startup.Catalina\
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)\
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)\
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)\
        at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:261)\
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:443)\

So, when I start the instance with systemctl start it will fail. But if I run this command (as root...) then it will start:

/opt/liferay/uatapi/liferay-ce-portal-7.3.2-ga3/tomcat-9.0.33/bin/startup.sh

If I run that full commmand AS tomcat it doesn't start with the same error. So, it appears that the issue is permissions. The tomcat user and group are owners of all files and folders. But, somehow, the tomcat user either doesn't have permissions or the path gets jacked up so that the class files can't be found. I followed the suggestions in the article I referenced above but the changes had no impact.

I tripped across one article on SELINX that seemed to point to an issue there. This are the SELINUX settings:

SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31\

The workaround to keep the instances running is just to manually start them but what is causing systemctl start NOT to work? I suspect permissions but I sure as heck can't see why since everything is owned by tomcat:tomcat


回答1:


So, this is self-inflicted as most "mysteries" are. I still cannot account for some of the differences I see when looking into SELinux contexts between the instances but the REAL cause was subtle (to me). Permissions on the {tomcat root}/lib and {tomcat root}/lib/ext had no execute permissions. That may have been due to a jar that was added recently and then needed to be updated by owner and permissions. In any case, the original issue resulted in many trial and error attempts to fix it which complicated matters further.

I discovered the solution by doing a folder by folder, file by file comparison between working and non-working instances. Apparently the new jar and the owner/permission changes were applied to all but the production version.

Thanks for the suggestions.



来源:https://stackoverflow.com/questions/65160505/tomcat-9-no-longer-starting-using-systemctl-but-will-start-manually

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!