Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 343
user3674227 Avatar asked Feb 28 '15 00:02

user3674227


People also ask

How do I stop Systemd service start operation from timing out?

Create a service drop-in configuration directory. Define TimeoutStartSec option to increase startup timeout. Reload systemd manager configuration. Inspect altered timeout for start operation.

What is ExecStart?

ExecStart= Commands with their arguments that are executed when this service is started. The value is split into zero or more command lines according to the rules described below (see section "Command Lines" below). Unless Type= is oneshot , exactly one command must be given.


1 Answers

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.

like image 155
Michael Hampton Avatar answered Oct 06 '22 12:10

Michael Hampton