这是我的 tomcat.service 文件,位于 etc/systemd/system
[root@ip-10-81-27-248 system]# less tomcat.service
Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
SuccessExitStatus=143
Environment=TOMCAT_JAVA_HOME=/usr/java/latest/jre
Environment=JAVA_HOME=/usr/java/latest/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true - Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
现在当我检查我的 tomcat 的状态时它说
ExecStop=/bin/kill -15 $MAINPID(代码=退出,状态=1/FAILURE)
[root@ip-10-81-27-248 system]# service tomcat status -l
Redirecting to /bin/systemctl status -l tomcat.service
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2017-04-25 02:43:57 UTC; 6min ago
Process: 16187 ExecStop=/bin/kill -15 $MAINPID (code=exited, status=1/FAILURE)
Process: 16154 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 16164 (code=exited, status=0/SUCCESS)
Apr 25 02:43:54 ip-10-81-27-248.us-west-2.compute.internal systemd[1]: Starting Apache Tomcat Web Application Container...
Apr 25 02:43:54 ip-10-81-27-248.us-west-2.compute.internal startup.sh[16154]: Existing PID file found during start.
Apr 25 02:43:54 ip-10-81-27-248.us-west-2.compute.internal startup.sh[16154]: Removing/clearing stale PID file.
Apr 25 02:43:54 ip-10-81-27-248.us-west-2.compute.internal startup.sh[16154]: Tomcat started.
Apr 25 02:43:54 ip-10-81-27-248.us-west-2.compute.internal systemd[1]: Started Apache Tomcat Web Application Container.
Apr 25 02:43:57 ip-10-81-27-248.us-west-2.compute.internal systemd[1]: tomcat.service: control process exited, code=exited status=1
Apr 25 02:43:57 ip-10-81-27-248.us-west-2.compute.internal systemd[1]: Unit tomcat.service entered failed state.
Apr 25 02:43:57 ip-10-81-27-248.us-west-2.compute.internal systemd[1]: tomcat.service failed.
我尝试使用服务 tomcat 重新启动,但它仍然说 tomcat 服务失败。这可能是什么原因造成的?
答案1
这是一个错误:
Environment='JAVA_OPTS=-Djava.awt.headless=true - Djava.security.egd=file:/dev/./urandom'
^^
删除这两个空格。
答案2
我已经提到 这个答案 并给予 tomcat 用户整个 tomcat 目录的所有权对我来说是有效的
cd /opt && sudo chown -R tomcat tomcat/