几分钟后,Jar文件的Systemd服务出现“操作超时”错误或停留在“激活模式”中。

15

服务单位是:

[Unit]
Description=test
After=syslog.target
After=network.target

[Service]
Type=forking
ExecStart=/bin/java -jar /home/ec2-user/test.jar
TimeoutSec=300

[Install]
WantedBy=multi-user.target

它开始运行1-4分钟没问题,但后来就失败了:

tail /var/log/messages:

Feb 27 18:43:44 ip-172-31-40-48 systemd: Reloading.
Feb 27 18:44:06 ip-172-31-40-48 systemd: Starting test...
Feb 27 18:44:06 ip-172-31-40-48 java: 5.1.73
Feb 27 18:44:06 ip-172-31-40-48 java: Starting the internal [HTTP/1.1] server on port 8182
Feb 27 18:49:06 ip-172-31-40-48 systemd: test.service operation timed out.Terminating.
Feb 27 18:49:06 ip-172-31-40-48 systemd: test.service: control process exited, code=exited status=143
Feb 27 18:49:06 ip-172-31-40-48 systemd: Failed to start test.
Feb 27 18:49:06 ip-172-31-40-48 systemd: Unit test.service entered failed state.

systemctl status test.service(重启时停留在激活模式):

test.service - Setsnew
Loaded: loaded (/etc/systemd/system/test.service; enabled)
Active: activating (start) since Sun 2015-03-01 14:29:36 EST; 2min 30s ago
Control: 32462 (java)
CGroup: /system.slice/test.service

测试服务(失败后)的状态:systemctl status test.service:

test.service - test
Loaded: loaded (/etc/systemd/system/test.service; enabled)
Active: failed (Result: exit-code) since Fri 2015-02-27 18:49:06 EST; 18min ago
Process: 27954 ExecStart=/bin/java -jar /home/ec2-user/test.jar (code=exited, status=143)
  • 在命令行中运行jar文件时,它可以正常工作。
  • 尝试更改jar文件的位置,因为我认为这是权限问题。
  • selinux已关闭。

我该如何解决这个问题,以便在启动时启动jar文件? 有任何替代方法吗? (RHEL7不包括service命令)

1个回答

31

您将服务类型设置为 forking,但此服务不会分叉。它只是直接运行。因此systemd等待程序守护进程化自身5分钟,但从未实现。这种服务的正确类型是simple

您还禁用了SELinux,这是您应解决的另一个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接