简体   繁体   中英

Tomcat: Can't start tomcat after installing it on Ubuntu: "Job for tomcat.service failed because the control process exited with error code."

I followed the steps https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04 to install tomcat 8.5.24 on Ubuntu 16.04, till running sudo ufw allow 8080 in "Step 6: Adjust the Firewall and Test the Tomcat Server".

Then I can't start tomcat,

$ sudo systemctl start tomcat
Job for tomcat.service failed because the control process exited with error code. See "systemctl status tomcat.service" and "journalctl -xe" for details.

and the link http://localhost:8080/ doesn't work in both firefox and google chrome browsers.

I was wondering how to solve the problem.

The following details are what I followed the above output messages of sudo systemctl start tomcat . It seems that /opt/tomcat/bin/startup.sh succeeded while /opt/tomcat/bin/shutdown.sh failed. Much appreciate your help!

$ systemctl status tomcat.service
● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2017-12-01 18:55:30 EST; 2s ago
  Process: 19490 ExecStop=/opt/tomcat/bin/shutdown.sh (code=exited, status=1/FAILURE)
  Process: 19478 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 19440 (code=exited, status=127)

Dec 01 18:55:30 ocean systemd[1]: tomcat.service: Control process exited, code=exited status=1
Dec 01 18:55:30 ocean systemd[1]: Failed to start Apache Tomcat Web Application Container.
Dec 01 18:55:30 ocean systemd[1]: tomcat.service: Unit entered failed state.
Dec 01 18:55:30 ocean systemd[1]: tomcat.service: Failed with result 'exit-code'.

$ journalctl -xe

-- Unit tomcat.service has begun starting up.
Dec 01 18:51:24 ocean startup.sh[18873]: Existing PID file found during start.
Dec 01 18:51:24 ocean startup.sh[18873]: Removing/clearing stale PID file.
Dec 01 18:51:24 ocean startup.sh[18873]: Tomcat started.
Dec 01 18:51:24 ocean shutdown.sh[18885]: PID file found but no matching process was found. Stop aborted.
Dec 01 18:51:24 ocean systemd[1]: tomcat.service: Control process exited, code=exited status=1
Dec 01 18:51:24 ocean systemd[1]: Failed to start Apache Tomcat Web Application Container.
-- Subject: Unit tomcat.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit tomcat.service has failed.
-- 
-- The result is failed.
Dec 01 18:51:24 ocean systemd[1]: tomcat.service: Unit entered failed state.
Dec 01 18:51:24 ocean systemd[1]: tomcat.service: Failed with result 'exit-code'.
Dec 01 18:51:34 ocean systemd[1]: tomcat.service: Service hold-off time over, scheduling restart.
Dec 01 18:51:34 ocean systemd[1]: Stopped Apache Tomcat Web Application Container.
-- Subject: Unit tomcat.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit tomcat.service has finished shutting down.
Dec 01 18:51:34 ocean 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.
Dec 01 18:51:35 ocean startup.sh[18896]: Existing PID file found during start.
Dec 01 18:51:35 ocean startup.sh[18896]: Removing/clearing stale PID file.
Dec 01 18:51:35 ocean startup.sh[18896]: Tomcat started.
Dec 01 18:51:35 ocean shutdown.sh[18908]: PID file found but no matching process was found. Stop aborted.
Dec 01 18:51:35 ocean systemd[1]: tomcat.service: Control process exited, code=exited status=1
Dec 01 18:51:35 ocean systemd[1]: Failed to start Apache Tomcat Web Application Container.
-- Subject: Unit tomcat.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit tomcat.service has failed.
-- 
-- The result is failed.
Dec 01 18:51:35 ocean systemd[1]: tomcat.service: Unit entered failed state.
Dec 01 18:51:35 ocean systemd[1]: tomcat.service: Failed with result 'exit-code'.

My Java versions are

$ java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

$ javac --version
javac 9.0.1

update:

Instead of sudo systemctl start tomcat which gives the error above, if I run

cd /opt/tomcat/bin

sudo ./catalina.sh run

http://localhost:8080/ shows the correct webpage. SO what is the reason that one doesn't work while the other does?

使用户tomcat成为整个 tomcat 目录的所有者:

cd /opt && sudo chown -R tomcat tomcat/

我通过从/etc/systemd/system/tomcat.service JAVA_HOME中删除“ /jre ”解决了这个问题

Find JAVA_Home ($env | grep JAVA_HOME)

sudo vi /etc/systemd/system/tomcat.service

Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64"

You might have added the following line in your tomcat service:-

Environment="JAVA_HOME=/usr/lib/jvm/default-java"

you have to replace it with the actual version of java you are using. Type the following command in you terminal :-

sudo update-java-alternatives -l

output

replace the output of the above command with the JAVA_HOME variable path and your variable should look somewhat like following:-

Environment="JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64"

Now reload daemon and restart you service it should be working fine

sudo systemctl daemon-reload

sudo systemctl start tomcat

Check the status of service

sudo systemctl status tomcat

I had this same issue on an existing installation of Tomcat on Ubuntu:

I started having this issue when I tried clearing the logs files by making a copy of the existing one and then creating a new one using these commands:

sudo cp /opt/tomcat/logs/catalina.out catalina_copy.out
sudo rm -rf /opt/tomcat/logs/catalina.out
sudo touch /opt/tomcat/logs/catalina.out

And I was having this error when I tried to start tomcat using sudo systemctl restart tomcat :

$ sudo systemctl start tomcat
Job for tomcat.service failed because the control process exited with error code. See "systemctl status tomcat.service" and "journalctl -xe" for details.

Here's how I fixed it :

The issue was that after I created and made a copy of the files, the ownership for the files was changed from tomcat to root , which I confirmed by running the command below in the /opt/tomcat/logs directory:

ls -lh

All I had to do was to change the ownership from root to tomcat by running the command below:

sudo chown -R tomcat:tomcat catalina.out
sudo chown -R tomcat:tomcat catalina_copy.out

This time when I tried starting the tomcat server using sudo systemctl restart tomcat it worked fine.

That's all.

I hope this helps

只需从 'tomcat.service' 文件中的 JAVA_HOME 中删除 '/jre',服务就会启动。

I encountered a similar problem today, only difference was that the service was running perfectly until last night and all of a sudden it stopped..

The reason was that the Java version had been updated automatically which changed the java path.

All I had to do was update the new Java path in the tomcat.service file, restart the daemon and viola..!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM