Reputation: 11
This is the error message i am facing
I had tomcat8 already installed. i removed that and then i tried installing tomcat8 again but facing this issue and i am not able to install tomcat again. List of Steps i followed before Installing -
sudo apt-get remove tomcat8
sudo apt-get remove --auto-remove tomcat8
sudo apt-get purge tomcat8
sudo apt-get purge --auto-remove tomcat8
Now i have installed new tomcat8 from here - https://websiteforstudents.com/setup-apache-tomcat-8-8-5-on-ubuntu-16-04-18-04-lts/
and getting error - image attached above
Upvotes: 1
Views: 16898
Reputation: 377
In my case using RHEL 8 system and i did below steps to fix the issue, then able to start tomcat service using systemctl.
Step 1: Validate any SELinux context related error in the audit search.
ausearch -m avc -ts recent
error reported unable to start service using systemctl due to SELinux context.
Step 2: Change SELinux SELinux contex for tomcat related files and directories
ls -lZ /etc/systemd/system/tomcat.service
chcon system_u:object_r:systemd_unit_file_t:s0 /etc/systemd/system/tomcat.service
chcon -Rv system_u:object_r:etc_runtime_t:s0 /opt/CAE/
semanage fcontext -a -t etc_runtime_t /opt/tomcat/bin/catalina.sh
semanage fcontext -a -t etc_runtime_t /opt/CAE/
Step 3: Define the systemctl file with below information's
$ sudo cat /etc/systemd/system/multi-user.target.wants/tomcat.service
[Unit]
Description=tomcat service
After=syslog.target network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/opt/CAE/CAESECURE_CMVQ1Z02_AS/java"
Environment="CATALINA_BASE=/opt/CAE/CAESECURE_CMVQ1Z02_AS/tomcat"
Environment="CATALINA_HOME=/opt/CAE/CAESECURE_CMVQ1Z02_AS/tomcat"
Environment="CATALINA_PID=/opt/tomcat/bin/tomcat.pid"
PIDFile="/opt/tomcat/bin/tomcat.pid"
ExecStart=/opt/tomcat/bin/catalina.sh start
ExecStop=/opt/tomcat/bin/catalina.sh stop
[Install]
WantedBy=multi-user.target
Step 4: Now start the service using systemctl
systemctl daemon-reload
systemctl start tomcat.service
systemctl restart tomcat.service
Validation: Now no SELinux error has been reported and able to start the service
ausearch -m avc -ts recent
systemctl status tomcat.service
no error reported
Upvotes: 0
Reputation: 16045
First of all, if you are using Debian or Ubuntu, using the tomcat8/tomcat9
packages (cf. packages.ubuntu.com) is the easiest way to run a Tomcat server.
In your case the tomcat.service
file lacks a PIDFile
option, which helps determining in a reliable way that Tomcat is running. Therefore I would modify your tomcat.service
script to contain:
[Service]
# ...
# The rest of the options
PIDFile="/run/tomcat.pid"
Environment="CATALINA_PID=/run/tomcat.pid"
Before starting the service make sure that your Tomcat is not running (killall java
or something more subtle) and remember to reload the SystemD daemon:
systemctl daemon-reload
Edit: After the modification the tomcat.service
file should look like this:
[Unit]
Description=Tomcat servlet container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/run/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
PIDFile="/run/tomcat.pid"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
Upvotes: 1