I am facing a problem which I could not figure out:
Scenario:
When a new instance powers up on the morning (Autoscaling), it starts with tomcat on a failed state, to solve this issue I just connect to the instancia via SSH and execute:
systemctl restart tomcat This solves the issue but I would like to find the root cause on why Tomcat9 is failing to start when the instance is powered on by the first time
Looking thru the logs, I find that when Tomcat9 is restarted, It appears as this:
[root#ip-172-31-177-124 bin]# systemctl status tomcat
● tomcat.service - Apache Tomcat
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-10-05 09:06:09 CEST; 2h 36min ago
Process: 3626 ExecStop=/usr/local/apache-tomcat/bin/shutdown.sh (code=exited, status=1/FAILURE)
Process: 3735 ExecStart=/usr/local/apache-tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 3742 (java)
CGroup: /system.slice/tomcat.service
└─3742 /usr/lib/jvm/java-1.8.0-openjdk/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat/conf/logging.properties -Djava.util.log...
Oct 05 09:06:09 ip-172-31-177-124.eu-west-1.compute.internal systemd[1]: Starting Apache Tomcat...
Oct 05 09:06:09 ip-172-31-177-124.eu-west-1.compute.internal startup.sh[3735]: /usr/local/apache-tomcat/bin/catalina.sh: line 514: /run/tomcat9.pid: P...enied
Oct 05 09:06:09 ip-172-31-177-124.eu-west-1.compute.internal startup.sh[3735]: Tomcat started.
Oct 05 09:06:09 ip-172-31-177-124.eu-west-1.compute.internal systemd[1]: Started Apache Tomcat.
Here are the journalctl -xe logs when Tomcat is restarted manually:
-- Unit tomcat.service has begun shutting down.
sep 17 20:00:37 ip-172-31-177-144.eu-west-1.compute.internal shutdown.sh[5311]: $CATALINA_PID was set but the specified file does not exist. Is Tomcat running?
sep 17 20:00:37 ip-172-31-177-144.eu-west-1.compute.internal systemd[1]: tomcat.service: control process exited, code=exited status=1
sep 17 20:00:37 ip-172-31-177-144.eu-west-1.compute.internal systemd[1]: tomcat.service: main process exited, code=exited, status=143/n/a
sep 17 20:00:37 ip-172-31-177-144.eu-west-1.compute.internal systemd[1]: Unit tomcat.service entered failed state.
sep 17 20:00:37 ip-172-31-177-144.eu-west-1.compute.internal systemd[1]: tomcat.service failed.
sep 17 20:00:37 ip-172-31-177-144.eu-west-1.compute.internal systemd[1]: Starting Apache Tomcat...
-- Subject: Unit tomcat.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has begun starting up.
sep 17 20:00:37 ip-172-31-177-144.eu-west-1.compute.internal startup.sh[5322]: /usr/local/apache-tomcat/bin/catalina.sh: line 514: /run/tomcat9.pid: Permission
sep 17 20:00:37 ip-172-31-177-144.eu-west-1.compute.internal startup.sh[5322]: Tomcat started.
sep 17 20:00:37 ip-172-31-177-144.eu-west-1.compute.internal systemd[1]: Started Apache Tomcat.
Does anybody know what is going on here?
EDIT: Catalina/Java Logs when crash occours:
2021-10-01 08:03:03,628 ERROR org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler [scheduling-1]Unexpected error occurred in scheduled task.java.lang.ExceptionInInitializerError: null at javax.crypto.JceSecurityManager.<clinit>(JceSecurityManager.java:65) at javax.crypto.Cipher.getConfiguredPermission(Cipher.java:2590) at javax.crypto.Cipher.getMaxAllowedKeyLength(Cipher.java:2614) at sun.security.ssl.CipherSuite$BulkCipher.isUnlimited(CipherSuite.java:535) at sun.security.ssl.CipherSuite$BulkCipher.<init>(CipherSuite.java:507) at sun.security.ssl.CipherSuite.<clinit>(CipherSuite.java:614) at sun.security.ssl.SSLContextImpl.getApplicableSupportedCipherSuiteList(SSLContextImpl.java:294) at sun.security.ssl.SSLContextImpl.access$100(SSLContextImpl.java:42) at sun.security.ssl.SSLContextImpl$AbstractTLSContext.<clinit>(SSLContextImpl.java:529) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at java.security.Provider$Service.getImplClass(Provider.java:1634) at java.security.Provider$Service.newInstance(Provider.java:1592) at sun.security.jca.GetInstance.getInstance(GetInstance.java:236) at sun.security.jca.GetInstance.getInstance(GetInstance.java:164) at javax.net.ssl.SSLContext.getInstance(SSLContext.java:156) at javax.net.ssl.SSLContext.getDefault(SSLContext.java:96) at javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:122) at
Java version:
# java -version
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)
I have created a GUI Javafx app and exported it to a jar file. The GUI app is working fine. After creating this app i have moved it to linux system and it is working fine here. Now i want to run this GUI app in linux using services so that i can make this service run at start of linux system.
For that I have created a pointless.sh file which on run runs the jar file. It is working perfectly the code for this pointless.sh file are
java -jar GUI1.jar
on Runinng this script i.e. "./pointless" the GUI is shown on the screen.
Problem starts when i try to make a service for it.
I made a service for it in /etc/systemd/system pointless.service
[Service]
ExecStart=/home/mandeep/Documents/pointless.sh
on running sudo systemctl start pointless.service nothing happens and the status shows following errors.
● pointless.service
Loaded: loaded (/etc/systemd/system/pointless.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2019-07-06 13:44:00 EDT; 25min ago
Process: 1449 ExecStart=/home/mandeep/Documents/pointless.sh (code=exited, status=203/EXEC)
Main PID: 1449 (code=exited, status=203/EXEC)
Jul 06 13:44:00 debian systemd[1]: Started pointless.service.
Jul 06 13:44:00 debian systemd[1449]: pointless.service: Failed at step EXEC spawning /home/mandeep/Documents/pointless.sh: Exec format error
Jul 06 13:44:00 debian systemd[1]: pointless.service: Main process exited, code=exited, status=203/EXEC
Jul 06 13:44:00 debian systemd[1]: pointless.service: Unit entered failed state.
Jul 06 13:44:00 debian systemd[1]: pointless.service: Failed with result 'exit-code'.
Update !!!
Step 1
As expected I created a simple Java app helloworld and exported it to jar file. I ran this file as java -jar helloworld and It worked.
Step 2
I created a simple service for it and service also worked as expected.
the service codes are
[Service]
ExecStart=/usr/bin/java -jar /home/mandeep/Documents/helloworld.jar
Output
Jul 07 17:08:13 debian systemd[1]: Started pointless.service.
Jul 07 17:08:13 debian java[2765]: Hello World!
Step 3
I Updated service back to GUI1.jar to check original problem posted.
code
[Service]
ExecStart=/usr/bin/java -jar /home/mandeep/Documents/GUI1.jar
and again it shows the error
Output
● pointless.service
Loaded: loaded (/etc/systemd/system/pointless.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2019-07-07 17:14:37 EDT; 4s ago
Process: 2816 ExecStart=/usr/bin/java -jar /home/mandeep/Documents/GUI1.jar (code=exited, status=1/FAILURE)
Main PID: 2816 (code=exited, status=1/FAILURE)
Jul 07 17:14:37 debian java[2816]: at com.sun.glass.ui.Application.run(Application.java:146)
Jul 07 17:14:37 debian java[2816]: at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:257)
Jul 07 17:14:37 debian java[2816]: at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:211)
Jul 07 17:14:37 debian java[2816]: at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:675)
Jul 07 17:14:37 debian java[2816]: at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:337)
Jul 07 17:14:37 debian java[2816]: at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
Jul 07 17:14:37 debian java[2816]: ... 5 more
Jul 07 17:14:37 debian systemd[1]: pointless.service: Main process exited, code=exited, status=1/FAILURE
Jul 07 17:14:37 debian systemd[1]: pointless.service: Unit entered failed state.
Jul 07 17:14:37 debian systemd[1]: pointless.service: Failed with result 'exit-code'.
Found the answer
Made following changes under [Service] in pointless.service
a) use "Environment=DISPLAY:=0"
b) declare "User=<user>"
and under [Install] optional
c) declare "WantedBy=<user>#.service"
I've installed Tomcat (apache-tomcat-8.5.37), on a CentOS VM (using bento/centos-7).
Tomcat is installed in
/opt/tomcat/apache-tomcat-8.5.37
and Java 8 is installed in
/usr/java/jre1.8.0_192-amd64
Before to install Tomcat I've created a tomcat user in this way
sudo useradd tomcat
sudo passwd tomcat
sudo mkdir /opt/tomcat
sudo chown -R tomcat:tomcat /opt/tomcat
su – tomcat
If I try to start Tomcat manually using
/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh
all works fine and I can test Tomcat ad its examples from the url
http://192.168.33.10:8080
(note: 192.168.33.10 is the IP of my virtual machine ...)
I can also shutdown Tomcat using
/opt/tomcat/apache-tomcat-8.5.37/bin/shutdown.sh
I'd like to start Tomcat like e service so I've stopped Tomcat and then I've edited a file
/etc/systemd/system/tomcat.service
with this content
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/java/jre1.8.0_192-amd64
Environment=CATALINA_PID=/opt/tomcat/apache-tomcat-8.5.37/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.37/
Environment=CATALINA_BASE=/opt/tomcat/apache-tomcat-8.5.37/
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
User=tomcat
Group=tomcat
UMask=0007
[Install]
WantedBy=multi-user.target
Then
sudo systemctl daemon-reload
and
sudo systemctl start tomcat
Tomcat does not responding now invoking the url
http://192.168.33.10:8080
and the output of
sudo systemctl status tomcat
is the follow
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2019-01-01 09:34:46 UTC; 13min ago
Process: 14438 ExecStop=/bin/kill -15 $MAINPID (code=exited, status=1/FAILURE)
Process: 14425 ExecStart=/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 14436 (code=exited, status=0/SUCCESS)
Jan 01 09:34:46 localhost.localdomain systemd[1]: Starting Apache Tomcat Web Application Container...
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Existing PID file found during start.
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Removing/clearing stale PID file.
Jan 01 09:34:46 localhost.localdomain systemd[1]: Started Apache Tomcat Web Application Container.
Jan 01 09:34:46 localhost.localdomain systemd[1]: tomcat.service: control process exited, code=exited status=1
Jan 01 09:34:46 localhost.localdomain systemd[1]: Unit tomcat.service entered failed state.
Jan 01 09:34:46 localhost.localdomain systemd[1]: tomcat.service failed.
The output of
journalctl -xe
is the follow
Jan 01 09:34:46 localhost.localdomain sudo[14418]: tomcat : TTY=pts/0 ; PWD=/opt/tomcat/apache-tomcat-8.5.37/temp ; USER=root ; COMMAND=/bin/systemctl start tomcat
Jan 01 09:34:46 localhost.localdomain polkitd[635]: Registered Authentication Agent for unix-process:14419:1135902 (system bus name :1.85 [/usr/bin/pkttyagent --notify-fd 5 --fallb
Jan 01 09:34:46 localhost.localdomain systemd[1]: Starting Apache Tomcat Web Application Container...
-- Subject: Unit tomcat.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has begun starting up.
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Existing PID file found during start.
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Removing/clearing stale PID file.
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Tomcat started.
Jan 01 09:34:46 localhost.localdomain polkitd[635]: Unregistered Authentication Agent for unix-process:14419:1135902 (system bus name :1.85, object path /org/freedesktop/PolicyKit1
Jan 01 09:34:46 localhost.localdomain systemd[1]: Started Apache Tomcat Web Application Container.
-- Subject: Unit tomcat.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has finished starting up.
--
-- The start-up result is done.
Jan 01 09:34:46 localhost.localdomain kill[14438]: Usage:
Jan 01 09:34:46 localhost.localdomain kill[14438]: kill [options] <pid|name> [...]
Jan 01 09:34:46 localhost.localdomain kill[14438]: Options:
Jan 01 09:34:46 localhost.localdomain kill[14438]: -a, --all do not restrict the name-to-pid conversion to processes
Jan 01 09:34:46 localhost.localdomain kill[14438]: with the same uid as the present process
Jan 01 09:34:46 localhost.localdomain kill[14438]: -s, --signal <sig> send specified signal
Jan 01 09:34:46 localhost.localdomain kill[14438]: -q, --queue <sig> use sigqueue(2) rather than kill(2)
Jan 01 09:34:46 localhost.localdomain kill[14438]: -p, --pid print pids without signaling them
Jan 01 09:34:46 localhost.localdomain kill[14438]: -l, --list [=<signal>] list signal names, or convert one to a name
Jan 01 09:34:46 localhost.localdomain kill[14438]: -L, --table list signal names and numbers
Jan 01 09:34:46 localhost.localdomain kill[14438]: -h, --help display this help and exit
Jan 01 09:34:46 localhost.localdomain kill[14438]: -V, --version output version information and exit
Jan 01 09:34:46 localhost.localdomain kill[14438]: For more details see kill(1).
Jan 01 09:34:46 localhost.localdomain systemd[1]: tomcat.service: control process exited, code=exited status=1
Jan 01 09:34:46 localhost.localdomain systemd[1]: Unit tomcat.service entered failed state.
Jan 01 09:34:46 localhost.localdomain systemd[1]: tomcat.service failed.
Jan 01 09:34:59 localhost.localdomain sudo[14451]: tomcat : TTY=pts/0 ; PWD=/opt/tomcat/apache-tomcat-8.5.37/temp ; USER=root ; COMMAND=/bin/systemctl status tomcat
Jan 01 09:48:45 localhost.localdomain sudo[15115]: tomcat : TTY=pts/0 ; PWD=/opt/tomcat/apache-tomcat-8.5.37/bin ; USER=root ; COMMAND=/bin/systemctl status tomcat
The output of catalina.out is the follow
01-Jan-2019 09:09:21.585 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
01-Jan-2019 09:09:21.602 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
01-Jan-2019 09:09:21.614 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2829 ms
01-Jan-2019 09:09:21.697 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
01-Jan-2019 09:09:21.697 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.37
01-Jan-2019 09:09:21.738 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/ROOT]
01-Jan-2019 09:09:22.777 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/ROOT] has finished in [1,038] ms
01-Jan-2019 09:09:22.795 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/docs]
01-Jan-2019 09:09:22.847 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/docs] has finished in [70] ms
01-Jan-2019 09:09:22.847 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/examples]
01-Jan-2019 09:09:23.468 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/examples] has finished in [621] ms
01-Jan-2019 09:09:23.469 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/host-manager]
01-Jan-2019 09:09:23.522 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/host-manager] has finished in [54] ms
01-Jan-2019 09:09:23.522 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/manager]
01-Jan-2019 09:09:23.569 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/manager] has finished in [47] ms
01-Jan-2019 09:09:23.592 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
01-Jan-2019 09:09:23.601 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
01-Jan-2019 09:09:23.604 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1990 ms
01-Jan-2019 09:12:38.830 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
01-Jan-2019 09:12:38.831 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
01-Jan-2019 09:12:38.870 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
01-Jan-2019 09:12:38.878 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
01-Jan-2019 09:12:39.117 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
01-Jan-2019 09:12:39.123 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
01-Jan-2019 09:12:39.131 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
01-Jan-2019 09:12:39.137 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]
????
Suggestions are appreciated!!
NOTE: As of OCT 2019
I followed the BUG https://bz.apache.org/bugzilla/show_bug.cgi?id=63063, still it did not resolve the issue.
I did little trial and error and got the issue resolved. It works smooth and works completely fine as per standards. Even if you kill the tomcat service gracefully or using kill -9 and then start the tomcat service using systemctl as mentioned below, it works like charm.
I am using Ubuntu 16.04, tomcat 8.5.37, Java 1.8.0_222
I used below systemd script, kept it at location: /etc/systemd/system/
# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container for ShopWorx
After=syslog.target network.target
[Service]
Type=forking
WorkingDirectory=/usr/local/tomcat/bin
ExecStart=/bin/bash /usr/local/tomcat/bin/catalina.sh start
ExecStop=/bin/bash /usr/local/tomcat/bin/catalina.sh stop
User=emgda
Group=emgda
[Install]
WantedBy=multi-user.target
and ran below command sequentially
systemctl daemon-reload
systemctl start tomcat
systemctl status tomcat
Below is output for status of tomcat service.
● tomcat.service - Apache Tomcat Web Application Container for ShopWorx
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2019-10-09 14:52:08 IST; 1min 46s ago
Process: 3713 ExecStart=/bin/bash /usr/local/tomcat/bin/catalina.sh start (code=exited, status=0/SUCCESS)
Main PID: 3720 (bash)
CGroup: /system.slice/tomcat.service
├─3720 /bin/bash /usr/local/tomcat/bin/catalina.sh start
└─3722 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.
Oct 09 14:52:08 ubuntu systemd[1]: Starting Apache Tomcat Web Application Container ...
Oct 09 14:52:08 ubuntu bash[3713]: Tomcat started.
Oct 09 14:52:08 ubuntu systemd[1]: Started Apache Tomcat Web Application Container.
IMPORTANT: WorkingDirectory, ExecStart, ExecStop must be taken care with, their values are crucial.
I found related bug reports:
Bug 63063
Bug 63041
This bug will be fixed in next version.
A common problem, when you start tomcat once manually (using your own user account), the temporary files, logs etc. are owned by you, not by the daemon user (tomcat, according to the quoted tomcat.service file. Subsequent starts with the daemon user can't overwrite those files due to missing permissions - this might also prevent proper logging of those problems.
Fix those permissions (or rather: file ownerships) and try again. My daemon start scripts typically have a chown for the relevant files, just to make sure that I'm not running into those problems in case someone has manually started using a wrong user account.
delete pid file as said in your error message
Existing PID file found during start.
/opt/tomcat/apache-tomcat-8.5.37/temp/tomcat.pid
I've solved changing this line
ExecStop=/bin/kill -15 $MAINPID
in
ExecStop=sudo /bin/kill -15 $MAINPID
in my /etc/systemd/system/tomcat.service file.
Its new content is now
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/java/jre1.8.0_192-amd64
Environment=CATALINA_PID=/opt/tomcat/apache-tomcat-8.5.37/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.37/
Environment=CATALINA_BASE=/opt/tomcat/apache-tomcat-8.5.37/
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh
ExecStop=sudo /bin/kill -15 $MAINPID
User=tomcat
Group=tomcat
UMask=0007
[Install]
WantedBy=multi-user.target
Now tomcat service start with
sudo systemctl start tomcat
and the output of
sudo systemctl status tomcat
is
[vagrant#localhost system]$ sudo systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) since Tue 2019-01-08 20:28:25 UTC; 1s ago
Process: 14447 ExecStart=/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 14458 (code=exited, status=0/SUCCESS)
Some time it would be your java heap memory exceed as your current server memory. You can set it in your setenv.sh file in tomcat8 and then restart the server.
I have face same kind of issue when I have downgrade the system configuration after that tomcat could't be restart so I have just adjust the heap memory in tomcat/bin/setenv.sh file and /etc/systemd/system/tomcat.service file according to system configuration then I have restart the tomcat. Now it's working fine.
at an old CentOS 6.10 the solution was changing /etc/init.d/tomcat8
to use runuser instead of su or sudo so changing
/bin/su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
to
/sbin/runuser -s /bin/sh $TOMCAT_USER $CATALINA_HOME/bin/startup.sh
maybe you can try this:
[Unit]
Description=Tomcat
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/local/jdk1.8.0_251
Environment=LD_LIBRARY_PATH=/usr/local/apr/lib
Environment=LD_RUN_PATH=/usr/local/apr/lib
PIDFile=/usr/local/apache-tomcat-9.0.36/bin/tomcat_8080.pid
ExecStart=/usr/local/apache-tomcat-9.0.36/bin/startup.sh
ExecReload=/usr/local/apache-tomcat-9.0.36/bin/catalina.sh restart
ExecStop=/usr/local/apache-tomcat-9.0.36/bin/shutdown.sh
PrivateTmp=true
User=root
Group=root
[Install]
WantedBy=multi-user.target
it is crucial to specify apr/lib
One of my server is running with tomcat for a java application. The application is working fine with tomcat but in syslog we are getting the following error continuously in Ubuntu:
Oct 15 16:00:18 HiT-APP-Primary shutdown.sh[115760]: PID file found but either no matching process was found or the current user does not have permission to stop the process. Stop aborted.
Oct 15 16:00:18 HiT-APP-Primary systemd[1]: tomcat.service: Control process exited, code=exited status=1
Oct 15 16:00:18 HiT-APP-Primary systemd[1]: tomcat.service: Unit entered failed state.
Oct 15 16:00:18 HiT-APP-Primary systemd[1]: tomcat.service: Failed with result 'exit-code'.
Oct 15 16:00:28 HiT-APP-Primary systemd[1]: tomcat.service: Service hold-off time over, scheduling restart.
Oct 15 16:00:28 HiT-APP-Primary systemd[1]: Stopped Apache Tomcat Web Application Container.
Oct 15 16:00:28 HiT-APP-Primary systemd[1]: Starting Apache Tomcat Web Application Container...
Oct 15 16:00:28 HiT-APP-Primary startup.sh[115772]: Existing PID file found during start.
Oct 15 16:00:28 HiT-APP-Primary startup.sh[115772]: Removing/clearing stale PID file.
Oct 15 16:00:28 HiT-APP-Primary startup.sh[115772]: Tomcat started.
Oct 15 16:00:28 HiT-APP-Primary systemd[1]: Started Apache Tomcat Web Application Container.
Oct 15 16:00:35 HiT-APP-Primary shutdown.sh[115867]: PID file found but either no matching process was found or the current user does not have permission to stop the process. Stop aborted.
Oct 15 16:00:35 HiT-APP-Primary systemd[1]: tomcat.service: Control process exited, code=exited status=1
Oct 15 16:00:35 HiT-APP-Primary systemd[1]: tomcat.service: Unit entered failed state.
Oct 15 16:00:35 HiT-APP-Primary systemd[1]: tomcat.service: Failed with result 'exit-code'.
Can anyone solve it please?
in my case java home was not properly setup in tomcat service file to make this fixed open tomcat service file.
vim /etc/systemd/system/tomcat.service
and verify JAVA_HOME is pointing to the correct JRE version if not then make it correct
Environment="JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre"
After this reload daemon and start service again
Oct 15 16:00:18 HiT-APP-Primary shutdown.sh[115760]: PID file found but either no matching process was found or the current user does not have permission to stop the process. Stop aborted.
Looks like a permission issue. Check the permissions.
Otherwise
set CATALINA_PID=/tmp/tomcat.pid, or to a directory where tomcat has access. Then restart tomcat.
I am trying to start elasticsearch on gcp, however, I am facing the below error.
Nov 06 06:29:07 poc-02 systemd[1]: Starting Elasticsearch...
Nov 06 06:29:07 poc-02 systemd[1]: Started Elasticsearch.
Nov 06 06:29:07 poc-02 elasticsearch[8939]: which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
However, i have java present in path /usr/bin. Any hint?