Systemd Service for jar file gets "operation timed out" error after few minues or stay in "activating mode"

user3674227 picture user3674227 · Feb 28, 2015 · Viewed 9.5k times · Source

the service unit is:

[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

it starts fine for 1-4 minues. But later it fails:

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 (while restarting- stays in activating mode):

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 (after fail):

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)
  • when running the jar in command line it works just fine.
  • tried changing the jar location because I thought it's a permissions problem
  • selinux is off

How can i fix this issue so I could start the jar on boot? there any alternatives? (RHEL7 do not include service command)

Answer

Michael Hampton picture Michael Hampton · Jun 9, 2015

You made the service type forking, but this service does not fork. It just runs directly. Thus systemd waited five minutes for the program to daemonize itself, and it never did. The correct type for such a service is simple.

You also disabled SELinux, which is another problem you should resolve.